Solved

ASP.net page not validating! C#

Posted on 2004-03-22
20
340 Views
Last Modified: 2012-08-14
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
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
  • 9
  • 8
20 Comments
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10654212
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
 

Author Comment

by:Tsrom
ID: 10655152
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
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10658276
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 6

Expert Comment

by:gtvingo14
ID: 10658388
also, your phone validation says (xxx)xxx-xxxx but accepted format is xxx-xxx-xxxx otherwise it should work now
0
 

Author Comment

by:Tsrom
ID: 10659784
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
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10659869
have you tried updating the code to the one above? when I view the source its still the old code...
0
 

Author Comment

by:Tsrom
ID: 10659944
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
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10660057
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
 

Author Comment

by:Tsrom
ID: 10660205
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
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10660788
you need to make sure that your server supports scripting
0
 

Author Comment

by:Tsrom
ID: 10660903
OK I'll check it right now. Thanx I'll let you know.
0
 

Author Comment

by:Tsrom
ID: 10661095
Yes they do support .net version 1.1
0
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10662033
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
 

Author Comment

by:Tsrom
ID: 10662284
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
 
LVL 6

Accepted Solution

by:
gtvingo14 earned 500 total points
ID: 10662304
anytime...
0
 

Author Comment

by:Tsrom
ID: 10697114
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
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10704231
I can upload the form to my site and see if it works...
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.NET Enums [Flags] & Bitwise Design Question 6 53
T-SQL and CLR parameter strings 9 66
PowerShell: Adding ToGB to a script 4 74
Data Analysis 7 59
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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