0

我正在学习 ASP.Net。我有一个动态创建的 ImageButton,我想在用户将鼠标悬停在控件上时更改 ImageURL。我已经尝试过了,但它不起作用:

 imgStars.Attributes.Add("onmouseover", "this.src= '~/Images/4Stars.png'")

如果我将代码隐藏中的 imgStars.ImageURL 设置为 ~/Images/4Stars.png 它可以工作。但它在javascript中不起作用。

请帮忙。我已经尝试了几个小时来寻找我的答案,但我不知道该怎么做。

4

2 回答 2

1

“xanadont”回答正确,但您的解决方案不适用于每种情况。为确保客户端可以使用每个相对目录,请使用以下代码片段:

imgStars.Attributes.Add("onmouseover", "this.src= '" + this.Page.ResolveClientUrl("~/Images/4Stars.png") + "'");
于 2012-04-04T03:50:48.903 回答
0

在 VB 中,您应该使用以下代码:

    *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")*
于 2015-10-10T06:49:09.220 回答