Q:

Retrieve textbox values in code behind file asp.net

Hi I have a crontrol on the page:
<asp:TextBox ID="q" runat="server" autocomplete="off" />

which I'm trying to access the value of from the code behind file.
I've tried:
TextBox searchTerm = FindControl("q") as TextBox;

But it doesn't work.

A:

If it is an ASP.NET TextBox server control which is inside your form, you can  simply use the Text property
string searchKey=q.Text;

You can access any elements inside your CodeBehind if it has an ID property with a value and Runat Property value set to "Server"
Ex : You can write some markup like this in your .ASPX page
<div id="someInfoDiv" runat="server"> Tim's point is valid</div>

and in codebehind
 someInfoDiv.InnerHtml = "So i am adding that";

