Jude Jude - 1 year ago 172
ASP.NET (C#) Question

How DropDownList's SelectedIndexChanged() works without PostBack?


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>();
var columnNames= from t in typeof(Person).GetProperties() select t.Name;
foreach (var item in columnNames)
ListBox1.DataSource = list;

Answer Source

You could put the DropDownList into an <asp:UpdatePanel> and set AutoPostBack="true" on the DropDownList. You have to set the trigger to the SelectedIndexChanged event.

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

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <asp:DropDownList ID="drop1" runat="server" OnSelectedIndexChanged="ddlTablo_SelectedIndexChanged" />
      <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download