473,503 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2177
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1688
by: Punisher | last post by:
I'm adding checkbox controls to a table dynamically when the form loads for the first time. When a postback occurs, the controls are not maintained in the table. How do I get them to retain...
4
2488
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
4
3090
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
1
2048
by: Jeffrey Todd | last post by:
I have successfully created functionality that mostly models what I'm trying to do - which is dynamically insert controls into a user control (ascx), and insert validation controls, also...
6
1476
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
9
7907
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
1
7588
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
5
4440
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
4
17884
by: jack | last post by:
Hi, Consider the following handler: protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; if (row.RowType != DataControlRowType.DataRow)...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.