AsyncPostback Trigger - 未发送回文本框值

时间:2015-06-02 16:41:11

标签: c# asp.net

我的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)的值在失去焦点时会被发送回服务器?发生异步回发但没有值。

1 个答案:

答案 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;
}