In this tutorial we will show you how to set up a list of radio buttons for the user to select and then click on a submit button that redirects the user to the appropriate page.

1. Open a new Web Site using the ASP.NET Empty Web Site template using Visual Basic and name it anything of your choice.

2. Right click on the solution in Solution Explorer and click Add New Item. Select Visual Basic as the installed template and select Web Form. Leave the name as Default.aspx.

3. In between the opening and closing div tags enter a new paragraph by writing <p> </p>.

4. From the toolbox click and drag a RadioButtonList inside the p tags you created.

5. In between the <asp:RadioButtonList> tags you created enter three ListItems by putting three open and closing <asp:ListItem></asp:ListItem> as shown in the code below:

Code Block
Default.aspx
Adding items to a RadioButtonList is simple with the <asp:ListItem> tag. Adding the Value ID is very important for coding use.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Value="Google">Google</asp:ListItem>
        <asp:ListItem Value="Yahoo">Yahoo</asp:ListItem>
        <asp:ListItem Value="Bing">Bing</asp:ListItem>
        </asp:RadioButtonList>
    </p>
    </div>
    </form>
</body>
</html>

I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.

6. Drag a Button control from the toolbox and place it right underneath the ending “</asp:RadioButtonList>” and change the text to “Submit”.
Code Block
Default.aspx
Adding a button is simple, simply click and drag Button after the closing RadioButtonList tag.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Value="Google">Google</asp:ListItem>
        <asp:ListItem Value="Yahoo">Yahoo</asp:ListItem>
        <asp:ListItem Value="Bing">Bing</asp:ListItem>
        </asp:RadioButtonList>
        <asp:Button ID="Button1" runat="server" Text="Submit" />
    </p>
    </div>
    </form>
</body>
</html>
7. Switch to Design view in Default.aspx. Double click on the “Submit” button we created to take us to the Default.aspx.vb page. You should see a method named Button1_Click as shown in the code block below.
Code Block
Default.aspx.vb
This code identifies the selected radio button and redirects the page to the appropriate website based on the radio button selected.
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgsHandles Button1.Click
        If (RadioButtonList1.SelectedValue.EndsWith("Google")) Then
            Response.Redirect("http://www.google.com")
        ElseIf (RadioButtonList1.SelectedValue.EndsWith("Yahoo")) Then
            Response.Redirect("http://www.yahoo.com")
        ElseIf (RadioButtonList1.SelectedValue.EndsWith("Bing")) Then
            Response.Redirect("http://www.bing.com")
        Else
            MsgBox("Please Select a Website.", _
                vbExclamation, _
                "Select a Website")
        End If
    End Sub

End Class

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect’s help, we were able to avoid any headaches!

Remember that we set the Value property of each button to Google, Yahoo, and Bing? Well now we get to test which button is selected by using that property and redirect the page to the appropriate web site.

Run the page by clicking on the green arrow near the top of the page or by simply pressing F5. When you run the page you will see three radio buttons, Google, Yahoo, and Bing with a button underneath. Click on either radio button and it will redirect you to the appropriate web site.

WebSite9.zip