方法一:人为移动事件注册代码 #region Web Form Designer generated code override protected void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); this.DataGrid1.ItemCommand+=new DataGridCommandEventHandler(DataGrid1_ItemCommand);//人为的移到这里,就不会再丢失了 } private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); //this.DataGrid1.ItemCommand+=new DataGridCommandEventHandler(DataGrid1_ItemCommand);系统默认加在这里,把它人为的移到上面 }
事件从此不在丢失
原来是在InitializeComponent现在要写在OnInit