469,917 Members | 1,631 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Using Dynamically Adding Controls on PostBack

Okay, so I have a base Page class called ArticlesPageBase. This base class
has reads in an overridable ArticleId and Loads the data into a Panel object
in the ContentPlaceHolder of the Master.

The article that it loads from the Database is a xml field that contains
html code for the article. I added some custom html to the database article
called <question id="22" />

When the article contains inline questions are parse out the start and ends
of the article to literal controls and do a
panel.Controls.Add(QuestionControl);

My problem is on PostBack my Master Article Panel container has 0 controls.

Is there a way to make these customer controls persist over postback? I
tried creating a List<QuestionControlsand adding to there in addition to
the panel, but I kept getting serialization errors.
Sep 18 '06 #1
3 2025
How are you dynamically adding? If you add to a container that has ViewState
they should be there.

Question 2: What does your page load look like. Does it reset any page
elements.

Worst case is adding the info necessary to reconstitute a control properly
to viewstate and using the viewstate to rebuild the page. You then look in
your "property bag" for controls to render and render them from viewstate
values. One caveat, if you repaint and want the control to go away, you have
to clear it from ViewState as well.

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

*************************************************
Think outside of the box!
*************************************************
"Ben Dewey" <As*********@hotmail.comwrote in message
news:uO**************@TK2MSFTNGP02.phx.gbl...
Okay, so I have a base Page class called ArticlesPageBase. This base
class has reads in an overridable ArticleId and Loads the data into a
Panel object in the ContentPlaceHolder of the Master.

The article that it loads from the Database is a xml field that contains
html code for the article. I added some custom html to the database
article called <question id="22" />

When the article contains inline questions are parse out the start and
ends of the article to literal controls and do a
panel.Controls.Add(QuestionControl);

My problem is on PostBack my Master Article Panel container has 0
controls.

Is there a way to make these customer controls persist over postback? I
tried creating a List<QuestionControlsand adding to there in addition to
the panel, but I kept getting serialization errors.

Sep 18 '06 #2
Well does a panel have/persist ViewState?

My Custom Control is a using some radio button lists and text boxes that I
need to get postback info from to see whether they answered the question
right. Do I need viewstate to get PostBack data from radiobuttonlists and
textboxes?
Sep 19 '06 #3
I got it working. I had to readd the controls everytime. the issue I was
having was that I was loading them in OnLoad, i moved all the code to
OnInit and it worked.
Sep 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Punisher | last post: by
4 posts views Thread by Bas Groeneveld | last post: by
4 posts views Thread by Harry | last post: by
6 posts views Thread by Bjorn Sagbakken | last post: by
9 posts views Thread by Chris | last post: by
1 post views Thread by jelle.huygen | last post: by
5 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.