[英]Button onClick Event Handler Never Fires in Chrome Only
I am working on an old ASP.NET WebForms application that has an .aspx page with the following control: 我正在使用一个旧的ASP.NET WebForms应用程序,该应用程序具有带以下控件的.aspx页面:
<asp:Button ID="Budget_Approve" OnClick="Budget_Approve_Click" runat="server"
Visible="True" Width="100" Height="30" Text="Approve"></asp:Button>
The Budget_Approve_Click
event handler is never being hit, and I am trying to determine why. Budget_Approve_Click
事件处理程序永远不会被命中,我正在尝试确定原因。 I noticed when the page loads, this code gets executed to add some inline js to the onclick
attribute: 我注意到页面加载时,执行此代码以向
onclick
属性添加一些内联j:
Budget_Approve.Attributes.Add("onclick", "return confirm_approve();");
The HTML that gets rendered: 呈现的HTML:
<input type="submit" name="ctl00$mainContent$Budget_Approve" value="Approve"
onclick="return confirm_approve();WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ctl00$mainContent$Budget_Approve",
"", true, "", "", false, false))"
id="ctl00_mainContent_Budget_Approve" style="height:30px;width:100px;">
So when I click, I expect confirm_approve()
to be executed. 所以当我点击时,我希望执行
confirm_approve()
。 If it returns true
, I expect a postback and for my event handler to fire. 如果它返回
true
,我希望回发和我的事件处理程序触发。 Debugging in Chrome, I find that confirm_approve()
does indeed return true
: 在Chrome中调试,我发现
confirm_approve()
确实返回true
:
However, the postback never happens, and the Budget_Approve_Click
event handler never gets hit. 但是,回发永远不会发生,
Budget_Approve_Click
事件处理程序永远不会被命中。 Why not? 为什么不?
Edit: I tried removing the line that adds the inline javascript code entirely. 编辑:我尝试删除完全添加内联JavaScript代码的行。 However, still no postback.
但是,仍然没有回发。 The following HTML is rendered for the button:
为按钮呈现以下HTML:
<input type="submit" name="ctl00$mainContent$Budget_Approve"
value="Approve"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ctl00$mainContent$Budget_Approve",
"", true, "", "", false, false))"
id="ctl00_mainContent_Budget_Approve" style="height:30px;width:100px;" />
Update: Discovered that the postback does work in IE, but still not Chrome. 更新:发现回发在IE中可以正常工作 ,但仍然不是Chrome。 Are there any browser-specific settings or issues that could potentially cause this problem?
是否存在可能导致此问题的特定于浏览器的设置或问题?
我会用这个来解决它:
Budget_Approve.Attributes.Add("onclick", "if (!confirm_approve()) return false;");
试试这个...
Budget_Approve.Attributes.Add("onclick", "if (!confirm_approve()) return false;");
Check if your button is disabled somehow. 检查您的按钮是否以某种方式被禁用。
$("input[type='submit']").attr("disabled", "disabled"); $(“input [type ='submit']”)。attr(“disabled”,“disabled”);
If something like this happens, Chrome will have an incomplete POST request. 如果出现类似情况,Chrome将会收到不完整的POST请求。 ASP.NET will not fire the server side events.
ASP.NET不会触发服务器端事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.