How to change ImageUrl attribute of an image when loading a page using asp.net and C # in IE

I have links on the home page that may or may not have attachments associated with them. If the links have attachments, an icon will be placed next to the link. The icon will only be there if the link has an attachment.

protected void Page_Load(object sender, EventArgs e)
    {
        foreach (Image pic in imgAttachment)
            {
                 int type = ds.Current_Events[index].AttachmentID;
                 //ds is the dataset

The foreach loop goes through each of the Current Event images on the home page, then gets the type of binding associated with each link, for example, AtachmentID. AttachmentID can be 0, 1, 2 or 3, which means there is no attachment, no attachment, no attachment, video or attachment.

The switch statement is then used to change the ImageUrl attribute to the corresponding image.

                 switch (type)
                     {
                            case 0:
                                break;
                            case 1:
                                pic.ImageUrl = "images/eventicons/Photo.jpg";
                                //changed from just "Photo.jpg"
                                break;
                            case 2:
                                pic.ImageUrl = "images/eventicons/Video.jpg";
                                //changed from just "Video.jpg"
                                break;
                            case 3:
                                pic.ImageUrl = "images/eventicons/Doc.jpg";
                                //changed from just "Doc.jpg"
                                break;
                            default:
                                pic.Visible = false;
                                break;
                      }
                  index++;
            }
    }

The image does not load in IE, however it works for firefox.

aspx

<div>
  <ul>
   <li>
      <asp:HyperLink ID="lblEvent1" runat="server">              
           <img src="images/bar_blank.gif" />
      </asp:HyperLink>
      <asp:Image ID="Image1" runat="server" />
   </li>
   <li>
      <asp:HyperLink ID="lblEvent2" runat="server">
           <img src="images/bar_blank.gif" />
      </asp:HyperLink>
      <asp:Image ID="Image2" runat="server" />
   </li>
  </ul>
</div>
+3
3

.

, , 500 . , , , . 40 . ie.

, , , ImageUrl asp.net , , , (500kb).

, , , gif ..

0

.

pic.ImageUrl = "Photo.jpg";

, ASP.Net ...

pic.ImageUrl = "~/MyImagePath/Photo.jpg";
+1

What does the html code that is generated from your code look like? Could you post this as there are issues with how IE and firefox render images based on how you link to your image. It would be nice to see the rendering as well as your code.

0
source

Source: https://habr.com/ru/post/1709606/


All Articles