Problem: Adding a control and not finding it on postback

Discussion in 'ASP .Net Web Controls' started by Luiz Vianna, Feb 9, 2005.

  1. Luiz Vianna

    Luiz Vianna Guest

    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
    Luiz Vianna, Feb 9, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message news:...
    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
    Steve C. Orr [MVP, MCSD], Feb 10, 2005
    #2
    1. Advertising

  3. Luiz Vianna

    Luiz Vianna Guest

    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]" <> escreveu na mensagem news:%...
    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" <> wrote in message news:...
    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
    Luiz Vianna, Feb 10, 2005
    #3
  4. 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" <> wrote in message news:...
    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]" <> escreveu na mensagem news:%...
    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" <> wrote in message news:...
    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
    Steve C. Orr [MVP, MCSD], Feb 10, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dr Deadpan
    Replies:
    3
    Views:
    4,022
    Dr Deadpan
    Nov 21, 2003
  2. gnewsgroup
    Replies:
    1
    Views:
    387
    gnewsgroup
    Feb 13, 2008
  3. David Bowey
    Replies:
    2
    Views:
    205
    Nick Stansbury
    Apr 5, 2005
  4. Abhijit Kothiwale

    URGENT !! Finding the control ID that sent postback in Page_Load

    Abhijit Kothiwale, Nov 10, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    126
    Abhijit Kothiwale
    Nov 10, 2003
  5. David Bowey
    Replies:
    2
    Views:
    207
    Nick Stansbury
    Apr 5, 2005
Loading...

Share This Page