Stop DropDownList In Asp.net webforms from refreshing the page

Alon M picture Alon M · Jul 1, 2011 · Viewed 7.6k times · Source

I have a normal dropdownlist:

<asp:DropDownList ID="kindofser" runat="server" AutoPostBack="True" 
        Height="21px" Width="166px" 
        onselectedindexchanged="kindofser_SelectedIndexChanged">
        <asp:ListItem>שרתי משחק</asp:ListItem>
        <asp:ListItem Value="1">rgrgr</asp:ListItem>
        <asp:ListItem Value="2">rgreger</asp:ListItem>

    </asp:DropDownList>

Everytime I change my option, a SelectedIndexChanged event happens, but the page is refreshed. Can I stop it from happening?

Answer

Akram Shahda picture Akram Shahda · Jul 1, 2011

Omit the AutoPostBack property from the markup.

AutoPostBack gets or sets a value that indicates whether an automatic postback to the server occurs when the selected index has been changed in a DropDownList. The default value of this DropDownList.AutoPostBack is false.

If you need to update a part of your page's data, you could use Partial Page Updates with ASP.NET AJAX.