Solved

asp.net form not validating

Posted on 2004-03-22
6
451 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

805 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