松架东的风声

Web 改变生活, DotNet 改变Web

导航

在asp.net中防止按钮多次点击提交的办法!

asp.net中防止按钮多次点击提交的办法!  
为提交button 加上下面的属性:

 

System.Text.StringBuilder sb = new System.Text.StringBuilder();

                            sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");

                            sb.Append("if (Page_ClientValidate() == false) { return false; }} ");

                            sb.AppendFormat("this.value = '{0}';", this.waitText);

                            sb.Append("this.disabled = true;");

                            sb.Append(this.Page.GetPostBackEventReference(this));

                            sb.Append(";");

                            this.Attributes["onclick"] = sb.ToString();   

 如果页面上没有校验控件. 可以直接用下面的:

 this.Button1.Attributes.Add("onclick",
                "this.value='Please wait...';this.disabled = true;"
                    + this.GetPostBackEventReference(this.Button1));

posted on 2004-09-08 10:03  松架东的风声  阅读(1337)  评论(0)    收藏  举报