UpdatePanel 中的 ImageButton 导致 Firefox 中完全回发
我有一个带有图像按钮的更新面板:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server" />
当页面加载时,根据某些逻辑,我在后面的代码中设置了 onclick 属性。
btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();");
在 IE 中工作得很好。 在 FF 中,图像按钮会导致回发! 通过反复试验和网上搜索,我发现罪魁祸首是 onclick。 一篇博客文章建议,如果设置了 OnClientClick,则不应发生回发,因此我将 imagebutton 更改为:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
OnClientClick="#"/>
我能够让它在单击 imagebutton 时不进行回发,但不幸的是,它没有解决我的问题完全。 现在呈现的 HTML 是:
<input type="image" id="ctl00_WorkSpaceContent_ctlParent_btnChangeMedium"
src="../../images/sec.gif" onclick="#;ChangeMedium();"/>
因此,永远不会调用 ChangeMedium()
函数。 有解决这个问题的方法吗?
非常感谢任何帮助
谢谢!
I have an updatepanel that has an Image button:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server" />
When the page loads, based on some logic, I set the onclick attributes in the code behind.
btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();");
Works greate in IE. In FF, the imagebutton causes a postback! By trial and error and by searching the web, I found the culprit to be the onclick. One blog entry suggested that if the OnClientClick is set, then the postback should not happen, so I changed the imagebutton to:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
OnClientClick="#"/>
I was able to get it to not do a postback on the imagebutton click, but unfortunately, it did not solve my problem fully. The HTML rendered now is:
<input type="image" id="ctl00_WorkSpaceContent_ctlParent_btnChangeMedium"
src="../../images/sec.gif" onclick="#;ChangeMedium();"/>
So, the ChangeMedium()
function is never called. Any workarounds to this problem?
Any help is really appreciated
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个:
Try this:
您应该做的是删除 OnClientClick 并输入以下内容:
What you should do is remove the OnClientClick and put the following: