asp.netdrop-down-menupostback

How to fire a DropDownList's SelectedIndexChanged() event without full PostBack?


DropDownList's SelectedIndexChanged() Event fills the ListBox on the page. Obviously this posts the page back to the server. Is there any way to make it happen without full postback?

protected void ddlTablo_SelectedIndexChanged(object sender, EventArgs e)
{
    List<string> list = new List<string>();
    ListBox1.Items.Clear();
    var columnNames= from t in typeof(Person).GetProperties() select t.Name;
    foreach (var item in columnNames)
    {
         list.Add(item);
    }
    ListBox1.DataSource = list;
    ListBox.DataBind();
}

Solution

  • You could put the DropDownList into an <asp:UpdatePanel> and set the trigger to the SelectedIndexChanged event of the DropDownList.

    Something like this (don't forget the script manager)

    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <ContentTemplate>
          <asp:DropDownList ID="drop1" runat="server" OnSelectedIndexChanged="ddlTablo_SelectedIndexChanged" />
       </ContentTemplate>
       <Triggers>
          <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
       </Triggers>
    </asp:UpdatePanel>