Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

ASP.net page not validating! C#

I have a simple web form. I want the form to email the results when the end user hits the submit button. I have accomplished this task, but when the form is submitted the form is no longer returning the error messages. I can now fill out the form however I want and it still emails the results. I can even submit it blank. Why is the form not validating? Thanx -  cfcoder


 <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title>Larry Woodruff - 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>

<script language="JavaScript" type="text/JavaScript">
<!-- Hide script from old browsers
function newWindow() {
calcWindow = window.open('http://www.lendscape.com/calc.html','calcWin','toolbar=no,location=no,scrollbars=yes,width=650,height=600')
}

// End hiding script from old browsers -->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="css_test.css">
 </head>

<body marginwidth="0" topmargin="0" leftmargin="0" rightmargin="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
 <td align="center">
 
 <!-- Start main table header -->
            <table width="782" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                      <td><img src="images/hdr_left.jpg" width="80" height="140" alt="" border="0"><img src="images/hdr_logo.jpg" width="181" Height="140" alt="" border="0"><img src="images/hdr_name.jpg" width="260" height="140" alt="" border="0"><img src="images/hdr_right.jpg" width="261" height="140" alt="" border="0"></td>
                    </tr>
            </table>
            
<!-- Top navigation -->            
            <table width="782" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/lft_square.jpg" height="40" width="41" alt="" border="0"></td>
    <td background="images/nav_bar.gif" height="40" width="169">&nbsp;</td>
    <td align="center" background="images/nav_bar_top.jpg" height="40" width="56"><a href="index.aspx"><span class="bold">HOME</span></a></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="2"><span class="boldtxt">|</span></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="110"><span class="bold">APPLY ONLINE</span></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="2"><span class="boldtxt">|</span></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="108"><a href="javascript:newWindow()"><span class="bold">CALCULATORS</span></a></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="2"><span class="boldtxt">|</span></td>
      <td align="center" background="images/nav_bar_top.jpg" height="40" width="84"><a href="about.aspx"><span class="bold">ABOUT ME</span></a></td>
    <td background="images/nav_bar.gif" height="40" width="169">&nbsp;</td>
    <td><img src="images/rt_square.jpg" width="41" height="40" alt="" border="0"></td>
  </tr>
</table>

<!-- Address, Phone Numbers, Email, Fast App -->
<table width="782" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/top_lftsidebar.gif" width="41" height="189" alt="" border="0"></td>
    <td><img src="images/larryw.jpg" width="166" height="189" alt="Larry Woodruf" border="0"></td>
    <td width="309" height="189">
      
<!-- Nested table for addess and phone nimbers -->
      <table width="308" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/white_spacer.gif" width="5" height="5"></td>
  </tr>
  <tr>
    <td align="center"><img src="images/firstpri_addy.gif" width="233" height="116" alt="First Priority Financial" border="0"></td>
  </tr>
  <tr>
    <td><img src="images/white_spacer.gif" width="5" height="5"></td>
  </tr>
  <tr>
    <td align="center"><span Class="boldtxt">Email: </span><a href="mailto:lwoodruff@lendscape.com"><span class="email">lwoodruff@lendscape.com</span></a></td>
  </tr>
  <tr>
    <td><img src="images/white_spacer.gif" width="5" height="5"></td>
  </tr>
  <tr>
    <td align="center">&nbsp;&nbsp;<a href="fastapp.aspx">Click here to fill out an online application!</a></td>
      </tr>
</table>
<!-- End nested table -->

</td>
    <td><img src="images/house.gif" width="226" height="189" alt="1-707-688-4212" border="0"></td>
    <td><img src="images/top_rtsidebar.gif" width="41" height="189"></td>
  </tr>
</table>

<!-- Centerline table -->
<table width="782" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/lft_centerline.jpg" width="41" height="11" alt="" border="0"></td>
      <td><img src="images/centerline.jpg" alt="" border="0" width="700" height="11"></td>
      <td><img src="images/rt_centerline.jpg" width="41" height="11" border="0"></td>
  </tr>
</table>
<!-- End centerline table -->
<table width="782" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" width="41" background="images/lftlowform_cols.gif" height="100%">&nbsp;</td>
    <td width="700"><!--Startfiller content -->
<table  width="700" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <!-- Start Web Form -->      
      <asp:label id="Message" runat="server" />

