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.

解决方案 »

  1.   

    这个我知道,我如果在单击事件里加入if(!Page.Ispostback) ,那么当我点击按钮的时候也不会执行了
      

  2.   

    服务器端Button发送到客户端是一个Submit按钮
    在InitializeComponent函数里你可以看到事件关联
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
      

  3.   

    如果你是双击控件进入事件的话,就不用在代码里加onclick事件了。在InitializeComponent函数里已经添加了代码了:this.Button1.Click += new System.EventHandler(this.Button1_Click);
    否则就会执行两次。
      

  4.   

    wendua(嘿呵) :我也没自己加啊,我用的是vs.net都是自动生成的代码
      

  5.   

    override protected void OnInit(EventArgs e)
    {
    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();
    }
      

  6.   

    这个与IsPostBack是无关的,当用refresh时,IE会重复你上一次的submit事件