Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem: Adding a control and not finding it on postback

Reply
Thread Tools

Problem: Adding a control and not finding it on postback

 
 
Luiz Vianna
Guest
Posts: n/a
 
      02-09-2005
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
 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      02-10-2005
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


"Luiz Vianna" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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
 
Reply With Quote
 
 
 
 
Luiz Vianna
Guest
Posts: n/a
 
      02-10-2005
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]" <(E-Mail Removed)> escreveu na mensagem news:%(E-Mail Removed)...
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


"Luiz Vianna" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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
 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      02-10-2005
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


"Luiz Vianna" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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]" <(E-Mail Removed)> escreveu na mensagem news:%(E-Mail Removed)...
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


"Luiz Vianna" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the javascript that disables postback the postback control? gnewsgroup ASP .Net 1 02-13-2008 10:45 PM
Adding a Dynamic User Control from the Base Page Class (and retaining it on Postback?) David Bowey ASP .Net Building Controls 2 04-05-2005 08:17 AM
Adding a Dynamic User Control from the Base Page Class (and retaining it on Postback?) David Bowey ASP .Net Web Controls 2 04-05-2005 08:17 AM
Newbie : Adding an onclick event to server control, prevents postback.??? Dr Deadpan ASP .Net 3 11-21-2003 11:46 AM
URGENT !! Finding the control ID that sent postback in Page_Load Abhijit Kothiwale ASP .Net Web Controls 0 11-10-2003 09:06 AM



Advertisments