Adding controls dynamically problem.

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
Back
Top