ImageButton ?

  • Thread starter Thread starter TM
  • Start date Start date
T

TM

I have this line below coded in the aspx/html at design time:

*****************
<TD>
<asp:ImageButton id="Imagebutton1"
onmouseover="this.src='<%=MyImage2%>'"
onmouseout="this.src='<%=MyImage1%>'"
runat="server" ImageAlign="Left"
ImageUrl="<%=MyImage1%>">
</asp:ImageButton>
</TD>
*****************

"MyImage1" and "MyImage2" are c# string variables contain the physical paths
initialized during page_load operation.

When hovering the ImageButton1, I got a "RED X" image instead of the real
image. I displayed the path of MyImage1 & 2 and they both show valid images.

Thanks,

Thomas
 
Hover over the broken image, right click and select Properties. Then check
the image path it shows...
 
Hi, Thomas,

The reason is that you mix up the ASP.NET control with old asp code.
The asp:ImageButton will be initialized on page_init event. however, "<%=", which equals to Response.write, might occur after page_load.
You'd bette do in either ASP.NET or old ASP way.
In HTML source:
<TD><asp:ImageButton id="Imagebutton1"
runat="server" ImageAlign="Left"
</asp:ImageButton></TD>
In Page_PreRender event of Code-behind:
Imagebutton1.ImageUrl = MyImage1
Imagebutton1.Attributes("onmouseover") = "this.src='" & MyImage2 & "''"
Imagebutton1.Attributes("onmouseout") = "this.src='" & MyImage1 & "''"

Bin Song, MCP

----- TM wrote: -----
<TD><asp:ImageButton id="Imagebutton1"
onmouseover="this.src='<%=MyImage2%>'"
onmouseout="this.src='<%=MyImage1%>'"
runat="server" ImageAlign="Left"
ImageUrl="<%=MyImage1%>"></asp:ImageButton></TD>

I have this line below coded in the aspx/html at design time:

*****************
*****************

"MyImage1" and "MyImage2" are c# string variables contain the physical paths
initialized during page_load operation.

When hovering the ImageButton1, I got a "RED X" image instead of the real
image. I displayed the path of MyImage1 & 2 and they both show valid images.

Thanks,

Thomas
 
Back
Top