<% if(!Page.IsPostBack) { %>
<table align="center" width="500" cellspacing="2" cellpadding="1" border="0">      
      <form runat="server" name="form1" method="post" action="">
            <tr>
                  <td colspan="3"><span class="bold">Application Request&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Required Fields</span> <font color="red">*</font></td>
            </tr>
            <tr>
                  <td width="91" align="left"><span class="bold">Applicant Name:</span></td>
                  <td width="154"><asp:textbox ID="txtApplicantName" MaxLength="25" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtApplicantName" Display="Dynamic" ErrorMessage="Applicant name is required!" ID="rfvApplicantName" runat="server" Text="*" /></td>
                  <td width="236" rowspan="10" valign="top"><asp:validationsummary DisplayMode="BulletList" HeaderText="The following errors occured!" ID="vsSummary" runat="server" />&nbsp;</td>
            </tr>
            <tr>
              <td align="left"><span class="bold">Address:</span></td>
              <td><asp:textbox ID="txtAddress" MaxLength="25" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtAddress" Display="Dynamic" ErrorMessage="Address is required!" ID="rfvAddress" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">City:</span></td>
              <td><asp:textbox ID="txtCity" MaxLength="15" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtCity" Display="Dynamic" ErrorMessage="City is required!" ID="rfvCity" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">State:</span></td>
              <td><asp:textbox ID="txtState" MaxLength="15" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtState" Display="Dynamic" ErrorMessage="State is required!" ID="rfvState" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Zip Code:</span></td>
              <td><asp:textbox ID="txtZipCode" MaxLength="5" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Zip Code is required!" ID="rfvZipCode" runat="server" Text="*" /><asp:regularexpressionvalidator ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Must contain a valid zip code!" ID="revZipCode" runat="server" Text="*" ValidationExpression="\d{5}(-\d{4})?" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Email:</span></td>
              <td><asp:textbox ID="txtEmail" MaxLength="30" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Email is required!" ID="rfvEmail" runat="server" Text="*" /><asp:regularexpressionvalidator ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Email must contain a valid email address!" ID="revEmail" runat="server" Text="*" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Phone #:</span></td>
              <td><asp:textbox ID="txtPhone" MaxLength="12" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtPhone" Display="Dynamic" ErrorMessage="Must contain a valid phone #! (***)***-**** " ID="revPhone" runat="server" Text="*" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Fax #:</span></td>
              <td><asp:textbox ID="txtFax" MaxLength="15" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtFax" Display="Dynamic" ErrorMessage="Must contain a valid fax #!" ID="revFax" runat="server" Text="*" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Income:</span></td>
              <td><asp:textbox ID="txtIncome" MaxLength="15" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtIncome" Display="Dynamic" ErrorMessage="Must contain valid dollar format! $!!!!.!!" ID="revIncome" runat="server" Text="*" ValidationExpression="^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$" /></td>
              </tr>

            <tr>
              <td align="left"><input type="submit" OnServerClick="Send_Email" runat="server" class="submit" value="Submit Form" />


</td>
              <td align="center"><input name="Reset" type="reset" value="Reset Form"></td>
            </tr>
                              
      </form>
      
</table>
<% } %>




<!-- End Web Form -->
</td>
  </tr>
</table>

<table width="700" border="0" cellspacing="0" cellpadding="0">
  <td width="168" align="center">&nbsp;</td>
    <td width="56" align="center"><a href="index.aspx"><span class="bold">HOME</span></a></td>
    <td width="2" align="center"><span class="boldtxt">|</span></td>
    <td width="110" align="center"><span class="bold">APPLY ONLINE</span></td>
    <td width="2" align="center"><span class="boldtxt">|</span></td>
    <td width="108" align="center"><a href="javascript:newWindow()"><span class="bold">CALCULATORS</span></a></td>
    <td width="2" align="center"><span class="boldtxt">|</span></td>
    <td width="84" align="center"><a href="about.aspx"><span class="bold">ABOUT ME</span></a></td>
    <td width="168" align="center">&nbsp;</td>
</table></td>
    <td align="right" width="41" background="images/rghtlowform_cols.gif" height="100%">&nbsp;</td>
  </tr>
<tr>
    <td><img src="images/lftlow_square.jpg" width="41" height="40" alt="" border="0"></td>
    <td><img src="images/low_bar.jpg" width="700" height="40" alt="" border="0"></td>
    <td><img src="images/rtlow_square.jpg" width="41" height="40" alt="" border="0"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

</body>
</html>
0
Tsrom
Asked:
Tsrom
  • 9
  • 8
1 Solution
 
gtvingo14Commented:
Tsrom, are you trying to access the form by clicking the back button? if you are try doing hard refresh Ctrl+f5, and post what happens. I can try debugging it tomorrow for you, unless someone else finds the problem. also do you have your form set to autopostback?
0
 
TsromAuthor Commented:
I would really appreciate your help with this issue gtvingo14. What is happening is I have completely lost the form validation. When I go to the page and submit the form blank, I no longer get an error message. I can basically fill out the form fields any way I want and it returns no error. when I remove the script for the system.web.mail the form validates perfectly. Thanx - Tsrom
0
 
gtvingo14Commented:
ok try this...

if(!Page.IsPostBack) { %>
<form runat="server" name="form1" method="post" action="" ID="Form1">
<table align="center" width="500" cellspacing="2" cellpadding="1" border="0">
<tbody>

validation....

</tbody>
</table>
</form>
<% } %>
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
gtvingo14Commented:
also, your phone validation says (xxx)xxx-xxxx but accepted format is xxx-xxx-xxxx otherwise it should work now
0
 
TsromAuthor Commented:
Here is the new code but the code still doesnot validate the form for some reason. If you want to see what I mean, you can find the page at: http://www.larrywloans.com/fastapp.aspx. When the form is submitted blank it just sends successfully! - Thanx so much!

