亲宝软件园·资讯

展开

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

.net 流氓 人气:0
想了解Asp.Net中避免重复提交和弹出提示框的实例代码的相关内容吗,.net 流氓在本文为您仔细讲解asp.net 避免重复提交和弹出提示框的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:.net,避免重复提交,.net弹出提示框,下面大家一起来学习吧。

前台代码:

 <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中避免重复提交和弹出提示框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

加载全部内容

相关教程
猜你喜欢
用户评论