RadioButtonList madness...on click it ALWAYS reselects 1st option

Last post 03-26-2009 8:52 AM by cookster1976. 2 replies.

Sort Posts:

  • RadioButtonList madness...on click it ALWAYS reselects 1st option

    03-26-2009, 6:56 AM
    • Member
      17 point Member
    • cookster1976
    • Member since 09-16-2008, 9:59 AM
    • Posts 52

    I have the following set of radio button lists set up on my form. This was on an ajaxtoolkit tab control but i have removed everything else from the page to try and find why this wont work, and im still stuck. Here is the relevant html:

    <asp:UpdatePanel ID="pnlStatutoryConditions" runat="server" UpdateMode="Conditional" >

    <ContentTemplate>

    <asp:Table ID="tblStatCond" runat="server" style="WIDTH: 824px; HEIGHT: 229px" cellSpacing="1" cellPadding="3" width="824" border="1">

    <asp:TableHeaderRow CssClass="gridColHeader" HorizontalAlign="Center" runat="server" >

    <asp:TableHeaderCell runat="server" Width="20%"></asp:TableHeaderCell>

    <asp:TableHeaderCell runat="server" Width="20%">A <br /><br />Asset is Compliant<br /><br /><br /></asp:TableHeaderCell>

    <asp:TableHeaderCell runat="server" Width="20%">B <br /><br />Asset is Non-Compliant, but corrective action is being undetaken</asp:TableHeaderCell>

    <asp:TableHeaderCell runat="server" Width="20%">C <br /><br />Asset is Non-Compliant, but plan of action has been identified</asp:TableHeaderCell>

    <asp:TableHeaderCell runat="server" Width="20%">D <br /><br />Asset is Non-Compliant, and no action is planned<br /><br /></asp:TableHeaderCell>

    </asp:TableHeaderRow>

    <asp:TableRow runat="server">

    <asp:TableCell runat="server" CssClass="gridrow1">Building Standards</asp:TableCell>

    <asp:TableCell ColumnSpan=4 runat="server" CssClass="gridrow1">

    <asp:RadioButtonList ID="rblstBuildingStandards" runat="server" RepeatDirection=Horizontal Width=675px EnableViewState=true AutoPostBack=true>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    </asp:RadioButtonList>

    </asp:TableCell>

    </asp:TableRow>

    <asp:TableRow runat="server">

    <asp:TableCell runat="server" CssClass="gridrow1">Alarms/Detection</asp:TableCell>

    <asp:TableCell ColumnSpan=4 runat="server" CssClass="gridrow1">

    <asp:RadioButtonList ID="rblstAlarmDetect" runat="server" RepeatDirection=Horizontal Width=675px OnSelectedIndexChanged="rblstAlarmDetect_SelectedIndexChanged" EnableViewState=true AutoPostBack=true>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    </asp:RadioButtonList>

    </asp:TableCell>

    </asp:TableRow>

    <asp:TableRow runat="server" >

    <asp:TableCell runat="server" CssClass="gridrow1">Services or Plant</asp:TableCell>

    <asp:TableCell ColumnSpan=4 runat="server" CssClass="gridrow1">

    <asp:RadioButtonList ID="rblstServicePlant" runat="server" RepeatDirection=Horizontal Width=675px EnableViewState=true AutoPostBack=true>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    </asp:RadioButtonList>

    </asp:TableCell>

    </asp:TableRow>

    <asp:TableRow runat="server">

    <asp:TableCell runat="server" CssClass="gridrow1">Food Safety</asp:TableCell>

    <asp:TableCell ColumnSpan=4 runat="server" CssClass="gridrow1">

    <asp:RadioButtonList ID="rblstFoodSafety" runat="server" RepeatDirection=Horizontal Width=675px EnableViewState=true AutoPostBack=true>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    </asp:RadioButtonList>

    </asp:TableCell>

    </asp:TableRow>

    <asp:TableRow runat="server" >

    <asp:TableCell runat="server" CssClass="gridrow1">Other H + S</asp:TableCell>

    <asp:TableCell ColumnSpan=4 runat="server" CssClass="gridrow1">

    <asp:RadioButtonList ID="rblstOtherHS" runat="server" RepeatDirection=Horizontal Width=675px EnableViewState=true AutoPostBack=true>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    <asp:ListItem></asp:ListItem>

    </asp:RadioButtonList>

    </asp:TableCell>

    </asp:TableRow>

    <asp:TableFooterRow>

    <asp:TableCell ColumnSpan=5 CssClass="gridrow1">

    <asp:TextBox id="statCondErrorText" runat="server" ReadOnly=true TextMode=MultiLine width = 75% Wrap=true BackColor="#EFEFEF" Visible=false ForeColor=red/>

    &nbsp &nbsp &nbsp &nbsp &nbsp

    <asp:Button id="btnUpdateStatConditions" runat="server" Text="Update" CssClass="Button" Width="60px" ></asp:Button>

    </asp:TableCell>

    </asp:TableFooterRow>

    </asp:Table>

    </ContentTemplate>

    </asp:UpdatePanel>

     For some reason whenever i click a different button it posts back and then re-selects the first in the list for ALL the radio button lists on the form. So if i clicka radiobutton in the rblstAlarm list and rblstFoodSafety is set at index 2, it resets alarm list selected to 0 and foodsafety to 0 as well.

    I am loading the initial values from a row returned from the database like so:

    Private Sub loadStatCondData(ByVal row As dsStatutoryConditions.dtStatutoryConditionsRow)

    'Set up Building Standards radio button list (only one can be selected):

    If row.SBY_BUILD_STAND_A = 1 Then

    rblstBuildingStandards.Items(0).Selected = True

    Else

    If row.SBY_BUILD_STAND_B = 1 Then

    rblstBuildingStandards.Items(1).Selected = True

    Else

    If row.SBY_BUILD_STAND_C = 1 Then

    rblstBuildingStandards.Items(2).Selected = True

    Else

    If row.SBY_BUILD_STAND_D = 1 Then

    rblstBuildingStandards.Items(3).Selected = True

    End If

    End If

    End If

    End If

    'set up Alarm radio button list (only one can be selected)

    If row.SBY_ALARM_A = 1 Then

    rblstAlarmDetect.Items(0).Selected = True

    Else

    If row.SBY_ALARM_B = 1 Then

    rblstAlarmDetect.Items(1).Selected = True

    Else

    If row.SBY_ALARM_C = 1 Then

    rblstAlarmDetect.Items(2).Selected = True

    Else

    If row.SBY_ALARM_D = 1 Then

    rblstAlarmDetect.Items(3).Selected = True

    End If

    End If

    End If

    End If

    'set up services or plant radion button list (only one can be selected)

    If row.SBY_SERVORPLANT_A = 1 Then

    rblstServicePlant.Items(0).Selected = True

    Else

    If row.SBY_SERVORPLANT_B = 1 Then

    rblstServicePlant.Items(1).Selected = True

    Else

    If row.SBY_SERVORPLANT_C = 1 Then

    rblstServicePlant.Items(2).Selected = True

    Else

    If row.SBY_SERVORPLANT_D = 1 Then

    rblstServicePlant.Items(3).Selected = True

    End If

    End If

    End If

    End If

    'set up food safety radio button list (only one can be selected)

    If row.SBY_FOOD_SAFETY_A = 1 Then

    rblstFoodSafety.Items(0).Selected = True

    Else

    If row.SBY_FOOD_SAFETY_B = 1 Then

    rblstFoodSafety.Items(1).Selected = True

    Else

    If row.SBY_FOOD_SAFETY_C = 1 Then

    rblstFoodSafety.Items(2).Selected = True

    Else

    If row.SBY_FOOD_SAFETY_D = 1 Then

    rblstFoodSafety.Items(3).Selected = True

    End If

    End If

    End If

    End If

    'set up other h&s radio button list (only one can be selected)

    If row.SBY_OTHER_HS_A = 1 Then

    rblstOtherHS.Items(0).Selected = True

    Else

    If row.SBY_OTHER_HS_B = 1 Then

    rblstOtherHS.Items(1).Selected = True

    Else

    If row.SBY_OTHER_HS_C = 1 Then

    rblstOtherHS.Items(2).Selected = True

    Else

    If row.SBY_OTHER_HS_D = 1 Then

    rblstOtherHS.Items(3).Selected = True

    End If

    End If

    End If

    End If

    End Sub

    This is my pageload:

    If Not IsPostBack Then

    Dim sBookedOut As String = Request.QueryString("BookedOut")

    Try

    Dim row As dsStatutoryConditions.dtStatutoryConditionsRow = MyBase.getStatutoryConditionsData()

    loadStatCondData(row)

    Catch ex As Exception

    statCondErrorText.Text = String.Empty

    statCondErrorText.Visible = True

    statCondErrorText.Text = ex.Message

    End Try

    MyBase.S_ID = Request.QueryString("S_ID")

    MyBase.SBY_ID = Request.QueryString("SBY_ID")

    MyBase.Location = Request.QueryString("Location")

    End If

     When i change the radio button selected it postsback ok, and i have tried using the immediate window to get the selectedindex of the radiobuttonlists to see if i need to handle getting the selected radio button when postback is true. But the selectedindex is always zero and the selectedindexchanged event for the control is never hit (even after postback is finished).

    I have ensured that the selected index is never set anywhere else in my code other than the loadStatCondData routine.

    This one has me completely stumped.

     

    ps: Sorry for reams of code, for some reason in get a no xmlhttp error when i try to post it in a code window

  • Re: RadioButtonList madness...on click it ALWAYS reselects 1st option

    03-26-2009, 8:39 AM
    Answer
    • Star
      10,561 point Star
    • getchinna_sv
    • Member since 09-10-2008, 8:29 PM
    • Hyderabad
    • Posts 1,802

    Give some unique value to asp:ListItem

    <asp:RadioButtonList ID="rblstOtherHS" runat="server" RepeatDirection=Horizontal Width=675px EnableViewState=true AutoPostBack=true>
    
    <asp:ListItem Text="" Value="sfdsf"></asp:ListItem>
    
    <asp:ListItem Text="" Value="sfdsfsaf"></asp:ListItem>
    
    <asp:ListItem Text="" Value="sfdsfdsf"></asp:ListItem>
    
    <asp:ListItem Text="" Value="sfdgfdgsf"></asp:ListItem>
    
    </asp:RadioButtonList>
    or use RadioButtons with same group name in each row instead or radiobutton list
     
    Chinna_sv...
  • Re: RadioButtonList madness...on click it ALWAYS reselects 1st option

    03-26-2009, 8:52 AM
    • Member
      17 point Member
    • cookster1976
    • Member since 09-16-2008, 9:59 AM
    • Posts 52

    not that i dont appreciate the help...because I REALLY do, but this answer makes me want to cry. I have spent ages looking at this and that's what the problem was all along! Crying

    thank you though, problem solved Yes

Page 1 of 1 (3 items)