ASP.NET OnSelectedIndexChanged DropDownList event not fired

I am trying to use some AJAX and ASP.Net together to allow me to run functions without having to refresh the whole page, but I ran into a problem with this

Here is my code

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" /> <asp:TextBox runat="server" ID="txt1" /> </ContentTemplate> </asp:UpdatePanel> 

And here is my code for

  Sub update1(ByVal sender As Object, ByVal e As EventArgs) txt1.Text = Now.ToString End Sub 

The event does not fire because I do not have AutoPostBack="True" on my ddl, but adding that ddl will return the whole page.

Is there a way to avoid using AutoPostBack="True" so that it only refreshes the panel?

I know I can use asp:Button to get around this, but I really would like to be able to use ddl with OnSelectedIndexChanged

thanks

+7
source share
2 answers

If you want to not send the entire view server to the server, you should look at callbacks .

Instead, if you want to avoid refreshing the entire page, but with postback, this should work:

 <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" AutoPostBack="True" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostbackTrigger ControlID="ddl1" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <asp:TextBox runat="server" ID="txt1" /> </ContentTemplate> </asp:UpdatePanel> 
+7
source

Try creating a new page with the same codes and different page names. Worked for me

0
source

All Articles