For training purposes, I would like to have two pages.
Now having said that, this is what I have so far:
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-Mail Address</title>
<style type="text/css">
label,input {
display: block;
float: left;
margin-bottom: 10px;
}
input, select, textarea
{
border: solid 1px #000;
background-color: #fff;
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 1.0em;
}
label {
text-align: right;
width: 125px;
padding-right: 20px;
}
br {
clear: left;
}
</style>
</head>
<body>
<form id="form1" runat="server" method="post" action="confirm.aspx">
<label>Name:</label>
<asp:TextBox runat="server" id="name"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ErrorMessage="Please Enter Your Name" id="RegularExpressionValidator2" ControlToValidate="name" Display="Dynamic">
</asp:RegularExpressionValidator>
<br />
<label>E-Mail:</label>
<asp:TextBox runat="server" id="email"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ErrorMessage="Please Enter Your E-Mail Address" id="RequiredFieldValidator1" ControlToValidate="email" Display="Dynamic">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat="server" ErrorMessage="Please Check Your E-Mail Address" id="RegularExpressionValidator3" ControlToValidate="email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
<br />
<label>Message:</label>
<asp:TextBox runat="server" id="message" TextMode="MultiLine" style="height: 125px"></asp:TextBox>
<br />
<br />
<asp:Button runat="server" Text="Submit" id="Submit" />
</form>
</body>
</html>
in the contact.aspx page. This code was built using Expression Web so I am hoping it is pretty good / correct. While I understand some of this might not be that great of .NET code, I would like to leave most as is unless absolutely necessary.
Now in my confirm.aspx page, I would like for it to say
Thank you <name> for contacting us. We will be in touch soon.
(with name being replaced with the name that was entered into the form.aspx page).
Now, if there was an error, maybe something like:
Sorry, there was an error, please click here to re-enter your information.
What I have so far is:
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Text" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient("mail.example.org");
System.Text.StringBuilder sb = new StringBuilder();
System.Net.Mail. msg = null;
sb.Append("E-Mail from: " + txtname.Text + "\n");
sb.Append("E-Mail Address : " + txtemail.Text + "\n");
sb.Append("Message : " + txtmessage.Text + "\
try
{
msg = new System.Net.Mail.MailMessage(txtEmail.Text
"crb@example.org", "Message from your Web Site",
sb.ToString());
sc.Send(msg);
}
catch(Exception ex)
finally
{
if (msg != null)
{
msg.Dispose();
}
}
}
</script>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
Thank you for your message.
else
//
An error occurred
</body>
</html>
Now I understand that I can use some things like
- Code: Select all
<%@ Import Namespace="System.Net.Mail" %>
to replace it in the code, but for now, I would like to stay away from that until a bit later.
I have done this with ASP and using the JMail ASP component, but I would like to do this in .NET on two pages (contact.aspx and confirm.aspx)
Thank you!