Going to a specific link on dropdown list item selection - ASP.NET WebForms

Hemanth B 886 Reputation points
2021-06-24T07:25:24.723+00:00

Hi, I added a drop down list in web forms asp.net c#. I double clicked and added this code. Selecting "Length Calculator" should redirect them to another web form. But when I test it, it's not working. But the "Response.Redirect" code works for a button perfectly. Pls help!

  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            if (DropDownList1.SelectedValue == "Length Calculator")  
            {  
                Response.Redirect("Length Converter.aspx");  
            }  
        }  

Image for the dropdown list items108942-sss.png

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-06-25T01:54:52.73+00:00

    Hi @Hemanth B ,
    I suggest you could check if you run the method of SelectedIndexChanged. Do you have add AutoPostBack="true" in the dropdownlist?
    I have created a test and it works.Just like this:

     <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">  
                    <asp:ListItem Value="0" Text="--Select--"></asp:ListItem>  
                    <asp:ListItem Value="Length Calculator" Text="Length Calculator"></asp:ListItem>  
                </asp:DropDownList>  
    
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
            {  
                if (DropDownList1.SelectedValue == "Length Calculator")  
                {  
                    Response.Redirect("2175764.aspx");  
                }  
            }  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.