我想在 AJAX 调用中从服务器获取警报,Update Panel
但有些东西阻止HttpContext.Current.Response.Write
了客户端触发。
这是一个非常简单的aspx正文内容
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- DropDownList doesn't work here -->
</ContentTemplate>
</asp:UpdatePanel>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="1">First</asp:ListItem>
<asp:ListItem Value="2">Second</asp:ListItem>
</asp:DropDownList>
</div>
</form>
这就是我在 VB 中处理它的地方
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Dim alertMsg As String
Dim alertScript As String
'DO OTHER STUFF HERE
alertMsg = String.Format("You Selected {0}", DropDownList1.SelectedItem.Text)
alertScript = String.Format("<script type= text/javascript>alert('{0}');</script>", alertMsg)
System.Web.HttpContext.Current.Response.Write(alertScript)
End Sub
两次 vb 代码都会触发,但它只会在 UpdatePanel 外部而不是内部调用时编写警报消息。
我究竟做错了什么?