Search code examples
asp.netdrop-down-menuautopostback

AutoPostBack= "true" not functioning properly with dropdown list asp.net


I have a dropdown list that is populated with values from a DB table, when you select a value from the list a repeater appears and shows extra details about that selected value. The only problem is that the page only refreshes for the first value selected, if you try to make a different selection the page doesn't change.

The repeater seems to be working fine, but there must be something wrong with the AutoPost back in the dropdown.

<asp:DropDownList ID="DropDownList1" Width="150px" runat="server" DataSourceID="SqlDataSource1" DataTextField="LCID" DataValueField="LCID" EnableViewState="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack= "true" >

 </asp:DropDownList>

this is the code from the aspx.cs file:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

    Response.Redirect("http://localhost:31003/?LCID="+ DropDownList1.SelectedValue);


}
}

If anyone can see what I am missing from my program I would be very grateful, thanks.


Solution

  • you are missing the PageName in Response.Redirect

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("~/PageName.aspx?LCID="+ DropDownList1.SelectedValue);
    }