Solved

asp.net form not validating

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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