问题
Recently, we tested our products on IE10 and encountered a problem about that server button control “Asp:ImageButton” are not be fired on IE10 with UpdatePanel. And the below is the sample code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Here is the content.
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="buttonSubmit" />
</Triggers>
</asp:UpdatePanel>
<br />
<br />
<asp:Button ID="buttonSubmit" runat="server" ToolTip="Submit" OnClick="buttonSubmit_Click" />
</form>
server side:
protected void buttonSubmit_Click(object sender, ImageClickEventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.Page.GetType(), "alert", "alert('It works.')", true);
}
Here are two things which confused me: One is the issue only happens when I deployed on IIS and works fine when debugging on VS. The two is if I removed the upper two tag “br”, the event would be fired. Besides, if I change the ImageButton to Button, the event also would be fired.
So, I don’t know if I am missing something or misunderstand the life circle of the ImageButton and Button control. Any help would very appreciate.
Test environments: VS2010, IIS 7.5, IE10(10.0.9200.16484)
回答1:
Simply installing .NET Framework 4.5 can fix this problem.
This problem can be caused by the ImageButton IE10 bug which involves IE10 incorrectly converting coordinates to decimal rather than integer. This causes ImageButton clicks to fail in many, if not most, situations on IE10.
This can fix the problem even if you do not switch your application pool over to .NET Framework 4.5.
In my case, I left the app pools at .NET Framework 3.5. Apparently installing .NET Framework 4.5 overwrites some files for other framework versions.
See the workarounds section here
Related: IE10 sending image button click coordinates with decimals (floating point values) causing a ParseInt32 FormatException
回答2:
IE10 has a bug. If you develop a new aspx page and and ajaxify the page with updatepanels, the page won't work correctly.No server events will fire. But other browsers will do their job fine.I wonder why haven't microsoft noticed/fixed this issue. I handled the problem with forcing IE9 mode
<meta http-equiv="x-ua-compatible" content="IE=9" />
回答3:
Change ImageButton to a LinkButton and put the image inside of it.
It is a nice workaround, that's work for me.
回答4:
I changed the ImageButton to a LinkButton and put the button image inside of it. Works.
回答5:
You can do the same thing in the Page_PreRender
private bool alert;
protected void buttonSubmit_Click(object sender, EventArgs e)
{
alert= true;
ViewState["alert"] = alert;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (ViewState["alert"] != null)
alert= (bool)ViewState["alert"];
if (alert)
{
alert= false;
ScriptManager.RegisterStartupScript(this, this.Page.GetType(), "alert", "alert('It works.')", true);
}
}
Update Panel doesn't work correctly in IE 10 with button clicks,images etc.
来源:https://stackoverflow.com/questions/15330468/imagebutton-does-not-fire-a-post-back-on-ie10