Redian新闻
>
Answer Re: ASP.NET 难题测试 (1)
avatar
Answer Re: ASP.NET 难题测试 (1)# DotNet - 窗口里的风景
p*p
1
你说得没错。
具体地说,是DropDownList 的 TrackViewState() 在第一个"before" item假如前还没有
被执行。
Page_Init
TrackViewState() called, 但这时候这个DropDownList还不存在。
Page_Load
ddlDynamic = new DropDownList()
ddlDynamic.Items.Add("before") - ddlDynamic的TrackViewState() not
called, 所以这时候加入的item没有被保存在ViewState里,postback后就丢失了
form1.Controls.Add(ddlDynamic); - 当一个Control加入到一个control hierachy
tree时,它的父节点会对他初始化,让这个Control及其子节点到达父节点的状态。因为
这时Page已经inited, 所以,Control_Init会执行,Control_TrackViewState() called.
ddlDyna
avatar
b*e
2
Wow, really ASP.NET guru. Thanks for sharing this question.
By the way, do you know if there are any good books about ASP.NET
component (user control/custom control) design?

【在 p*p 的大作中提到】
: 你说得没错。
: 具体地说,是DropDownList 的 TrackViewState() 在第一个"before" item假如前还没有
: 被执行。
: Page_Init
: TrackViewState() called, 但这时候这个DropDownList还不存在。
: Page_Load
: ddlDynamic = new DropDownList()
: ddlDynamic.Items.Add("before") - ddlDynamic的TrackViewState() not
: called, 所以这时候加入的item没有被保存在ViewState里,postback后就丢失了
: form1.Controls.Add(ddlDynamic); - 当一个Control加入到一个control hierachy

avatar
p*p
3
Microsoft Press has a book: Developing Microsoft ASP.NET Server Controls and
Components. It's the best book about ASP.NET that I have ever see. Strongly
recommend.
Besides, the ASP.NET source code helps a lot on understanding how ASP.NET
works. You can use Reflector to see decompiled-code, or download the Mono
project source code. The Mono source code looks exactly the same as the
decompiled MS implementation. :)


没有
hierachy
因为
called.
上一
DropdownList

【在 b*e 的大作中提到】
: Wow, really ASP.NET guru. Thanks for sharing this question.
: By the way, do you know if there are any good books about ASP.NET
: component (user control/custom control) design?

avatar
n*g
4

do it in Page_Init is a better choice?
I met the similar problem before but I didn't figure out the detail.
I solved the problem by move the code to Page_Init.

【在 p*p 的大作中提到】
: 你说得没错。
: 具体地说,是DropDownList 的 TrackViewState() 在第一个"before" item假如前还没有
: 被执行。
: Page_Init
: TrackViewState() called, 但这时候这个DropDownList还不存在。
: Page_Load
: ddlDynamic = new DropDownList()
: ddlDynamic.Items.Add("before") - ddlDynamic的TrackViewState() not
: called, 所以这时候加入的item没有被保存在ViewState里,postback后就丢失了
: form1.Controls.Add(ddlDynamic); - 当一个Control加入到一个control hierachy

avatar
k*i
5
exactly.
We might need not to know the implementation detail of asp.net but we
definitely need to know the event sequence which is well documented.

没有
hierachy
因为
called.
上一
DropdownList

【在 n*********g 的大作中提到】
:
: do it in Page_Init is a better choice?
: I met the similar problem before but I didn't figure out the detail.
: I solved the problem by move the code to Page_Init.

avatar
k*i
6

similar one would be Building ASP.NET Server Controls




【在 p*p 的大作中提到】
: Microsoft Press has a book: Developing Microsoft ASP.NET Server Controls and
: Components. It's the best book about ASP.NET that I have ever see. Strongly
: recommend.
: Besides, the ASP.NET source code helps a lot on understanding how ASP.NET
: works. You can use Reflector to see decompiled-code, or download the Mono
: project source code. The Mono source code looks exactly the same as the
: decompiled MS implementation. :)
:
:
: 没有

avatar
p*p
7
No, it won't help if the code is moved into Page_Init(), for the same reason:
when adding the "Before" item, the dropdownlist_TrackViewState is not called.
so, any state change will not be saved untill dropdownlist is added.
I read a MSDN article in which claims that the dynamically created controls
must be added at the Page_Init() stage, in fact, that's not correct .
Page_Init() is not the only time that the control will be initialized. When
new control is added at run time, the parent control

【在 n*********g 的大作中提到】
:
: do it in Page_Init is a better choice?
: I met the similar problem before but I didn't figure out the detail.
: I solved the problem by move the code to Page_Init.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。