VS.NET中事件丢失的避免方法
来源:互联网 发布:sql 添加默认值约束 编辑:程序博客网 时间:2024/05/26 12:54
VS.NET中事件丢失的避免方法
在vs.net中经常遇到事件丢失的问题,可以这样避免一下
方法一:
把InitializeComponent中的注册事件,如下
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
}
剪切到override protected void OnInit(EventArgs e)里面,如下
方法二:
把InitializeComponent中的注册事件,如下
剪切到你的自定义方法中
然后在pageload中调用自定义方法就可以了,如
每次需要注册方法时,就在刚才的剪切区注册就可以了,这样虽然麻烦一些,但是可以保证事件不会丢失。
摘自 : http://blog.csdn.net/jelink/archive/2006/09/23/1269751.aspx
在vs.net中经常遇到事件丢失的问题,可以这样避免一下
方法一:
把InitializeComponent中的注册事件,如下
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
}
剪切到override protected void OnInit(EventArgs e)里面,如下
override protected void OnInit(EventArgs e)
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
方法二:
把InitializeComponent中的注册事件,如下
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
剪切到你的自定义方法中
private void LoadEvent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
然后在pageload中调用自定义方法就可以了,如
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
LoadEvent();
}
}
{
if(!Page.IsPostBack)
{
LoadEvent();
}
}
每次需要注册方法时,就在刚才的剪切区注册就可以了,这样虽然麻烦一些,但是可以保证事件不会丢失。
摘自 : http://blog.csdn.net/jelink/archive/2006/09/23/1269751.aspx
- VS.NET中事件丢失的避免方法
- VS.NET中事件丢失的避免方法
- 寻找VS.Net 2005中SQL Server 的丢失的组件
- 在VS.NET 的项目中使用生成事件
- vs.net 2005中web.config智能感知丢失时
- vs.net 2005中web.config智能感知丢失时
- vs.net 2005中web.config智能感知丢失时
- 关于vs.net2003的WEB页面事件丢失?
- Talking about 关于vs.net2003的WEB页面事件丢失?
- 避免移动终端设备数据丢失的十个方法
- 关于jquery中丢失事件的问题
- vs.net 2005中引用webservice的简单方法
- 修复.NET中通过HttpWebRequest 中GET 方法丢失Cookie的bug
- ASP.Net中session丢失的解决办法
- asp.net中Session丢失的原因
- asp.net在IE10下事件丢失的原因分析
- 找回VS工具栏中丢失的行缩进按钮
- VS中丢失ArcGis 控件和模板的解决方法
- 汇编指令
- spss 中的数据录入格式
- 在使用 Response.End、Response.Redirect 或 Server.Transfer 时出现 ThreadAbortException
- ajax: 用户体验之进度条
- 我想好了,去深圳
- VS.NET中事件丢失的避免方法
- 2007年2月26日上午的学习
- OpenSSL for windows
- RowFilter的使用.....
- tomcat+MYSQL+proxool 的配置介绍!
- 2.6 Qt提供的控件和对话框类(Built-in Widget and Dialog Classes)
- C语言面试题(2)——华为
- javascript 小技巧(自己总结)
- 对爱情,迷糊。。。