您的位置:首页 > 其它

防止页面在提交的过程中多次点击按钮

2008-09-23 22:12 441 查看
今天正好碰到这个问题,由于按钮多次点击会造成额外的错误,下面主要是利用javascript脚本,在提交的过程中禁用按钮,这里主要解决多次点击,不包括F5刷新,下面贴上代码,大家一看就会明白。写程序还得多动手。

首先是前台页

using System;

using System.Collections;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

namespace DebugDemo

{

public partial class _Default : System.Web.UI.Page,IPostBackEventHandler

{

static int i = 0;

protected void Page_Load(object sender, EventArgs e)

{

if (!this.IsPostBack)

{

}

this.btnTest.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(btnTest, ""));

}

protected void btn_Click(object sender, EventArgs e)

{

i++;

txtName.Text +=txtName.Text+ "sajdfjas;ldf";

txtName.Text = i.ToString();

if (i == 1)

Response.Redirect("http://news.163.com");

else

Response.Redirect("http://www.google.com");

}

#region IPostBackEventHandler Members

public void RaisePostBackEvent(string eventArgument)

{

}

#endregion

}

}


上面代码中,为实现GetPostBackEventReference的正确应用就继承了IPostBackEventHandler接口,RaisePostBackEvent方法是接口中的成员,由于我只是防止出错而不进行其它操作,所以就不对方法进行实现。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