当前位置: 移动技术网 > IT编程>开发语言>c# > Asp.Net中避免重复提交和弹出提示框的实例代码

Asp.Net中避免重复提交和弹出提示框的实例代码

2019年07月18日  | 移动技术网IT编程  | 我要评论

前台代码:

 <asp:button id="button1" runat="server" text="打印"  onclick="button1_click" onclientclick="this.value='数据提交中……';this.disabled=true;" usesubmitbehavior="false" />

后台代码:

public partial class webform1 : system.web.ui.page
  {
    protected override void onload(eventargs e)
    {
      stringbuilder pagebase_script = new stringbuilder("<script language=\"javascript\">");
      pagebase_script.append(@"var times=0;
         function pagebase_tick() //用于显示执行的时长
         {
         times++;
            var str = '';
            var temp = times%5;
            for(var i=0;i<temp;i++)
              str+='.';
         document.getelementbyid('pagebase_clocktimes').innerhtml ='正在提交,请稍候'+ str; 
         } "
        );
      pagebase_script.append("<").append("/").append("script>");
      stringbuilder pagebase_div = new stringbuilder(" <div id=\"pagebase_runing\" runat=\"server\" style=\"z-index: 12000; left: 0px; width: 100%; position: absolute; top: 0px; height: 100%\">");
      pagebase_div.append("<table width=\"100%\" height=\"100%\">");
      pagebase_div.append("<tr align=\"center\" valign=\"middle\">");
      pagebase_div.append("<td>");
      pagebase_div.append(" <table width=\"200\" height=\"25\" bgcolor=\"#9999ff\" style=\"filter: alpha(opacity=70); \">");
      pagebase_div.append(" <tr align=\"center\" valign=\"middle\">");
      pagebase_div.append("  <td>");
      pagebase_div.append("<div style=\"width:200px;height:25px; background-color: #99ccff; \">");
      pagebase_div.append("     <div id=\"pagebase_clocktimes\" style=\"color: #ff0000; float:left; width:196px;height:21px \" >正在提交,请稍候</div>");
      pagebase_div.append("</div>");
      pagebase_div.append("</td>");
      pagebase_div.append(" </tr>");
      pagebase_div.append(" </table>");
      pagebase_div.append(" </td>");
      pagebase_div.append(" </tr>");
      pagebase_div.append(" </table>");
      pagebase_div.append("</div>");
      stringbuilder pagebase_divhide = new stringbuilder("<script language=\"javascript\">");
      pagebase_divhide.append("document.getelementbyid('pagebase_runing').style.visibility = \"hidden\";");
      pagebase_divhide.append("<").append("/").append("script>");
      if (!page.clientscript.isstartupscriptregistered("runingscript"))
      {
        page.clientscript.registerstartupscript(page.gettype(), "pagebase_div", pagebase_div.tostring());
        page.clientscript.registerstartupscript(page.gettype(), "pagebase_script", pagebase_script.tostring());
        page.clientscript.registerstartupscript(page.gettype(), "pagebase_divhide", pagebase_divhide.tostring());
      }
      base.onload(e);
    }
    /// <summary>
    /// 设置提交之后.出现请等待提示,在页面调用基类的这个方法,把要提交的控件传入即可
    /// </summary>
    /// <param name="btn">提交按钮</param>
    public void submitload(button btn)
    {
      btn.attributes.add("onclick", "javascript:document.getelementbyid('pagebase_runing').style.visibility='visible';window.setinterval('pagebase_tick()',500);");
    }
    /// <summary>
    /// 设置提交之后.出现请等待提示
    /// </summary>
    /// <param name="lbtn">提交按钮</param>
    public void submitload(linkbutton lbtn)
    {
      lbtn.attributes.add("onclick",
                 "javascript:document.getelementbyid('pagebase_runing').style.visibility='visible';window.setinterval('pagebase_tick()',1000);");
    }
    protected void page_load(object sender, eventargs e)
    {
      submitload(button1);
    }
    protected void button1_click(object sender, eventargs e)
    {
      button1.enabled=false;
      //string ip = printinglabel.searchprinterip(textbox1.text, textbox2.text, textbox3.text);
      //response.write(ip);
      int ifs=0;
      for (int i = 0; i < 1000000000; i++)
      {
        ifs++;
      }
    }
  }
}

以上所述是小编给大家介绍的asp.net中避免重复提交和弹出提示框的实例代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网