Adding controls dynamically problem.

G

Guest

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 without having re-add them again.
 
N

Nicholas Paldino [.NET/C# MVP]

Punisher,

You have to re-add them again. If you don't, then how is it supposed to
know how to render it? ASP.NET page handlers don't retain state. Rather,
the state is retained through the viewstate, and the state is reconstructed
in the Page. Since the table control doesn't have any viewstate, it can't
retain whether or not you added controls.

You will have to re-add the controls again.

Hope this helps.
 
G

Guest

I thought when you do a postback, it retains the controls on the page. It's
not like a refresh is it? I could understand if it was, but that's not what
I'm wanting to do. I'm wanting to submit a page and then get the values out
of the checkboxes that was added dynamically.

How else can I can get the values from the dynamic added checkboxes?

Nicholas Paldino said:
Punisher,

You have to re-add them again. If you don't, then how is it supposed to
know how to render it? ASP.NET page handlers don't retain state. Rather,
the state is retained through the viewstate, and the state is reconstructed
in the Page. Since the table control doesn't have any viewstate, it can't
retain whether or not you added controls.

You will have to re-add the controls again.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Punisher said:
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 without having re-add them again.
 
G

Guest

Disregard, I'm using a CheckBoxList and it's doing what I want now.

Nicholas Paldino said:
Punisher,

You have to re-add them again. If you don't, then how is it supposed to
know how to render it? ASP.NET page handlers don't retain state. Rather,
the state is retained through the viewstate, and the state is reconstructed
in the Page. Since the table control doesn't have any viewstate, it can't
retain whether or not you added controls.

You will have to re-add the controls again.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Punisher said:
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 without having re-add them again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top