本文介绍了JavaScript的确认asp.net按钮从未提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个定期的ASP:按钮。我在.net 3.5工作。我已经尝试添加一个js确认与的OnClientClick按钮属性以及在$ C $加入C-后面,结果是一样的。不管是什么在确认弹出窗体用户点击不会提交??

i have a regular asp:button. I am working in .Net 3.5. I've tried adding a js confirm to the button with the OnClientClick attribute as well as adding in code-behind and the result is the same. No matter what the user clicks in the confirm pop-up the form will not submit??

BtnDeleteSelected.Attributes.Add(onclick事件,返回确认(你确定要删除吗?'););

BtnDeleteSelected.Attributes.Add("onclick", "return confirm('Are you sure you want to delete?');");

显示确认对话框,如果我选择OK仍不能提交..任何想法?谢谢。

The confirm dialog appears and if i select "OK" it still does not submit.. Any ideas? thanks.

推荐答案

这是因为你不应该在所有情况下回国。如果您查看网页的源代码,并查找按钮标记,你可能会看到这个...

That's because you should not be returning in all cases. If you view the source of the page and look for the button markup, you are likely to see this...

onclick="return confirm('Ok?'); __doPostback();"

的__doPostBack调用由在某些情况下,ASP.NET框架自动插入。既然你返回确认的结果立即无论,回发永远不会触发。最终的解决办法是不要设置onclick属性,而是使用。但是,如果有pressing理由通过的onclick在服务器端控制这一点,你可以用一个简单的如果语句,只有当他们preSS返回取消...

The __doPostback invocation is inserted automatically by the ASP.NET framework in some cases. Since you return immediately regardless of the result of confirm, the postback never fires. The ultimate solution would be to not to set the onclick attribute, but instead use an unobtrusive approach. However, if there is pressing reason to control this on the server-side via onclick, you can use a simple if statement and only return when they press "Cancel"...

string js = "if(!confirm('Are you sure you want to delete?')) return false;";
BtnDeleteSelected.Attributes.Add("onclick", js);

这篇关于JavaScript的确认asp.net按钮从未提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:38