我的UpdatePanel
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" UpdateMode="Conditional"
runat="server" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtName"
EventName="TextChanged"/>
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server"
AutoPostBack="true" OnTextChanged="txtName_TextChanged" />
<asp:TextBox ID="txtPhone" runat="server" AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
为什么我的文本框(txtName)的值在失去焦点时会被发送回服务器?发生异步回发但没有值。
答案 0 :(得分:1)
EventName 应为 EventName =&#34; TextChanged&#34; 。
TextChanged 是 TextBox 控件的默认设置,因此您甚至不需要设置它。
AsyncPostBackTrigger.EventName Property
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" UpdateMode="Conditional"
runat="server" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtName"
EventName="TextChanged"/>
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server"
AutoPostBack="true" OnTextChanged="txtName_TextChanged" />
<asp:TextBox ID="txtPhone" runat="server" AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
protected void txtName_TextChanged(object sender, EventArgs e)
{
string name = txtName.Text;
}