点击button第一次登陆后.我刷新页面发现button的click事件会在刷新时再次被激发,实在不明白我又没放到load里怎么会每次都激发,请大虾指点
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using myWebsite.middle;
using myWebsite.error;
namespace myWebsite
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
passworderror pa=new passworderror();//包含所有判断的库
protected System.Web.UI.WebControls.DataList DL_Leave_Word;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
MLeave_Word_2 Mw=new MLeave_Word_2();
Mcustomer Mc=new Mcustomer();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DL_Leave_Word.DataSource=Mw.Leave_Word();
DL_Leave_Word.DataBind();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text==""||TextBox2.Text=="")
{
pa.empty();
}
else
{
DataSet Ds=Mc.Login_DataSet(TextBox1.Text,TextBox2.Text);
int result=Ds.Tables[0].Rows.Count;
if(result>0)
{
Session["Customer_id"]=Ds.Tables[0].Rows[0].ItemArray[0];
pa.password(result);
//Response.Redirect("WebForm1.aspx");
}
else
{
pa.password(result);
}
}
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using myWebsite.middle;
using myWebsite.error;
namespace myWebsite
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
passworderror pa=new passworderror();//包含所有判断的库
protected System.Web.UI.WebControls.DataList DL_Leave_Word;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
MLeave_Word_2 Mw=new MLeave_Word_2();
Mcustomer Mc=new Mcustomer();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DL_Leave_Word.DataSource=Mw.Leave_Word();
DL_Leave_Word.DataBind();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text==""||TextBox2.Text=="")
{
pa.empty();
}
else
{
DataSet Ds=Mc.Login_DataSet(TextBox1.Text,TextBox2.Text);
int result=Ds.Tables[0].Rows.Count;
if(result>0)
{
Session["Customer_id"]=Ds.Tables[0].Rows[0].ItemArray[0];
pa.password(result);
//Response.Redirect("WebForm1.aspx");
}
else
{
pa.password(result);
}
}
}
}
}
解决方案 »
- 技术难题,高手请进,【AjaxPro2】 和 【RecordSet】 的问题,高分寻求解决方案!!
- c#操作Excel时出现错误
- 最后50分,还是老问题! 马上结贴(60分全部送上)
- 求vs.net2005的下载地址,马上给分!!!
- .net基础是什么呀
- 为什么这样取不到值,错在哪里?myUserID=dgi.Cells[1].Text.ToString().Trim();取出的值为"",但这一列明明有值呀?
- 怎样使用户必须通过登录才可以访问站点?
- 好像用ASP.NET的人比较多,但我想听听对WinForm的评价,它是否实用?
- 初学,简单,帮我看看为什么出错
- 有人能详细讲一下session,application,viewstate等的区别吗?
- 从A页弹出B页,本来打开的汉字输入法,又关闭了,有办法吗
- 谁能帮我解答?
Page_Load
{
if(Page.IsPostBack) //加这句
{
...;//初始化操作代码
}
}这样,只要不跳出此页面,if语句里面的代码只执行一次。也就是说if语句只有第一次为 true
-------------
我也遇到了,我也没办法解决,点击按钮的时候实际上是提交本页,所以在IE的后腿按钮里会有一个历史记录.此时刷新等于重新运行按钮的事件.有的时候可以用JS来避免的,location.replace("http://www.sohu.com")这样就不会有历史记录了,也就不存在你说的刷新问题了.不过不是好办法.
{
if(Page.IsPostBack) //加这句
{ }
}
{
if(Page.IsPostBack) //加这句
{ }
}
+这句没用的