<% if(!Page.IsPostBack) { %>
<form runat="server" name="form1" method="post" action="" ID="Form1">
<table align="center" width="500" cellspacing="2" cellpadding="1" border="0">
<tbody>
      
            <tr>
                  <td colspan="3"><span class="bold">Application Request&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Required Fields</span> <font color="red">*</font></td>
            </tr>
            <tr>
                  <td width="91" align="left"><span class="bold">Applicant Name:</span></td>
                  <td width="154"><asp:textbox ID="txtApplicantName" MaxLength="25" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtApplicantName" Display="Dynamic" ErrorMessage="Applicant name is required!" ID="rfvApplicantName" runat="server" Text="*" /></td>
                  <td width="236" rowspan="10" valign="top"><asp:validationsummary DisplayMode="BulletList" HeaderText="The following errors occured!" ID="vsSummary" runat="server" />&nbsp;</td>
            </tr>
            <tr>
              <td align="left"><span class="bold">Address:</span></td>
              <td><asp:textbox ID="txtAddress" MaxLength="25" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtAddress" Display="Dynamic" ErrorMessage="Address is required!" ID="rfvAddress" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">City:</span></td>
              <td><asp:textbox ID="txtCity" MaxLength="15" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtCity" Display="Dynamic" ErrorMessage="City is required!" ID="rfvCity" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">State:</span></td>
              <td><asp:textbox ID="txtState" MaxLength="15" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtState" Display="Dynamic" ErrorMessage="State is required!" ID="rfvState" runat="server" Text="*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Zip Code:</span></td>
              <td><asp:textbox ID="txtZipCode" MaxLength="5" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Zip Code is required!" ID="rfvZipCode" runat="server" Text="*" /><asp:regularexpressionvalidator ControlToValidate="txtZipCode" Display="Dynamic" ErrorMessage="Must contain a valid zip code!" ID="revZipCode" runat="server" Text="*" ValidationExpression="\d{5}(-\d{4})?" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Email:</span></td>
              <td><asp:textbox ID="txtEmail" MaxLength="30" runat="server" /><asp:requiredfieldvalidator ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Email is required!" ID="rfvEmail" runat="server" Text="*" /><asp:regularexpressionvalidator ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Email must contain a valid email address!" ID="revEmail" runat="server" Text="*" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Phone #:</span></td>
              <td><asp:textbox ID="txtPhone" MaxLength="12" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtPhone" Display="Dynamic" ErrorMessage="Must contain a valid phone #! *** ***-**** " ID="revPhone" runat="server" Text="*" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Fax #:</span></td>
              <td><asp:textbox ID="txtFax" MaxLength="15" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtFax" Display="Dynamic" ErrorMessage="Must contain a valid fax #!" ID="revFax" runat="server" Text="*" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" /></td>
              </tr>
            <tr>
              <td align="left"><span class="bold">Income:</span></td>
              <td><asp:textbox ID="txtIncome" MaxLength="15" runat="server" /><asp:regularexpressionvalidator ControlToValidate="txtIncome" Display="Dynamic" ErrorMessage="Must contain valid dollar format! $!!!!.!!" ID="revIncome" runat="server" Text="*" ValidationExpression="^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$" /></td>
              </tr>

            <tr>
              <td align="left"><input type="submit" OnServerClick="Send_Email" runat="server" class="submit" value="Submit Form" />


</td>
              <td align="center"><input name="Reset" type="reset" value="Reset Form"></td>
            </tr>
      
</tbody>
</table>
</form>
<% } %>
0
 
gtvingo14Commented:
have you tried updating the code to the one above? when I view the source its still the old code...
0
 
TsromAuthor Commented:
yeah,  I did the file transfer and I checked it. Maybe it didnt go through. I will do it again and then check it. Thanx for your help. - Tsrom
0
 
gtvingo14Commented:
the form validates for me everytime at runtime, even after I send an email to my stmp I can go back and validation is fine...are you experiencing problems localy as well or is it just when you upload the files?
0
 
TsromAuthor Commented:
Locally the form validates perfect. Its on the server that no errors are returned when the form is filled out incorrectly. It just submits blank. If I put QQQQQQQ in the email field, its not checking for valid email!
0
 
gtvingo14Commented:
you need to make sure that your server supports scripting
0
 
TsromAuthor Commented:
OK I'll check it right now. Thanx I'll let you know.
0
 
TsromAuthor Commented:
Yes they do support .net version 1.1
0
 
gtvingo14Commented:
if you are paying for the hosting of your site, and we know that the site works fine localy it has to be their settings...tell them to look into it, I had similar problems resolved by calling our Hosting company, and telling them its on their end.
0
 
TsromAuthor Commented:
Thankyou for all of your help! It is so much appreciated. I have them looking into it as we speak! As soon as this is resolved I will award you the points. Again gtvingo14 Thanx! - Tsrom
0
 
gtvingo14Commented:
anytime...
0
 
TsromAuthor Commented:
gtvingo14, would it be possible to host that form for a short while so I can see it validate. My hosting company say's its not on their end. I cant get this form to return error messages when the form is filled out incorrectly. It passes the form results in email, but will not return error messages!
0
 
gtvingo14Commented:
I can upload the form to my site and see if it works...
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now