有这样的代码:在ASP防止重复submiting:CommandField中
<asp:UpdatePanel ID="id">
<asp:CommandField ButtonType="Image" InsertImageUrl="url/here" ShowInsertImage="true" ValidationGroup="valGr" />
</asp:UpdatePanel>
如何防止这个按钮在C#代码双击。
有这样的代码:在ASP防止重复submiting:CommandField中
<asp:UpdatePanel ID="id">
<asp:CommandField ButtonType="Image" InsertImageUrl="url/here" ShowInsertImage="true" ValidationGroup="valGr" />
</asp:UpdatePanel>
如何防止这个按钮在C#代码双击。
您可以先创建一个标志来保存提交并将其添加到表单中。然后在UpdatePanel进行更新并等待返回时打开并关闭该标志。
例如这个代码是允许提交表单只有当 fAlloToSubmit
是true
(和在UpdatePanel)的:
<script>
var fAlloToSubmit = true;
function AllowFormToRun()
{
if(!fAlloToSubmit)
alert("Please wait for the page to fully re-loaded.");
return fAlloToSubmit;
}
</script>
和你后面的代码设置表单上。
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.Attributes["onsubmit"] = "return AllowFormToRun();";
}
现在的UpdatePanel的,你打开国旗,你去更新的时刻,例如时刻,你点击命令:
<script>
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
// here is run when you click the command on the UpdatePanel
fAlloToSubmit = false;
}
function EndRequest(sender, args) {
// here is come after the upadate of the command
fAlloToSubmit = true;
}
</script>
这里的窍门是,我认为形式提交而不是查看页面上的每个控件以禁用它。
我会尝试你的代码,我会给出反馈。 – 2013-02-27 19:23:49
@MorarMihai This – Aristos 2013-02-27 20:01:30
你的意思是说,Page.Form.Attributes [“onsubmit”]接受了提交的按钮,即使可能有更多的按钮(例如InsertButton,EditButton,CancelButton等等)。所以,如果你喜欢它,你可以修改它或改进它。该代码必须适用于所有类型的按钮?脚本我可以把它放在同一个文件中? – 2013-02-28 06:52:40
也许有些JavaScript会在第一次点击的X毫秒内发生任何点击事件? – 2013-02-27 18:41:30
是的,你是对的,我已经找到了一些JavaScript代码,但我不知道如何找到这个按钮,因为我怎么知道asp自动生成html代码,它使我很难找到这个按钮。 – 2013-02-27 18:44:15
是的自动生成的ID是一个痛苦。如果你发布的JavaScript我可以告诉你如何做的元素选择 – 2013-02-27 18:56:02