首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在asp:CommandField中防止双重提交

在asp:CommandField中防止双重提交
EN

Stack Overflow用户
提问于 2013-02-28 02:39:43
回答 1查看 349关注 0票数 0

代码如下:

代码语言:javascript
复制
<asp:UpdatePanel ID="id">
 <asp:CommandField ButtonType="Image" InsertImageUrl="url/here" ShowInsertImage="true" ValidationGroup="valGr" />
</asp:UpdatePanel>

如何在C#代码中防止双击此按钮。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-28 02:59:51

您可以首先创建一个保存提交的标志,并将其添加到表单中。然后,当UpdatePanel进行更新时,打开并关闭该标志,而while正在等待返回。

例如,此代码仅在fAlloToSubmittrue时才允许提交表单(和UpdatePanel)

代码语言:javascript
复制
<script>
    var fAlloToSubmit = true;

    function AllowFormToRun()
    {
      if(!fAlloToSubmit)
          alert("Please wait for the page to fully re-loaded.");

      return fAlloToSubmit;
    }
</script>

在后面的代码中,您可以将其设置在窗体上。

代码语言:javascript
复制
protected void Page_Load(object sender, EventArgs e)
{
   Page.Form.Attributes["onsubmit"] = "return AllowFormToRun();";
}

现在对于UpdatePanel,您可以在进行更新时打开该标志,例如,当您单击该命令时:

代码语言:javascript
复制
<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>

这里的诀窍是,我让表单提交,而不是查看页面上的每个控件来禁用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15119729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档