This is driving me nuts!
I am trying to access a TextArea inside the GridView control. The TextArea is popped up when a button on a gridview is clicked. For some reason the textarea.value always contains " ".
<asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="false"
onrowcommand="gvCategories_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="add comment" onclick="showCommentBox()" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<div id="commentBox" style="display:none">
<input type="button" value="move comment input box" onclick="moveComment()" />
<textarea id="txtComment" rows="10" cols="30">
</textarea>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
function moveComment() {
alert(document.getElementById("txtComment").value);
}
I have added this code on the server side but the TextBox always returns " "
protected void gvCategories_RowCommand(object sender, GridViewCommandEventArgs e)
{
var row = (GridViewRow) (e.CommandSource as LinkButton).NamingContainer;
var description = (row.FindControl("txtDescription") as TextBox).Text;
lblComment.Text = description;
}