Problem: Adding a control and not finding it on postback

L

Luiz Vianna

Hi Guys,

I must missing something here:

My page add a Radion Button by program using a code like this:

Dim myRadioButton As New RadioButton
myRadioButton.EnableViewState = True
myRadioButton.ID = "ID1"
myRadioButton.GroupName = "Group1"
myRadioButton.Text = "My Text"
PlaceHolder1.Controls.Add(myRadioButton)

(There is also a button Next that causes the postBack. )

When the page loads I can see the radioButton on the page just fine, but....

When the page is "postbacked" I "go" to the "PlaceHolder1" and it has no controls on it?

Why is that? If I saw the control, it was rendered, wasn't it?

Thanks

Luiz
 
S

Steve C. Orr [MVP, MCSD]

Every time the page post back, it re-loads everything on the page. In most cases ASP.NET handles this automatically, but if you've put in custom code to dynamically add controls, you must re-add them upon each postback.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


Hi Guys,

I must missing something here:

My page add a Radion Button by program using a code like this:

Dim myRadioButton As New RadioButton
myRadioButton.EnableViewState = True
myRadioButton.ID = "ID1"
myRadioButton.GroupName = "Group1"
myRadioButton.Text = "My Text"
PlaceHolder1.Controls.Add(myRadioButton)

(There is also a button Next that causes the postBack. )

When the page loads I can see the radioButton on the page just fine, but....

When the page is "postbacked" I "go" to the "PlaceHolder1" and it has no controls on it?

Why is that? If I saw the control, it was rendered, wasn't it?

Thanks

Luiz
 
L

Luiz Vianna

OK,

but if I "re-add" my control How could I read its previous state?

In this case, how can I read the user's radiobutton selection?

Thanks

Luiz
"Steve C. Orr [MVP, MCSD]" <[email protected]> escreveu na mensagem Every time the page post back, it re-loads everything on the page. In most cases ASP.NET handles this automatically, but if you've put in custom code to dynamically add controls, you must re-add them upon each postback.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


Hi Guys,

I must missing something here:

My page add a Radion Button by program using a code like this:

Dim myRadioButton As New RadioButton
myRadioButton.EnableViewState = True
myRadioButton.ID = "ID1"
myRadioButton.GroupName = "Group1"
myRadioButton.Text = "My Text"
PlaceHolder1.Controls.Add(myRadioButton)

(There is also a button Next that causes the postBack. )

When the page loads I can see the radioButton on the page just fine, but....

When the page is "postbacked" I "go" to the "PlaceHolder1" and it has no controls on it?

Why is that? If I saw the control, it was rendered, wasn't it?

Thanks

Luiz
 
S

Steve C. Orr [MVP, MCSD]

Recreate it without setting the value.
ASP.NET will fill in the value for you.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


OK,

but if I "re-add" my control How could I read its previous state?

In this case, how can I read the user's radiobutton selection?

Thanks

Luiz
"Steve C. Orr [MVP, MCSD]" <[email protected]> escreveu na mensagem Every time the page post back, it re-loads everything on the page. In most cases ASP.NET handles this automatically, but if you've put in custom code to dynamically add controls, you must re-add them upon each postback.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


Hi Guys,

I must missing something here:

My page add a Radion Button by program using a code like this:

Dim myRadioButton As New RadioButton
myRadioButton.EnableViewState = True
myRadioButton.ID = "ID1"
myRadioButton.GroupName = "Group1"
myRadioButton.Text = "My Text"
PlaceHolder1.Controls.Add(myRadioButton)

(There is also a button Next that causes the postBack. )

When the page loads I can see the radioButton on the page just fine, but....

When the page is "postbacked" I "go" to the "PlaceHolder1" and it has no controls on it?

Why is that? If I saw the control, it was rendered, wasn't it?

Thanks

Luiz
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top