?
Solved

asp.net form not validating

Posted on 2004-03-22
6
Medium Priority
?
459 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 1200 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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 informatio…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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