C#: Refresh image on page load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eleven
    New Member
    • Mar 2008
    • 19

    C#: Refresh image on page load

    Hi everybody,

    I'm trying to load a different logo depending on who's logged in but the code doesn't seem to be working, well, it only works after i've rebooted my PC. Even when I log out it doesn't show the image its supposed to show for an un-authenticated user.
    I'm guessing its something to do with refreshing the page.. but even when I manually refresh the page it doesn't work.

    Hope someone can help me asap, i've spent too much time on this already.

    Thanks

    [CODE=C#]
    protected void Page_Load(objec t sender, EventArgs e)
    {

    if (!Page.User.Ide ntity.IsAuthent icated)
    BankLogoImage.I mageUrl = SmartecLogoImag e.ImageUrl;

    //Showing logged in user's bank logo
    if (Global.LoggedI nUser.FkBanksID .Value == 1)
    BankLogoImage.I mageUrl = "~/Images/ABSACashProtect or.jpg?";
    else
    if (Global.LoggedI nUser.FkBanksID .Value == 2)
    BankLogoImage.I mageUrl = "~/Images/NedBankLogo.jpg ?";
    else
    if (Global.LoggedI nUser.FkBanksID .Value == 3)
    BankLogoImage.I mageUrl = "~/Images/SmartecLogo.jpg ?";




    }
    [/CODE]
  • Waazzzii
    New Member
    • Jan 2008
    • 6

    #2
    BankLogoImage.I mageUrl = SmartecLogoImag e.ImageUrl;

    When you specify the asp Image tag you need to state the attribute 'ImageUrl=""' otherwise server side will not recognise it as being defined- this is most likely why you cannot change the value of it from the server. If you are using a regular html tag with the 'src' attribute then this will fail...

    Can you show your html code?

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Is your page being cached? What if you change the settings for that page to be not cached?

      Comment

      • Eleven
        New Member
        • Mar 2008
        • 19

        #4
        Originally posted by Waazzzii
        BankLogoImage.I mageUrl = SmartecLogoImag e.ImageUrl;

        When you specify the asp Image tag you need to state the attribute 'ImageUrl=""' otherwise server side will not recognise it as being defined- this is most likely why you cannot change the value of it from the server. If you are using a regular html tag with the 'src' attribute then this will fail...

        Can you show your html code?
        Here's my HTML Code, i did specify the ImageUrl attribute

        [CODE=HTML]
        <table style="width: 100%" border="0" cellpadding="0" cellspacing="0" >
        <tr>
        <td align="left" style="height: 50px; padding-left: 4px; border-bottom: #cccccc 2pt dotted;">
        <asp:Image ID="SmartecLogo Image" runat="server" Height="30px" ImageUrl="~/Images/SmartecLogo.PNG "
        Width="200px" /></td>
        <td align="center" style="height: 50px; border-bottom: #cccccc 2pt dotted;">
        <asp:Label runat="Server" ID="PageTitleLa ble" Font-Bold="True" CssClass="PageH eader"></asp:Label>
        </td>
        <td align="right" style="height: 50px; padding-right: 4px; border-bottom: #cccccc 2pt dotted;">
        <asp:Image ID="BankLogoIma ge" runat="server" Height="30px" ImageUrl="~/Images/ABSACashProtect or.PNG"
        Width="200px" ImageAlign="Rig ht" /></td>
        </tr>
        <tr>
        <td align="left">
        <asp:LoginNam e ID="LoginName1 " runat="server" Font-Bold="False" FormatString="W elcome back <b>{0}</b>"
        CssClass="Login User" />
        </td>
        <td align="right">
        &nbsp;</td>
        <td align="right">
        </td>
        </tr>
        </table>
        [/CODE]

        Comment

        • Eleven
          New Member
          • Mar 2008
          • 19

          #5
          Originally posted by Plater
          Is your page being cached? What if you change the settings for that page to be not cached?
          Plater, could you please explain how i'd go about making the page not chached? I don't know much about that.

          Thanks!

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            If you can (either in front end code or the backend code in the page_load), add the datetime number to the end of the request, sorta like this:

            "/Images/SmartecLogo.PNG ?t="+DateTime.N ow.Ticks.ToStri ng();


            This frequently "tricks" browsers into thinking it is requesting a different page since the query string is different, although it is still requesting the same file.

            Comment

            • Eleven
              New Member
              • Mar 2008
              • 19

              #7
              Originally posted by Plater
              If you can (either in front end code or the backend code in the page_load), add the datetime number to the end of the request, sorta like this:

              "/Images/SmartecLogo.PNG ?t="+DateTime.N ow.Ticks.ToStri ng();


              This frequently "tricks" browsers into thinking it is requesting a different page since the query string is different, although it is still requesting the same file.
              Thank you, i'll try it out.

              Comment

              Working...