Solved

asp.net form not validating

Posted on 2004-03-22
6
449 Views
Last Modified: 2008-03-03
I have a simple form in asp.net that was validating perfectly until I added the C# script to email the form results. Here is the script I added to email the form results:

 <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title> First Priority Financial!</title>
<%@ Import NameSpace="System.Web.Mail" %>
<script runat="server">
      protected void Page_Load(Object Sender, EventArgs e) {
            if(!Page.IsPostBack)
                  Message.Text = "";
      }


      protected void Send_Email(Object Sender, EventArgs e) {
            MailMessage mail = new MailMessage();

                  mail.To = "todd@escrowmall.com";
                  mail.From = "Loans@larrywloans.com";

                  mail.BodyFormat = MailFormat.Html;

                  mail.Subject = "Online Application";
//mail.Body = Request.Form["body"];


string strBody = "<html><body><b>Name:</b> " + Request.Form["txtApplicantName"] + "<br><br><b>Address:</b> " + Request.Form["txtAddress"] + "<br><br><b>City:</b> " + Request.Form["txtCity"] + "<br><br><b>State:</b> " + Request.Form["txtState"] + "<br><br><b>Zip:</b> " + Request.Form["txtZipCode"] + "<br><br><b>Email:</b> " + Request.Form["txtEmail"] + "<br><br><b>Phone:</b> " + Request.Form["txtPhone"] + "<br><br><b>Fax:</b> " + Request.Form["txtFax"] + "<br><br><b>Income:</b> $" + Request.Form["txtIncome"] + "<br> <font color=\"red\"></font></body></html>";
mail.Body = strBody;




            SmtpMail.Send(mail);
            Response.Flush();

            Message.Text = "<center>Application Sent Successfully...<br><br>" +
                        "<a href=\"todd.aspx\">Go Back</a></center><Br><Br>";
      }
</script>


Am I possibly missing an if statement for IsPageValid, or something of the sort. If so where would it go? Thanx - Cfcoder
0
Comment
Question by:Tsrom
  • 2
6 Comments
 

Author Comment

by:Tsrom
ID: 10652330
I changed the code and the form still submits even when left blank! I am not getting the validation error messages that I should be getting!

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title>First Priority Financial!</title>
<%@ Import NameSpace="System.Web.Mail" %>
<script runat="server">
      protected void Page_Load(Object Sender, EventArgs e) {
            if(!Page.IsPostBack)
                  Message.Text = "";
      }


      protected void Send_Email(Object Sender, EventArgs e) {
            if (Page.IsValid)
{
MailMessage mail = new MailMessage();

mail.To = "todd@escrowmall.com";
mail.From = "Loans@larrywloans.com";

mail.BodyFormat = MailFormat.Html;

mail.Subject = "Online Application";
//mail.Body = Request.Form["body"];


string strBody = "<html><body>Name: " + Request.Form["txtApplicantName"] + "<br><br>Address: " + Request.Form["txtAddress"] + "<br><br>City: " + Request.Form["txtCity"] + "<br><br>State: " + Request.Form["txtState"] + "<br><br>Zip: " + Request.Form["txtZip"] + "<br><br>Email: " + Request.Form["txtEmail"] + "<br><br>Phone: " + Request.Form["txtPhone"] + "<br><br>Fax: " + Request.Form["txtFax"] + "<br><br>Income: $" + Request.Form["txtIncome"] + "<br> <font color=\"red\"></font></body></html>";
mail.Body = strBody;




SmtpMail.Send(mail);
Response.Flush();

Message.Text = "<center>Application Sent Successfully...<br><br>" +
"<a href=\"todd.aspx\">Go Back</a></center><Br><Br>";
}
}

</script>
0
 
LVL 35

Accepted Solution

by:
YZlat earned 300 total points
ID: 10652535
protected void Send_Email(Object Sender, EventArgs e) {
          if (Page.IsValid)
{
MailMessage mail = new MailMessage();

mail.To = "todd@escrowmall.com";
mail.From = "Loans@larrywloans.com";

mail.BodyFormat = MailFormat.Html;

mail.Subject = "Online Application";
//mail.Body = Request.Form["body"];


string strBody = "<html><body>Name: " + Request.Form["txtApplicantName"] + "<br><br>Address: " + Request.Form["txtAddress"] + "<br><br>City: " + Request.Form["txtCity"] + "<br><br>State: " + Request.Form["txtState"] + "<br><br>Zip: " + Request.Form["txtZip"] + "<br><br>Email: " + Request.Form["txtEmail"] + "<br><br>Phone: " + Request.Form["txtPhone"] + "<br><br>Fax: " + Request.Form["txtFax"] + "<br><br>Income: $" + Request.Form["txtIncome"] + "<br> <font color=\"red\"></font></body></html>";
mail.Body = strBody;




SmtpMail.Send(mail);
Response.Flush();

(Label) myLabel = FindControl("Message");

myLabel.Text = "<center>Application Sent Successfully...<br><br>" +
"<a href=\"todd.aspx\">Go Back</a></center><Br><Br>";
}
}

0
 

Author Comment

by:Tsrom
ID: 10652681
I changed the code and I am now getting a compilation error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'myLabel' does not exist in the class or namespace 'ASP.TMPpvf2duzwyu_aspx'

Source Error:

 

Line 34: Response.Flush();
Line 35:
Line 36: (Label) myLabel = FindControl("Message");
Line 37:
Line 38: myLabel.Text = "<center>Application Sent Successfully...<br><br>" +
 
0
 
LVL 9

Expert Comment

by:glsac
ID: 10654927
Yzlat has this code:

(Label) myLabel = FindControl("Message");

You have in your code:
Message.Text = "<center>Application Sent Successfully...<br><br>" +
"<a href=\"todd.aspx\">Go Back</a></center><Br><Br>";

Yzlat is assuming that Message is a label and setting that control to myLabel and displaying that result of Application sent....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now