I'm new to ASP. I have a simple contact form - text fields only - and the results are emailed. But I can't get the page to display. I get a Runtime Error.

<%@ Page Language="C#" MasterPageFile="~/SiteMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="contact_me_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<div id="iCntnr">
    <div id="contact_meCntnr">
        <asp:PlaceHolder ID="formPH" runat="server" Visible="true"> 
			<h3>I want to use stimulus money to clean my community's waterways.</h3>
			<p>Please contact me with more information.</p>
	
    	<form id="form1" runat="server"> 
		<table id="contact" cellspacing="0"> 
			<tr> 
				<td>First Name:</td> 
				<td><asp:TextBox ID="FNameTB" runat="server" /> 
					<asp:RequiredFieldValidator ControlToValidate="FNameTB" ID="reqFirstName" runat="server" CssClass="error" Text="First Name is a required field">First Name is a required field</asp:RequiredFieldValidator> 
				</td> 
			</tr> 
			<tr> 
				<td>Last Name:</td> 
				<td><asp:TextBox ID="LNameTB" runat="server" /> 
					<asp:RequiredFieldValidator ControlToValidate="LNameTB" ID="reqLastName" runat="server" CssClass="error" Text="Last Name is a required field">Last Name is a required field</asp:RequiredFieldValidator> 
				</td> 
			</tr> 
			<tr> 
				<td>Email:</td> 
				<td><asp:TextBox ID="EmailTB" runat="server" /> 
					<asp:RequiredFieldValidator Display="Dynamic" ControlToValidate="EmailTB" ID="reqEmail"  runat="server" CssClass="error" Text="E-mail is a required field">E-mail is required</asp:RequiredFieldValidator><asp:RegularExpressionValidator ControlToValidate="EmailTB" ID="regEmail" Display="Dynamic" runat="server" CssClass="error" Text="Invalid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> 
				</td> 
			</tr> 
			<tr> 
				<td>Comments:</td> 
				<td><asp:TextBox ID="CommentsTB" runat="server" TextMode="MultiLine" /> 
				</td>
			</tr>
            <tr>
            	<td colspan="2"><asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="SendMail"/><asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="Reset"/></td> 
            </tr>
		</table>             
		</form> 
		</asp:PlaceHolder> 
		
        <asp:PlaceHolder ID="sucessPH" runat="server" Visible="false"> 
		<p>Thank you for your submission.</p> 	
	</asp:PlaceHolder> 
    </div>
</div>
</asp:Content>

and here is the code file:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class contact_me_Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        ((SiteMaster)this.Master).SetHeaderTitle("Contact Me");
        
    }
    protected void SendMail(object sender, EventArgs e)
    {
		if(!IsValid)
		{
			return;
		}
		else
		{
                MailMessage mail = new MailMessage();
				mail.From = new MailAddress(EmailTB.Text);
				mail.To.Add(new MailAddress(ConfigurationManager.AppSettings["emailCorporate"]));
		        mail.Subject = "Contact Me about using Stimulus Money"; 
		        mail.IsBodyHtml = true;
		        mail.Body = "First Name: " + FNameTB.Text + "<br />";
		        mail.Body += "Last Name: " + LNameTB.Text + "<br />";
		        mail.Body += "Email: " + EmailTB.Text + "<br />";
		        mail.Body += "Comments: " + CommentsTB.Text + "<br />";
		
        		SmtpClient client = new SmtpClient();
				client.Host = ConfigurationManager.AppSettings["emailHost"];
        		client.UseDefaultCredentials = true;
        		client.Send(msg);
				
				formPH.Visible = false;
				sucessPH.Visible = true;
		}
    }
	protected void Reset(object s, EventArgs e)
	{
		FNameTB.Text = "";
		LNameTB.Text = "";
		EmailTB.Text = "";
		CommentsTB.Text = ""; 
	}    
}

>I get a Runtime Error.
Show us that error description.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.