I have a problem finding a textbox control which is within panel and this panel is within datalist control. I would like to get textbox.text property and I tried several ways but I always get empty string "" although textbox contain some text in it. My code is below:

aspx page

<asp:DataList ID="dlDataList" runat="server" onitemcommand="dlDataList_ItemCommand">

           <asp:Panel ID="pnlReply" runat="server" Visible="False">
             <asp:TextBox ID="txtTextBox" runat="server"</asp:TextBox><br />
             <asp:LinkButton ID="lnkbtnSend" CommandName="Send" runat="server">Send</asp:LinkButton>
           </asp:Panel><br />

           <asp:LinkButton ID="OpenPanel" CommandName="OpenPanel" runat="server">Open panel</asp:LinkButton>


aspx.cs page

protected void dlDataList_ItemCommand(object source, DataListCommandEventArgs e)

if (e.CommandName == "OpenPanel")
            Panel pnlReply = (Panel)e.Item.FindControl("pnlReply");
            pnlReply.Visible = true;

if (e.CommandName == "Send")
          TextBox txtTextBox = (TextBox)e.item.FindControl("txtTextBox");

          //I tried this way also..
          //TextBox txtTextBox = (TextBox)e.item.FindControl("pnlReady").FindControl("txtTextBox");

          string str = txtTextBox.Text;

Does anyone knows the way to get text property of Textbox control?

Thank you!

You are using the corrent property to get the text but your control is malformed. You have:

<asp:TextBox ID="txtTextBox" runat="server"</asp:TextBox><br />

which should be:

<asp:TextBox ID="txtTextBox" runat="server"></asp:TextBox><br />

commented: good job catching that syntax +6

Are u binding the Datalist in page load ? If yes then put your binding code in Not IsPostback condition.
Or it can be EnableViewState problem.