How to fire dropdownlist's SelectedIndexChange

2019-09-06 03:08发布

问题:

I've got a DropDownList on my page databound to a query from my database (Databinding is set up only in my .aspx file, not in codebehind). Next to it I have a second DDL that gets populated from the SelectedIndexChanged function of the first one. This works, but only when AutoPostback is set to true.

Is there a way to fire the SelectedIndexChanged event or manually call this function in my codebehind without having to reload the page every time?

回答1:

I would put the DDLs inside an AJAX UpdatePanel so it only updates that part of the page instead of a full page reload.



回答2:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
            Your Stuff with OnSelectedIndexChanged in codebehind
        </ContentTemplate>
    </asp:UpdatePanel>

Rul easy



回答3:

Attach to the <select /> element's onChange event a JavaScript function, and do an AJAX request to a webservice.