locked
ImageURL only works when placed in the Page_Load Event. RRS feed

  • Question

  • User79101098 posted

    Hello, I am new to ASP.Net programming and I can't seem to figure out what I am doing wrong. I am trying to set an ImageURL programmatically. If I place the code under the Page_Load event it works perfectly, however, if I place the code under any other event (e.g. combobox.SelectedIndexChanged) the image doesn't show up. I know the event is firing, because the code surrounding the ImageURL is working. Any thoughts?

    This works:

    protected void Page_Load(object sender, EventArgs e)
    {

         OrderNumber.Text = "250993";
         string code = ("^xa^cfa,50^fo100,100^fdSoik Sales^fs^fo100,200^fd6213 County HH^fs^xz");
         PalletTagPreview.ImageUrl = "http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/" + code;

         Lotcode.Text = "ABC123";
    }

    This doesn't:

    protected void CompanySelected_SelectedIndexChanged(object sender, EventArgs e)
    {

         OrderNumber.Text = "250993";
         string code = ("^xa^cfa,50^fo100,100^fdSoik Sales^fs^fo100,200^fd6213 County HH^fs^xz");
         PalletTagPreview.ImageUrl = "http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/" + code;

         Lotcode.Text = "ABC123";

    }

    Friday, December 21, 2018 4:58 PM

All replies

  • User-943250815 posted

    You did post how is your page. Presuming "CompanySelected" is a DropDownList, Event will be fired only if you set Property "AutoPostBack = True"
    If you set, PalletTagPreview.ImageUrl should get a value assinged as soon you change item on DropDownList

    Friday, December 21, 2018 8:08 PM
  • User79101098 posted

    SOLVED:

    Yes, "CompanySelected" is a dropdownlist and I did have AutoPostBack property set to True. Once I wrapped my controls in an Update Panel, it worked. I'm still learning all this HTML stuff. LOL. Thanks for your time. 

    Friday, December 21, 2018 10:25 PM
  • User-943250815 posted

    Nice know you get it solved.
    Just in case, due to nature of UpdatePanel I don´t think it can be a good starting point.
    Here you can find more about it and houw it behaves https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.updatepanel?view=netframework-4.7.2

    Saturday, December 22, 2018 1:39 AM