ASP.NET中防止页面多次提交的代码实现
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var obj = event.srcElement;
var objs = document.getElementsByTagName('INPUT');
for(var i=0; i< objs.length; i++)
{
if(objs[i].type.toLowerCase() == 'submit')
{
objs[i].disabled = true;
}
}
} //--> < /script>//ASP.NET中防止页面多次提交的代码:asp.netpublic class PreventMultiClick : System.Web.UI.Page {
protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.LinkButton LinkButton1; protected System.Web.UI.WebControls.Button Button3; private void Page_Load(object sender, System.EventArgs e)
{
this.GetPostBackEventReference(this.Button3);
//保证 __doPostBack(eventTarget, eventArgument) 正确注册 if(!IsPostBack)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function')
{
if (Page_ClientValidate() == false)
{
return false;
}
}"); //保证验证函数的执行 sb.Append("if(window.confirm('are you sure?')==false) return false; ");
//自定义客户端脚本 sb.Append("disableOtherSubmit(); ");
// disable所有submit按钮 sb.Append(this.GetPostBackEventReference(this.Button3));
//用__doPostBack来提交,保证按钮的服务器端click事件执行 sb.Append("; ");
Button3.Attributes.Add("onclick",sb.ToString());
}
} #region Web Form Designer generated code override protected void OnInit(EventArgs e)
{
// // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent();
base.OnInit(e);
}
/// < summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// < /summary> private void InitializeComponent()
{
this.Butto
相关文档:
在IIS URL Rewriting 和 ASP.NET routing(上)中,我们针对IIS URL Rewriting 和 ASP.NET routing的理念和功能分别进行分析并进行对比,在清楚了这些基本原理和异同之后,我们该如何在应用中挑选合适的URL优化方案呢?在本文中,我们将对此进行探讨分析,并例举几种两者协同应用的案例。
本文翻译自IIS官方网站,针对国内 ......
使用ASP.NET开发网站时,如果URL中传递的参数过长(具体多长没有测试)的话,在使用IE6浏览时,就会出现通过QueryString获得的值不完整,或者出现乱码的情况。其解决方法是:在Web.config中的System.web配置节中添加如下代码即可:
<globalization requestEncoding="gb2312" responseEncoding="gb2312" ......
Web 部件的一项主要功能是使最终用户能够个性化网页并保存其个性化设置。修改 Web 部件页的一个方面包括编辑可见 WebPart 控件的外观、布局、行为和其他属性。
Web 部件控件集中的几种控件可提供编辑功能。其中包括 EditorZone 控件,该控件是 Web 部件控件集中用于承载网页上的 EditorP ......
1.使用 使用Response.Write,这种方法会把JS代码写在页面的最顶部(的前面):
2. 使用: page.ClientScript.RegisterStartupScript(); 这种方法会把JS代码嵌入在页面的底部、表单的最后 (前面),适用于要在页面控件加载完成后运行的JS代码
3.使用RegisterClientScriptBlock();这种方法会把JS代码嵌入在页面的顶部、 ......
先看看ASP.NET页面刷新的实现方法:
第一:
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); } 第二:
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.locatio ......