Solved

asp.net form not validating

Posted on 2004-03-22
6
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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