title: how to get Text value from TextBox in Datalist
body: <p>i am trying to retrieve Text value from a TextBox when i click on a LinkButton,both of which are in ItemTemplate of a DataList.But it is returning a null value.</p>
  
  <p>this is code of datalist in the aspx page:</p>
  
  <pre><code> &lt;asp:DataList ID="DataList1" runat="server" Width="100%" DataKeyField="UserId" OnItemCommand="itemcommand"
                  OnItemDataBound="Data_Bind"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;table style="width: 100%"&gt;
                          &lt;tr&gt;
                              &lt;td&gt;
                                  &lt;a href="&lt;%#System.String.Format("ViewProfile.aspx?aid={0}",Eval("UserId")) %&gt;"&gt;
                                      &lt;asp:Image ID="Img" Width="100px" Height="80px" BorderStyle="Inset" BorderWidth="2px"
                                          BorderColor="Aqua" runat="server" ImageUrl='&lt;%#System.String.Format("../Content/Upload/{0}", Eval("UserDetail.UserPhoto")) %&gt;' /&gt;
                              &lt;/td&gt;
                              &lt;td &gt;
                                  &lt;asp:Label ID="name" runat="server" Text='&lt;%#Eval("UserDetail.Firstname")%&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;asp:Label ID="lastname" runat="server" Text='&lt;%#Eval("UserDetail.Lastname")%&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="post" runat="server" Text='&lt;%#Eval("Post.post")%&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="3"&gt;
                                  &lt;asp:LinkButton ID="Like" runat="server" CommandName="onLike" CommandArgument='&lt;%# Eval("Post.PostId") %&gt;'&gt;Like&lt;/asp:LinkButton&gt;
                                  &lt;asp:Label ID="lk" runat="server"&gt;&lt;/asp:Label&gt;
                                  &lt;asp:LinkButton ID="Share" runat="server" CommandName="onShare" CommandArgument='&lt;%# Eval("Post.PostId") %&gt;'&gt;Share&lt;/asp:LinkButton&gt;
                                  &lt;asp:Label ID="sh" runat="server"&gt;&lt;/asp:Label&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                          &lt;td colspan="3"&gt;
                            &lt;asp:TextBox ID="txtcomment"  runat="server" Height="40px" Text="abc" Width="600px"&gt;&lt;/asp:TextBox&gt;
                            &lt;input type="text" id="cmnt1" name="cmnt1" runat="server" /&gt;
                             &amp;nbsp;
                              &lt;asp:LinkButton ID="Comment" runat="server" CommandName="onComment" CommandArgument='&lt;%# Eval("Post.PostId") %&gt;'&gt;Comment&lt;/asp:LinkButton&gt;
                          &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td colspan="3"&gt;
                                  &lt;asp:DataList ID="DataList2" runat="server"&gt;
                                      &lt;ItemTemplate&gt;
                                          &lt;table&gt;
                                              &lt;tr&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:Image ID="Img2" Width="50px" Height="40px" BorderStyle="Inset" BorderWidth="2px"
                                                          BorderColor="Aqua" runat="server" ImageUrl='&lt;%#System.String.Format("../Content/Upload/{0}", Eval("UserDetail.UserPhoto")) %&gt;' /&gt;
                                                      &lt;asp:Label ID="fname" runat="server" Text='&lt;%#Eval("UserDetail.Firstname")%&gt;'&gt;&lt;/asp:Label&gt;
                                                      &lt;asp:Label ID="lname" runat="server" Text='&lt;%#Eval("UserDetail.Lastname")%&gt;'&gt;&lt;/asp:Label&gt;
                                                  &lt;/td&gt;
                                                  &lt;td&gt;
                                                      &lt;asp:Label runat="server" ID="cmnts" Text='&lt;%#Eval("Comments.Comment")%&gt;'&gt;&lt;/asp:Label&gt;
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/table&gt;
                                      &lt;/ItemTemplate&gt;
                                  &lt;/asp:DataList&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/ItemTemplate&gt;
  
              &lt;/asp:DataList&gt;
  </code></pre>
  
  <p>and this is the code behind:</p>
  
  <pre><code> protected void itemcommand(object source, DataListCommandEventArgs e)
      {
          if (e.CommandName == "onLike")
          {
              var k = e.CommandArgument;
  
              User ObjUser = new User();
              ObjUser = (User)Session["user"];
              ObjUser.Post.PostId = Convert.ToInt64(k);
  
              PostService.OnLike(ObjUser);
  
              DataList1.DataSource = PostService.GetPosts(ObjUser);
              DataList1.DataBind();
          }
          if (e.CommandName == "onComment")
          {
              var k = e.CommandArgument;
  
              TextBox cmnt = (TextBox) e.Item.FindControl("txtcomment");
              HtmlInputText cmnt1 = (HtmlInputText)e.Item.FindControl("cmnt1");
              User ObjUser = new User();
              ObjUser = (User)Session["user"];
              ObjUser.Post.PostId = Convert.ToInt64(k);
              ObjUser.Comments.Comment = cmnt.Text;
  
              PostService.OnComment(ObjUser);
  
              DataList1.DataSource = PostService.GetPosts(ObjUser);
              DataList1.DataBind();
  
          }
          if (e.CommandName == "onShare")
          {
              var k = e.CommandArgument;
  
              User ObjUser = new User();
              ObjUser = (User)Session["user"];
              ObjUser.Post.PostId = Convert.ToInt64(k);
  
              PostService.OnShare(ObjUser);
  
              DataList1.DataSource = PostService.GetPosts(ObjUser);
              DataList1.DataBind();
  
          }
  
      }
  </code></pre>