Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨我的网页有很多 imageButtons,点击刷新页面。我该如何防止这种情况?
var imageButton = new ImageButton(); imageButton.ImageUrl = "Styles/unClicked.png"; imageButton.ID = "btn" + questionName; imageButton.OnClientClick = ("javascript:button_pressed()");
我的第一个答案是,如果您不希望图像回发,请不要使用<asp:ImageButton>,而只需使用一个<img>元素。
<asp:ImageButton
<img>
但是,如果您想使用<asp:ImageButton>then 更新以下行来停止页面被回发(刷新)...
<asp:ImageButton>
imageButton.OnClientClick = "button_pressed();return false;"
请注意,您不需要初始的“javascript:”(浏览器知道它是 javascript)