Create two aspx pages
1) First Page will create a Verification Image
** CatchImage.aspx.cs
using System;
using System.Data;
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.Drawing;
using System.Drawing.Imaging;
public partial class CaptchaImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Random Rand = new Random();
int iNum = Rand.Next(10000, 99999);
Bitmap Bmp = new Bitmap(90, 50);
Graphics Gfx = Graphics.FromImage(Bmp);
Font Fnt = new Font("Verdana", 12, FontStyle.Bold);
Gfx.DrawString(iNum.ToString(), Fnt, Brushes.Yellow, 15, 15);
// Create random numbers for the first line
int RandY1 = Rand.Next(0, 50);
int RandY2 = Rand.Next(0, 50);
// Draw the first line
Gfx.DrawLine(Pens.Yellow, 0, RandY1, 90, RandY2);
// Create random numbers for the second line
RandY1 = Rand.Next(0, 50);
RandY2 = Rand.Next(0, 50);
// Draw the second line
Gfx.DrawLine(Pens.Yellow, 0, RandY1, 90, RandY2);
Bmp.Save(Response.OutputStream, ImageFormat.Gif);
Session["Number"] = iNum;
}
}
2) Second Page is contact us page
but the body of message shoul not be more than 20 characters so we add
customValidator control
** ContactUs.aspx.cs
using System;
using System.Data;
using System.Configuration;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.Web.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Session["Number"].ToString().Trim() == txtNumber.Text)
{
try
{
MailMessage message = new MailMessage();
message.To = "yasser021@gmail.com";
message.From = txtEmail.Text;
message.Subject = txtSubject.Text;
message.Body = txtBody.Text;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(message);
Response.Write("Email has been sent to our Sales Team");
}
catch (Exception ex)
{
}
}
else
{
Response.Write("Verification Email not match. Please re-enter");
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
//args.IsValid = (args.Value.Length <= 20); if (txtBody.Text.Length > 20)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
}
Wednesday, January 9, 2008
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment