0

Hi,

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">

       <ItemTemplate>
           <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>

       </ItemTemplate>
</asp:DataList>

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!

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by sebastian3
1

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 />

Votes + Comments
good job catching that syntax
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.