Dynamic Controls and View State

  • Thread starter Thread starter Sunil Menon
  • Start date Start date
S

Sunil Menon

Dear All,
We all always have a problem dynamic controls and
ViewState...Suppose we want to create dynamic Controls on Load of the
page and Save its value in the ViewState and get them back, will it be
asking for too much...I guess no...:-)
I have found a solution that I want to share in this newsgroup...
1. Write a page Class 'basePage.cs'.
2. In this page class write two functions :
SaveCtrlViewState(id, val) { ViewState[id] = val }
GetCtrlViewState(id, val) { val = ViewState[id] }
3. Derive your page from this page class.
4. Define your control and instead of saving the information in its
ViewState call the above function using reflection.
5. When you want the ViewState value of that control just call the
page's
GetCtrlViewState.

I found this workflow very simple and easy to use. Have I overlooked
any major mistakes?
Paul Wilson: It would be nice to have your comments too regarding
this.

Thanks & Regards
Sunil
 
I assume basePage.cs derives from Page. I see nothing wrong with this
methodology, as it is very similar to what is happening beneath the hood.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top