Link to home
Start Free TrialLog in
Avatar of mlg101
mlg101Flag for United States of America

asked on

RadioButton list conditional statement to response.redirect

I am trying to redirect a user to a specific url, depending on which radio button is selected in a autopostback prodedure on the radiobuttonlist. Each time, no matter which selection is chosen, however, it redirects to the first url listed in the conditional statement (ResultsTest2.aspx). Below is my code. Is there another way to code this so it works? thank you.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Request.QueryString("MMP") = "True" Then
            Dim List As ListItem = RadioButtonList1.Items.FindByValue("Standard")
            List.Selected = True
        ElseIf Request.QueryString("STHP") = "True" Then
            Dim List As ListItem = RadioButtonList1.Items.FindByValue("Short")
            List.Selected = True
        ElseIf Request.QueryString("HSA") = "True" Then
            Dim List As ListItem = RadioButtonList1.Items.FindByValue("HSA")
            List.Selected = True
        End If
End Sub
 
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        
        If RadioButtonList1.SelectedItem.Value = "Standard" Then
            Response.Redirect("ResultsTest2.aspx)
        ElseIf RadioButtonList1.SelectedItem.Value = "Short" Then
            Response.Redirect("ResultsTest3.aspx)
        ElseIf RadioButtonList1.SelectedItem.Value = "HSA" Then
            Response.Redirect("ResultsTest4.aspx)
        End If
 
<HTML>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Size="X-Small"
                    OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="True" RepeatDirection="Horizontal">
                    <asp:ListItem Value="Standard">Standard Medical Plans</asp:ListItem>
                    <asp:ListItem Value="Short">Short Term Medical Plans</asp:ListItem>
                    <asp:ListItem Value="HSA">Health Savings Account Eligible (HSA)</asp:ListItem>
                </asp:RadioButtonList>
    End Sub

Open in new window

Avatar of mlg101
mlg101
Flag of United States of America image

ASKER

As a side note, the page load populates the radiobutton list when the page first loads to the selection that was chosen on the previous page. When a user then clicks on a radio button on this page, it reloads the page (autopostback), then I have a querystring (which is didnt put on this post) that is supposed to keep the new selection, based on page load.

I just need it to go to the correc URL, based on their selection first though.
Avatar of liqiug
liqiug

you have populate the radiobutton list on page_load event, so you should add
if not page.ispostback then
   .......
end if
to avoid the event has run when the autopostback triggered
for your case. you run the page_load everytime you change in the radiobutton,
so you are always reset the valus and always go to first url
ASKER CERTIFIED SOLUTION
Avatar of liqiug
liqiug

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mlg101

ASKER

Perfect. Thank you!