页面生命周期和自定义控制生命周期问题. [英] Page life cycle and custom contrl Life cycle issue.

查看:117
本文介绍了页面生命周期和自定义控制生命周期问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一种复杂的自定义服务器控件.该项目中有超过20个班级.


我构建项目并在.aspx页中添加自定义控件.我还在页面中放了一个按钮控件.


现在,在按钮单击事件上,我分配了一个自定义控件属性,但它不会对结果产生影响,因为createchildcontrol
事件在按钮单击事件之前首先触发.


我很惊讶.我确定不会发生这种情况,因此我创建了一个新的自定义控件项目,并放入页面并单击一个按钮
控制.但是这里的createchildcontrol事件会在按钮单击事件之后触发,并且属性也会在按钮单击事件上受到影响.


谁能告诉我为什么在第一种情况下,在按钮单击事件之前首先触发createchildcontrol事件?

问候
Imrankhan

I have been working on one complex custom server control. There are more then 20 classes in this project.


I build the project and add custom control in .aspx page. I also put one button control in page.


Now On button click event, I assign one custom control property but it does not affect on result because createchildcontrol
event fires first before button click event.


I was surprised. I was sure this should not happen so I create new custom control project and put in page and take one button
control. But here createchildcontrol event fires after button click event and property is also affected on button click event.


Can anyone tell me why createchildcontrol event fires first before button click event in first case?


Regard
Imrankhan

推荐答案

在一个快速的Google上,我认为您需要在LoadViewState方法中调用sureChildControls.
From a quick google I think you need to call EnsureChildControls in the LoadViewState method.


感谢Christian Graus. br/>
我会尽力让你知道.

但是在第二种情况下,为什么createchildcontrol方法在按钮事件之后调用?

问候
Imrankhan
Thanks Christian Graus.

I will try and let you know.

But in second case, Why createchildcontrol method calls after button event?

Regard
Imrankhan


这篇关于页面生命周期和自定义控制生命周期问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