Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with preprocessor directive for ImgUrl property of Image in ASP.NET

I would like to parse QueryString and put the ID value to the ImgUrl path, I am trying this code:

<asp:Image ID="imgImageNormal" runat="server" ImageUrl='<%# string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString()) %>'/>

But the produced result is none. I am not getting any error message but after viewing the source of the page, this is the output for the image:

<img id="ctl00_ContentPlaceHolder1_imgImageNormal" src="" style="border-width:0px;" />

What am I doing wrong?

like image 228
Wodzu Avatar asked Dec 09 '25 08:12

Wodzu


1 Answers

Is this within the context of binding? If not, the <%#...%> syntax will not work. This code works:

<img ID="imgImageNormal" src=<%=string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString())%> />

Note setting runat="server" or enclosing the src attributes in quotes will cause this to fail. Although the above works, you would probably be better off just setting the imageurl property of an asp:image control from the codebehind on the page_load event.

For reference on where to use asp.net inline tags check out this site: http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx

like image 93
theChrisKent Avatar answered Dec 11 '25 20:12

theChrisKent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!