我正在尝试同时使用一些 AJAX 和 ASP.Net 以使我能够运行函数而不必刷新整个页面,但我在这样做时偶然发现了一个问题
这是我的代码
<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>
这是我的代码
Sub update1(ByVal sender As Object, ByVal e As EventArgs)
txt1.Text = Now.ToString
End Sub
事件不会触发,因为我没有
AutoPostBack="True"
在我的 ddl 上,但将其添加到 ddl 将回发整个页面。有没有办法避免使用
AutoPostBack="True"
以便它只更新面板?我知道我可以使用
asp:Button
为了解决这个问题,但我真的很想能够使用带有 OnSelectedIndexChanged
的 ddl谢谢
最佳答案
如果你想避免将整个 View 状态发送到服务器,你应该查看 callbacks .
相反,如果您想避免刷新整个页面,但使用回发,这应该有效:
<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>
关于ASP.NET DropDownList SelectedIndexChanged 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5868066/