Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text value of input from FindControl

Tags:

c#

asp.net

I know now normally you can get the value of a text input using the following:

txtName.Text

But because my input is inside of a LoginView I am using FindControl like this:

LoginView1.FindControl("txtComment")

This successfully find the text input but returns its type rather than the value. Adding the Text function at the end does not work.

like image 313
daveredfern Avatar asked Dec 06 '10 19:12

daveredfern


2 Answers

Try casting that Control to TextBox. FindControl returns a Control which doesn't have the Text property

TextBox txtName = LoginView1.FindControl("txtComment") as TextBox;
if (txtName != null)
{
    return txtName.Value;
}
like image 73
hunter Avatar answered Sep 24 '22 14:09

hunter


It has been a while since I used the controls, but i believe it is:

string text = ((TextBox)LoginView1.FindControl("txtComment")).Text;
like image 33
Jeremy B. Avatar answered Sep 21 '22 14:09

Jeremy B.