user2011977
user2011977

Reputation: 29

RadioButtonList Problems populating

I'm loading the radiobuttonlist from the page load event. The radiobuttonlist's are in the panel two, when I click submit in panel one; panel two becomes true and panel one becomes false. My radiobuttonlist seems to double itself in panel two.

 Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    rblUserID.Items.Add("****")
    rblUserID.Items.Add("****")
    rblUserID.Items.Add(txtUserID.Text)
    rblUserID.Items.Add("****")

    rblPassword.Items.Add("12345")
    rblPassword.Items.Add(txtPassword.Text)
    rblPassword.Items.Add("asdfg")
    rblPassword.Items.Add("100101")

    rblYears.Items.Add("26")
    rblYears.Items.Add("20")
    rblYears.Items.Add(txtBirthDate.Text)
    rblYears.Items.Add("13")

    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add(txtEmailAddress.Text)
End Sub

this is my html for the radiobuttonlist

<strike><asp:RadioButtonList ID="rblPassword" runat="server">
        </asp:RadioButtonList></strike>

Im trying to make some form of a quiz doesnt seem to work out for me.

Upvotes: 0

Views: 235

Answers (2)

Abdusalam Ben Haj
Abdusalam Ben Haj

Reputation: 5433

When you click on a Button , a PostBack is generated and the Page_Load is called again, make sure your RadioButtonList code is executed only once by Checking IsPostBack property like this :

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

 If Not Me.IsPostBack Then

    rblUserID.Items.Add("****")
    rblUserID.Items.Add("****")
    rblUserID.Items.Add(txtUserID.Text)
    rblUserID.Items.Add("****")

    rblPassword.Items.Add("12345")
    rblPassword.Items.Add(txtPassword.Text)
    rblPassword.Items.Add("asdfg")
    rblPassword.Items.Add("100101")

    rblYears.Items.Add("26")
    rblYears.Items.Add("20")
    rblYears.Items.Add(txtBirthDate.Text)
    rblYears.Items.Add("13")

    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add("*****@mail.com")
    rblEmail.Items.Add(txtEmailAddress.Text)

 End If

End Sub

Upvotes: 1

John Baker
John Baker

Reputation: 107

Sounds like to me is that your code is doing exactly what it intends to do. Although, your description on what you are trying to accomplish is a bit confusing.

My guess is to check to make sure you haven't already added the items when the page validates again. Or try to make sure the event only loads once or pick a different event that loads the RadioButtonList.

Best of luck to you!

Upvotes: 0

Related Questions