从嵌套的asp:UpdatePanel回发后,TextBox.Text返回空

时间:2013-10-10 10:47:34

标签: asp.net nested updatepanel postback

这是我的代码:

<asp:UpdatePanel runat="server" ID="UPnlParent" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
        <div><h3>title</h3></div>
             <asp:UpdatePanel runat="server" ID="UPnlChild" UpdateMode="Conditional">
                   <ContentTemplate>
                        <asp:TextBox runat="server" ID="Tb1"></asp:TextBox>
                        <asp:LinkButton runat="server" ID="Btn1" Text="Create" OnClick="Create" />
                   </ContentTemplate>
             </asp:UpdatePanel>
    </ContentTemplate>
</asp:UpdatePanel>

在后面的代码中,我有一个事件“创建”

的功能
protected void Create(object sender, EventArgs e)
    {
        string textFromPostBack= Tb1.Text;
        //do something...
    }

字符串为空。 谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

如果您希望按钮触发回发,则应将该按钮添加为更新面板的触发器:

<asp:UpdatePanel ...>
    <ContentTemplate>
        blablabla
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Btn1" />
    </Triggers>
</asp:UpdatePanel>

更多详情:Click

相关问题