p*p 发帖数: 75 | 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 |
b*e 发帖数: 3845 | 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
|
p*p 发帖数: 75 | 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?
|
n*********g 发帖数: 75 | 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
|
k****i 发帖数: 1072 | 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.
|
k****i 发帖数: 1072 | 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. :) : : : 没有
|
p*p 发帖数: 75 | 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.
|