H
hlubocky
I thought I had a good grasp of the problem related to dynamically
creating controls, but it appears that as my application grew in
complexity, the problem has resurfaced. As I understand it, in order
for a dynamically created control to persist its state, it needs to be
created and loaded into the page control hierarchy before the viewstate
is loaded.
The proposed solution, and that which I have been using, has been to
create all of the needed controls in the OnInit, and then when they are
going to be rendered, they will have the appropriate state set by the
loading of the viewstate. This also appears to affect when events are
received on postback. That is, if the control has been created before
viewstate is loaded, then an event on that control will correctly be
received.
My problem is that the dynamic creation of some controls depends on the
values persisted in the viewstate of other controls. This means that I
am unable to create all of the correct controls in OnInit since I don't
know exactly which to create. Here is an example. I have a Table that I
construct myself and render (no bound datagrid). The number of rows to
render depends on the paging settings retrieved when the viewstate is
loaded. If all of the content is text, then it doesn't matter. The
problem is that one column consists of LinkButtons, and if I don't
create the correct subset of the linkbuttons OnInit, then when they are
clicked by the user, the event won't be received on postback. (ie
default paging settings include 50 rows. When I disable default paging
to show say 100 rows, clicking any of the first 50 linkbuttons works
fine, but any after that (which aren't created in OnInit) don't.
Am I understanding the problem correctly? Is there a better solution?
The one I see at the moment is to create all possible LinkButtons in
OnInit(). I have a feeling my limited knowledge of ASP.Net is to blame
here.
Thanks,
--Brian
creating controls, but it appears that as my application grew in
complexity, the problem has resurfaced. As I understand it, in order
for a dynamically created control to persist its state, it needs to be
created and loaded into the page control hierarchy before the viewstate
is loaded.
The proposed solution, and that which I have been using, has been to
create all of the needed controls in the OnInit, and then when they are
going to be rendered, they will have the appropriate state set by the
loading of the viewstate. This also appears to affect when events are
received on postback. That is, if the control has been created before
viewstate is loaded, then an event on that control will correctly be
received.
My problem is that the dynamic creation of some controls depends on the
values persisted in the viewstate of other controls. This means that I
am unable to create all of the correct controls in OnInit since I don't
know exactly which to create. Here is an example. I have a Table that I
construct myself and render (no bound datagrid). The number of rows to
render depends on the paging settings retrieved when the viewstate is
loaded. If all of the content is text, then it doesn't matter. The
problem is that one column consists of LinkButtons, and if I don't
create the correct subset of the linkbuttons OnInit, then when they are
clicked by the user, the event won't be received on postback. (ie
default paging settings include 50 rows. When I disable default paging
to show say 100 rows, clicking any of the first 50 linkbuttons works
fine, but any after that (which aren't created in OnInit) don't.
Am I understanding the problem correctly? Is there a better solution?
The one I see at the moment is to create all possible LinkButtons in
OnInit(). I have a feeling my limited knowledge of ASP.Net is to blame
here.
Thanks,
--Brian