mlg101
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
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
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
so you are always reset the valus and always go to first url
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Thank you!
ASKER
I just need it to go to the correc URL, based on their selection first though.