C
Chuck Ritzke
Hi,
I've searched the newsgroup and other sources to understand how to handle
runtime controls and see I'm not the only one who's confused, but I'm still
not quite sure of the best way to handle from all the various
explanations/answers. I'm attempting the typical scenario...
I create a variable number of controls at runtime based on parameters from a
database.
I understand that I need to re-initialize the controls with the same ID upon
post-back so that the code-behind can see the controls and it's properties.
I also learned that I need to do so in Page_Init instead of Page_Load or the
code-behind won't be able to see the value of the control as
entered/selected by the user. (What's really odd to me when I tried to
initialize in Page_Load, is that somehow, somewhere, the value of those
controls must still exist because, even though I can't get to the value in
code-behind, the value does still get passed back to the browser in the
returning page. I just don't get why I can't get to that value if it's still
there.)
So anyway, I figure I should avoid going back to the database on postback.
So I store the initialization parameters in Viewstate. But of course,
Viewstate isn't available yet in Page_Init. So it seems that I'm forced to
go back to the database to get the initialization parameters (or use Session
or other memory state which I don't think I want to do). But this seems to
defeat almost the whole purpose of Viewstate enabled controls in the
firstplace. If I have to go back to the database anyway, what is the value
in a viewstate enabled runtime control?
Is returning to the database the only/best way to handle these controls, or
am I missing a trick?
Thanks in advance,
Chuck
I've searched the newsgroup and other sources to understand how to handle
runtime controls and see I'm not the only one who's confused, but I'm still
not quite sure of the best way to handle from all the various
explanations/answers. I'm attempting the typical scenario...
I create a variable number of controls at runtime based on parameters from a
database.
I understand that I need to re-initialize the controls with the same ID upon
post-back so that the code-behind can see the controls and it's properties.
I also learned that I need to do so in Page_Init instead of Page_Load or the
code-behind won't be able to see the value of the control as
entered/selected by the user. (What's really odd to me when I tried to
initialize in Page_Load, is that somehow, somewhere, the value of those
controls must still exist because, even though I can't get to the value in
code-behind, the value does still get passed back to the browser in the
returning page. I just don't get why I can't get to that value if it's still
there.)
So anyway, I figure I should avoid going back to the database on postback.
So I store the initialization parameters in Viewstate. But of course,
Viewstate isn't available yet in Page_Init. So it seems that I'm forced to
go back to the database to get the initialization parameters (or use Session
or other memory state which I don't think I want to do). But this seems to
defeat almost the whole purpose of Viewstate enabled controls in the
firstplace. If I have to go back to the database anyway, what is the value
in a viewstate enabled runtime control?
Is returning to the database the only/best way to handle these controls, or
am I missing a trick?
Thanks in advance,
Chuck