Nexusfactor
12-05-2010, 06:51 PM
<!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" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">
private void btnSend_Click(System.Object sender, System.EventArgs e)
{
//Creates the message
StringBuilder sb = new StringBuilder();
MailMessage msg1 = new MailMessage();
//build our message
sb.Append("From:");
sb.Append(txtFname.Text);
sb.Append(" ");
sb.Append(txtLname.Text);
sb.Append("<br />Email:");
sb.Append(txtEmail.Text);
sb.Append("<br />Phone:");
sb.Append(txtPhone.Text);
//Sets the from, to, subject, etc...
msg1.From = txtEmail.Text;
msg1.To = tbTo.Value;
msg1.Subject = tbSubject.Value;
msg1.Body = sb.ToString();
msg1.BodyFormat = MailFormat.Html;
msg1.Priority = MailPriority.Normal;
SmtpMail.SmtpServer = "smtp.agitraining.net";
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.agitraining.net");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","info");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","deadlock");
//Change the view to remove the form
MultiView1.ActiveViewIndex = -1;
try
{
SmtpMail.Send(msg1);
lblStatus.Text = "Message sent";
}
catch
{
lblStatus.Text = "Message sent";
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>
<style type="text/css">
body, tr, td {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<!-- Set your recipient info here -->
<asp:HiddenField runat="server" id="tbTo" Value="fredg@aquent.com"></asp:HiddenField>
<!-- Set your default subject here -->
<asp:HiddenField runat="server" id="tbSubject" Value="New Contact"></asp:HiddenField>
<!-- Form controls start here --->
<br />
<asp:Label runat="server" Text="Fill out your information below:" id="lblStatus"></asp:Label>
<br />
<br />
<br />
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<table align="center" style="width: 250px">
<tr>
<td>First Name:</td>
<td>
<asp:textbox id="txtFname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:textbox id="txtLname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<asp:textbox id="txtEmail" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>
<asp:textbox id="txtPhone" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:button id="Button1" runat="server" onClick="btnSend_Click" Text="Send Form" />
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
This is from the Microsoft tutorial, I did it, but i was wondering, lets say I wanted to check the form, to make sure the user hasn't missed something. Lets say if the user forgets there e-mail address and hits the submit button, it should prompt them saying "Email Required" and the cursor should be place in the e-mail textbox, how could I go about do it?
<%@ Page Language="c#" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">
private void btnSend_Click(System.Object sender, System.EventArgs e)
{
//Creates the message
StringBuilder sb = new StringBuilder();
MailMessage msg1 = new MailMessage();
//build our message
sb.Append("From:");
sb.Append(txtFname.Text);
sb.Append(" ");
sb.Append(txtLname.Text);
sb.Append("<br />Email:");
sb.Append(txtEmail.Text);
sb.Append("<br />Phone:");
sb.Append(txtPhone.Text);
//Sets the from, to, subject, etc...
msg1.From = txtEmail.Text;
msg1.To = tbTo.Value;
msg1.Subject = tbSubject.Value;
msg1.Body = sb.ToString();
msg1.BodyFormat = MailFormat.Html;
msg1.Priority = MailPriority.Normal;
SmtpMail.SmtpServer = "smtp.agitraining.net";
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.agitraining.net");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","info");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","deadlock");
//Change the view to remove the form
MultiView1.ActiveViewIndex = -1;
try
{
SmtpMail.Send(msg1);
lblStatus.Text = "Message sent";
}
catch
{
lblStatus.Text = "Message sent";
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>
<style type="text/css">
body, tr, td {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<!-- Set your recipient info here -->
<asp:HiddenField runat="server" id="tbTo" Value="fredg@aquent.com"></asp:HiddenField>
<!-- Set your default subject here -->
<asp:HiddenField runat="server" id="tbSubject" Value="New Contact"></asp:HiddenField>
<!-- Form controls start here --->
<br />
<asp:Label runat="server" Text="Fill out your information below:" id="lblStatus"></asp:Label>
<br />
<br />
<br />
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<table align="center" style="width: 250px">
<tr>
<td>First Name:</td>
<td>
<asp:textbox id="txtFname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:textbox id="txtLname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<asp:textbox id="txtEmail" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>
<asp:textbox id="txtPhone" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:button id="Button1" runat="server" onClick="btnSend_Click" Text="Send Form" />
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
This is from the Microsoft tutorial, I did it, but i was wondering, lets say I wanted to check the form, to make sure the user hasn't missed something. Lets say if the user forgets there e-mail address and hits the submit button, it should prompt them saying "Email Required" and the cursor should be place in the e-mail textbox, how could I go about do it?