zoukankan      html  css  js  c++  java
  • 防止多次提交的方法

    a.aspx

       <title>无标题页</title>
        <style type="text/css">
        .disable
         {
             border-style:none;
             border- thin;
             background-color:Transparent;
            color: #CCCCCC;
            cursor:wait;
        }
        </style>

        <script type="text/javascript" language="javascript">
        function DisableButton()
        {
            document.getElementById("Button2").className  = "disable";
            document.getElementById("Button2").value = '正在提交.';
            document.getElementById("Button2").onclick=Function("return false;");

            //return true;
          
        }
        document.onkeydown=mykeydown;  
        function   mykeydown()
        {  
            if(event.keyCode==116) //屏蔽F5刷新键  
            {  
                window.event.keyCode=0;  
                return   false;  
            }  
        }  
        </script>

    </head>
    <body>
        <form id="form1" runat="server">
         <div id="doing"   style="Z-INDEX: 12000; visibility:hidden; LEFT: 0px; WIDTH: 100%; CURSOR: wait; POSITION: absolute; TOP: 0px; HEIGHT: 100%">
                <table  style="100%; height:100%;">
                    <tr align="center" valign="middle">
                        <td>
                            <table width="169" height="62" bgcolor="#99cccc" style="FILTER: Alpha(Opacity=75); WIDTH: 169px; HEIGHT: 62px">
                                <tr align="center" valign="middle">
                                    <td>页面提交中.<br/>
                                        Loading.</td>
                                </tr>
                            </table>
                            </td>
                    </tr>
                </table>
            </div>
        <div>
            <div>
                输入一些内容<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
                <asp:ListBox ID="ListBox1" runat="server" Height="77px" Width="332px"></asp:ListBox><br />
                <asp:Button ID="Button2" runat="server" Text="OK" Width="77px" OnClick="Button2_Click" OnClientClick="return DisableButton();" />
                <asp:Button ID="btnSumbit" runat="server" UseSubmitBehavior="false" OnClientClick="this.value='Sumbit';this.disabled=true; " Text="Sumbit" OnClick="btnSumbit_Click" />
                <asp:Button ID="Button1" runat="server" Text="Loading" OnClick="Button1_Click1" />
            </div>

            </div>
        </form>
    </body>
    </html>

    a.aspx.cs

     public partial class WebForm1 : System.Web.UI.Page
        {
            static public int count = 0;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                   // Button2.Attributes.Add("onclick", "return DisableButton();");
                    this.Button1.Attributes.Add("onclick", "javascript:document.getElementById('doing').style.visibility='visible';");
                }


            }
            //override protected void OnPreRender(EventArgs e)
            //{
            //    doing.Style.Add("visibility", "hidden");
            //}
            //override protected void OnPreRenderComplete(EventArgs e)
            //{
            //    doing.Style.Add("visibility", "hidden");
            //}

            protected void Button2_Click(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(3000);
                count++;
                ListBox1.Items.Add(new ListItem("Hello "+TextBox1.Text + "  这是你第" + count.ToString() + "次点击   " + DateTime.Now.ToString()));
                TextBox1.Text = "";
            }

            protected void btnSumbit_Click(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(3000);
                count++;
                ListBox1.Items.Add(new ListItem("Hello " + TextBox1.Text + "  这是你第" + count.ToString() + "次点击   " + DateTime.Now.ToString()));
                TextBox1.Text = "";
            }

            protected void Button1_Click1(object sender, EventArgs e)
            {
               // doing.Style.Add("visibility", "show");
                System.Threading.Thread.Sleep(3000);
            }
        }

  • 相关阅读:
    CET成绩批量查询
    c++常用库简介
    1985年以来微软、苹果、Google赚了多少钱?
    试试PT建站脚本
    补门~
    网站提交大全
    uniapp接入人身核验小程序
    【odoo】【知识杂谈】关于菜单及记录规则中“非”计算的改造
    【odoo】【知识杂谈】关于odoo二开模块规范的一点思考
    mysql拒绝访问
  • 原文地址:https://www.cnblogs.com/yidianfeng/p/1370700.html
Copyright © 2011-2022 走看看