UpdatePanel 中的 ImageButton 导致 Firefox 中完全回发

发布于 2024-07-27 23:23:28 字数 888 浏览 2 评论 0原文

我有一个带有图像按钮的更新面板:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2024-08-03 23:23:28

尝试这个:

 <asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
 OnClientClick="javascript:void(0);ChangeMedium();"/>

Try this:

 <asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
 OnClientClick="javascript:void(0);ChangeMedium();"/>
飘然心甜 2024-08-03 23:23:28

您应该做的是删除 OnClientClick 并输入以下内容:

btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();return false;");

What you should do is remove the OnClientClick and put the following:

btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();return false;");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文