Solved

Page not validating!

Posted on 2004-03-22
11
211 Views
Last Modified: 2010-04-15
I built a simple asp.net form. when I added the code to make the page email the form results, the page stopped returning error messages and does not validate. the form will submit blank, or any way the end user chooses. Can some one please help me with this code. This is important.
Here is the code:

<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>
 
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
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 9

Expert Comment

by:glsac
ID: 10654916
youch why do you have all that html in code behind? Anyhow though where is your validation...unless I am blind (which is possible...long day today) I don't see it?
0
 

Author Comment

by:Tsrom
ID: 10655021
I can post all of the html if you would like. Its kind of a long page so I just cut out the C# script. Let me know if thats what you want to see. I'll post the validation:


<!-- 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>
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10655734
If you want server side validation, you should call this.IsValid in the page which will then call all the validation methods of all your Valiadators. The call to IsValid should be before you start preparing the data for sending
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Expert Comment

by:glsac
ID: 10656400
rerun scripts for validation...
go to command line:

C: --> cd windows (or winnt) --> cd microsoft.net --> cd framework --> cd v1.1.4322(your version) --> aspnet_regiis -c

This should fix the validation...happens sometimes...
0
 

Author Comment

by:Tsrom
ID: 10697117
glsac, the form validates perfect locally. when viewing the form on the server, it will not return error messages when filled out incorrect. It does pass the email!
0
 

Author Comment

by:Tsrom
ID: 10705382
Admin, please close this question. I am not getting response! Thanx
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 10965269
Hello,

Please make sure that you have aspnet_client directory in the root of your web application. It is required with every validation. I will give you some more information in an hour, sorry in hurry and got to go.

-Nauman
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 10965559
I have tested the code that you have pasted after some modification. It seems to be working. Can you tell in more detail about the problem.

Thanks, Nauman
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 500 total points
ID: 10965576
ok. This time I tested the script by adding Page.Validate in the  event. First I tested by adding it and then I tested by removing the statement and the validation failed this time. Replace your Send_Email code with this:

protected void Send_Email(Object Sender, EventArgs e) {
Page.Validate();
if (Page.IsValid)
{
  //Code to send e-mail
}

I hope this will help.

-Nauman
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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