Jump to Main Content

Create a ASP.NET Contact Form

Open the Web site in a browser

In order to see the results of our work, open your preferred web browser and type the following:

http://localhost/dev/contact.aspx

Don’t be concerned if the page doesn’t load immediately. Since the ASP.NET environment compiles each web form into Dynamic Link Libraries (DLL), the first time you load a web form into a browser; it has to compile any code or control before it can render the page. However, as a result, since it’s compiled, if there are no changes, subsequent requests for the page should speed up and no delay should be evident.

View Source

Once your web page has rendered, to reiterate what the ASP.NET environment is doing, view the source of the page in your browser and you should see this:

View Source of Generated Code

As you can see from the example above, the ASP.NET environment has automatically replaced the text box web controls with ordinary HTML input tags for first and last name, as well as email, and has used the ID of the control as the value for the name attribute. Keep note of the view state tag circled in red above, we’ll get to that later in the article. Since a comments field is generally thought to contain more text than an input tag, we use a text area tag instead. Let’s go ahead and create the text area tag by modifying our file as shown below:

<tr>
<td>Comments:</td>
<td><asp:TextBox ID="CommentsTB"  runat="server"  TextMode="MultiLine"  /></td>
</tr>

As you can see from the example above, in order to get a <textarea> tag, we use the text mode property of our text box control and set its value to multiline. Save your file and refresh your page to see the results.

We'll continue by creating our submit and reset buttons next.

top of page