postback in asp.net !
some value hide in viewstate to handler in server side. if(!Page.Ispostback) means the first time to visit the page.
some value hide in viewstate to handler in server side. if(!Page.Ispostback) means the first time to visit the page.
在InitializeComponent函数里你可以看到事件关联
this.Button1.Click += new System.EventHandler(this.Button1_Click);
否则就会执行两次。
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, System.EventArgs e)
{
string strConn="server=localhost;uid=sa;pwd=;database=test";
SqlConnection objConn=new SqlConnection(strConn);
string strIndex="insert into error values('ddd')";
SqlCommand objComm=new SqlCommand(strIndex,objConn);
objConn.Open();
objComm.ExecuteNonQuery();
objConn.Close();
}