469,569 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,569 developers. It's quick & easy.

Dynamically created control disappears after postback.

Hi,
I am creating some web user controls dynamically Using
LoadControl("ABC.ascx")
My user control contains 2 drop down list, 2nd one is loaded based on the
selection in the 1st one.

However whenever I make the selection in the 1st one, the control disappears
after the post back. I tried setting the EnableViewState=true but even that
did not help..
UCTemp ucTemp = (UCTemp)LoadControl("UCTemp.ascx");
ucTemp.EnableViewState = true;
plhInput.Controls.Add(ucTemp);

Does any one know why this is happening?

-Sami
Sep 3 '07 #1
1 2672
"Sami Rehman" <sa*********@4D.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Does any one know why this is happening?
Dynamically created controls do not survive a postback - they need to be
recreated each time the page loads, irrespective of how it loads.

In addition, if they need to be wired up to events, they need to be created
before the Page_Load event e.g. in the Page_Init event...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Donald Xie | last post: by
1 post views Thread by powerranger | last post: by
9 posts views Thread by Chris | last post: by
4 posts views Thread by Craig Buchanan | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.