无法获取面板中文本框的值

Can't get value of a textbox inside panel

本文关键字:文本 中文 获取      更新时间:2023-09-26

我现在不知道为什么我无法获得此控件的值。我试过两件事,我做错了什么?

文本框中的值不为 null(有一个值,在 page_load 中设置)。

我的文本字段:

 asp:UpdatePanel ID="pnlInstruments" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
 <asp:Panel ID="plStore" runat="server" GroupingText="Store">
       <div style="margin: 5px;">
       <asp:Label ID="Label6" runat="server" SkinID="header2NonBoldSkin" Text="Reval date" /><br />
       <asp:TextBox ID="txtText" runat="server" />
       <asp:Button runat="server" ID="btnStore" Text="&nbsp;&nbsp;Store&nbsp;&nbsp;" OnClick="btnStore_Click" 
           OnClientClick="return confirm('Are you sure to store data for ' + getRevalDate() +'?');" />
  </asp:Panel>
 </ContentTemplate>     
 </asp:UpdatePanel>

JS(值为空),元素为空...:

function getRevalDate() {
        return document.getElementById('<%= txtText.ClientID %>').value;
    }

也尝试了这个(相同的结果):

function getRevalDate() {
        return document.getElementById('<%= plStore.FindControl("txtText").ClientID %>').value;
    }

将面板放在更新面板和内容模板中。因此,它将在回发时刷新更新面板的内容。

<asp:UpdatePanel ID="updatePannel" runat="server">
    <ContentTemplate>
    <asp:Panel ID="plStore" runat="server" GroupingText="Store">
       <div style="margin: 5px;">
       <asp:Label ID="Label6" runat="server" SkinID="header2NonBoldSkin" Text="Reval date" /><br />
       <asp:TextBox ID="txtText" runat="server" />
       <asp:Button runat="server" ID="btnStore" Text="&nbsp;&nbsp;Store&nbsp;&nbsp;" OnClick="btnStore_Click" 
           OnClientClick="return confirm('Are you sure to store data for ' + getRevalDate() +'?');" />
  </asp:Panel>
  </ContentTemplate>
</asp:UpdatePanel>