0

I am trying to redirect to another web page when the user selects the drop down list and the user should be redirected to another web page as soon as the user clicks the submit button.This is my code for drop down list and button.On clicking the "click to proceed" button the user should be taken to next web page depending on list selection. Iam new to .Net Please help thanks in advance !!

         <asp:DropDownList ID="DropDownList1" runat="server" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem Value="-1">Select User</asp:ListItem>
        <asp:ListItem Value="staff">Staff</asp:ListItem>
        <asp:ListItem Value="student">Student</asp:ListItem>
        </asp:DropDownList>
        <br />
        <br />
         <br />
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Click to Proceed" />

2 Answers 2

1

In your Button1_Click event, use the Response.Redirect method to send people to the appropriate page.

http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.110%29.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

Following can be helpful for you.

protected void Button1_Click(object sender, EventArgs e)
{
    string sel_val = DropDownList1.SelectedValue; // use sel_val to apply if, else logic to redirect to
    // some possible examples
    if (sel_val != "-1") // as SelectedValue is string
    {
        // assuming there is staff.aspx, and you want to redirect to that page on selecting staff, this is just an example
        Response.Redirect(sel_val + ".aspx"); // use this to redirect to required page
    }

}

Also change aspx code like this.Note i have changed OnClick from onclick.

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click to Proceed" />

11 Comments

if (DropDownList1.SelectedValue == "staff") { Response.Redirect("Logs.aspx"); } I did like this but it failed to redirect @Arindam Nayak
Are you able to debug and see any error? It should work, and you are doing it correctly.
I dont get any error.. When i click the button its still in the same page :-( @Arindam Nayak
You can remove this onselectedindexchanged="DropDownList1_SelectedIndexChanged" if you don't need select event, and does that page refresh? i mean does it postback?
I have set AutoPostBack Property of dropdown to false when i click the button ,Yea It gets refreshed @Arindam
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.