Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All, I have a DropDownList in MasterPage which holds Years, and based on the value selected from MasterPage I am creating a session variable.
in Child Control I want to create dynamic controls based on session variables, I created all the required controls in child page but the problem persist while saving the value.

I used PreRender in Child Page which Gives the accurate Session Value from Master Page, but I dynamic control can't save its state (ViewState)
I used PageLoad in Child Page, but in PageLoad I am getting wrong Session Value from Master Page,

any Ideas please, which event should i use in Child Page to both have the accurate value of MasterPage Session and have ViewState of Dynamic Control in Child Page?
Posted
Comments
Sandeep Mewara 28-Jan-11 8:54am    
Are you resetting your session variable in Child page or so? How/Why you get 'wrong Session Value from Master Page' at later stage?
Did you tried to look at usng VS Debugger?
Abdul Rahman Hamidy 28-Jan-11 9:18am    
I just used these 2 statements, R for PreRender and L for PageLoad
Response.Write("R: " + Session["YearID"].ToString());

Response.Write("L: " + Session["YearID"].ToString());

these 2 provides different values.

1 solution

You can't create controls dynamically and expect them to have state if you create them during Page Load or later. There's tons of articles on this on the web. I find the easiest thing to do, is have a hidden control, and in that use javascript to store the values of my dynamically created controls, or if my dynamic controls are limited in scope ( i.e. there's not an infinite number of textboxes possible, for example ), just create them all the time and just hide/show them as needed.
 
Share this answer
 
Comments
Abdul Rahman Hamidy 28-Jan-11 10:19am    
thanks for your reply, but I solved it very easily, I created a property in my MasterPage and Iam
accessing that Property from child controls and OnPageLoad I do create control dynamically which in PageLoad ViewState is there for me, Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900