How do I reference the input of an HTML control in codebehind?

I’m using a textarea control to allow the user to input text and then place that text into the body of an e-mail. In the code behind, what is the syntax for referencing the users input? I thought I could just use message.Body = test123.Text; but this is not recognized.


<textarea id="TextArea1" cols="20" rows="2" ></textarea>


foreach (string recipient in recipients)
  var message = new System.Net.Mail.MailMessage("[email protected]", recipient);
  message.Subject = "Hello World!";         
  message.Body = test123.Text;                


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You are not using a .NET control for your text area. Either add runat="server" to the HTML TextArea control or use a .NET control:

Try this:

<asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />

Then reference it in your codebehind:
message.Body = TextArea1.Text;

Method 2

You need to use runat="server" like this:

<textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>

You can use the runat=server attribute with any standard HTML element, and later use it from codebehind.

Method 3

First make sure you have the runat="server" attribute in your textarea tag like this

<textarea id="TextArea1" cols="20" rows="2" runat="server"></textarea>

Then you can access the content via:
string body = TextArea1.value;

Method 4

You should reference the textarea ID and include the runat="server" attribute to the textarea

message.Body = TextArea1.Text;

What is test123?

Method 5

Missed property runat="server" or in code use Request.Params["TextArea1"]

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x