代码如下:
<asp:UpdatePanel ID="id">
<asp:CommandField ButtonType="Image" InsertImageUrl="url/here" ShowInsertImage="true" ValidationGroup="valGr" />
</asp:UpdatePanel>如何在C#代码中防止双击此按钮。
发布于 2013-02-28 02:59:51
您可以首先创建一个保存提交的标志,并将其添加到表单中。然后,当UpdatePanel进行更新时,打开并关闭该标志,而while正在等待返回。
例如,此代码仅在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>这里的诀窍是,我让表单提交,而不是查看页面上的每个控件来禁用它。
https://stackoverflow.com/questions/15119729
复制相似问题