I am learning ASP.Net. I have a dynamically created ImageButton that I would like to change the ImageURL for when the user hovers over the control. I have tried this but it does not work:
imgStars.Attributes.Add("onmouseover", "this.src= '~/Images/4Stars.png'")
If I set the imgStars.ImageURL in the codebehind to ~/Images/4Stars.png it works. But it does not work in javascript.
Please help. I have tried searching for my answer for hours, but I do not have a clue what to do.
"xanadont" answered you right but your solution will not work for every scenario. To ensure that every relative directory will be usable by the client, use this code snippet:
imgStars.Attributes.Add("onmouseover", "this.src= '" + this.Page.ResolveClientUrl("~/Images/4Stars.png") + "'");
in VB you should use the following code:
*imgBtnRegister.Attributes.Add("onmouseover", "this.src='" + Page.ResolveClientUrl("~/Images/Register_2.jpg") + "'")
imgBtnRegister.Attributes.Add("onmouseout", "this.src='" + Page.ResolveClientUrl("~/Images/Register_1.jpg") + "'")*
use *Page.ResolveClientUrl("~/Images/Register_2.jpg")* instead of *this.Page.ResolveClientUrl("~/Images/Register_2.jpg")*