I have an updatepanel that has an Image button:
我有一个带有图像按钮的updatepanel:
<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.
当页面加载时,基于某些逻辑,我在后面的代码中设置onclick属性。
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:
IE中的作品很棒。在FF中,图像按钮会导致回发!通过反复试验和搜索网络,我发现罪魁祸首是onclick。一篇博客文章建议如果设置了OnClientClick,那么不应该发生回发,所以我将图像按钮更改为:
<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:
我能够让它不在图像按钮点击回发,但不幸的是,它没有完全解决我的问题。现在呈现的HTML是:
<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?
因此,永远不会调用ChangeMedium()函数。有没有解决这个问题的方法?
Any help is really appreciated
任何帮助都非常感谢
Thanks!
2 个解决方案
#1
Try this:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
OnClientClick="javascript:void(0);ChangeMedium();"/>
#2
What you should do is remove the OnClientClick and put the following:
你应该做的是删除OnClientClick并输入以下内容:
btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();return false;");
#1
Try this:
<asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server"
OnClientClick="javascript:void(0);ChangeMedium();"/>
#2
What you should do is remove the OnClientClick and put the following:
你应该做的是删除OnClientClick并输入以下内容:
btnChangeMedium.Attributes.Add("onclick", "ChangeMedium();return false;");