|
-
Jun 15th, 2009, 09:16 AM
#1
Thread Starter
Not NoteMe
Persisting ViewState on a dynamically created user control
I've got a user control that represents a Parameter for a report. It has controls to pick / type a value as well as a valuechanged event.
I want its value to be persisted across postbacks.
I've got a page which dynamically creates these controls based on the report the user wants to view.
In order to get the report parameters i need to access the page's ViewState.
From doing research it seems i need to create my dynamic controls before LoadViewState occurs, however if i try this obviously i don't have access to the viewstate in order to determine who many controls i should create.
I've tried adding them in the Page_Load event, but have had no luck getting values back from the control's viewstate.
Any help is very much appreciated.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 16th, 2009, 03:14 AM
#2
Re: Persisting ViewState on a dynamically created user control
If you add/create dynamic controls in page_int the viewstate will be accessable in page_load. This is the general rule of thumb with controls added at runtime - it also makes the event handlers work like button click sub.
-
Jun 16th, 2009, 04:07 AM
#3
Thread Starter
Not NoteMe
Re: Persisting ViewState on a dynamically created user control
Thanks for the reply, but i need access to the viewstate in order to determine the number of controls to create so i can't create them in the page_init event.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 16th, 2009, 04:55 AM
#4
Thread Starter
Not NoteMe
Re: Persisting ViewState on a dynamically created user control
It seems the reason i can't create the controls in page_load is that the clientID is inconsistent. Even though i set the ID manually when loading the control it seems that some times the client id is the id of the control, other times it's a 'proper' client id, i.e. prefixed with IDs of parent controls (in this case the master page's content area).
Any thoughts would be very much appreciated as i've pretty much hit a wall with this.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 16th, 2009, 06:14 AM
#5
Re: Persisting ViewState on a dynamically created user control
Hello,
Are you aware that there is a difference between the Server Side ID, and the ClientID. The reason for this is that a control may be rendered several times on the same page. For instance, a textbox called TxtBox1, which is rendered on each row of a GridView. As a result, it has to make the ClientID unique.
Gary
-
Jun 16th, 2009, 06:48 AM
#6
Re: Persisting ViewState on a dynamically created user control
I don't understand what the clientID has to do with server side code? Unfortuneately asp.net does not give full control over clientID but 4.0 will be introducing that feature for us.
I think your in a catch 22 with viewstate needed before you add your controls and your controls needing to be added in page_int so they can take advantage of viewstate.
I have not overriden the load or save viewstate events and I think it could be fraught with problems to add your own values that way. Me I'd probably just go for a cheap work around like stuffing those viewstate value somewhere else
-
Jun 16th, 2009, 07:38 AM
#7
Thread Starter
Not NoteMe
Re: Persisting ViewState on a dynamically created user control
I'm aware the ID and clientID are different.
The clientID is used in serverside code for storeing/retreiving the viewstate (i believe).
My solution for now is to store things in the session variable, but obviously this isn't that create since i've got to manage unique IDs myself (since i can't rely on clientID).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 21st, 2009, 03:42 PM
#8
Re: Persisting ViewState on a dynamically created user control
Store the 'details' of the dynamic control created in a hidden field; read the hidden field to get the value out which could be, for example, the number of rows in your dynamic control. Read it when you need it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|