Solved

Page not validating!

Posted on 2004-03-22
11
202 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
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 9

Expert Comment

by:glsac
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 9

Expert Comment

by:glsac
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Tsrom
Comment Utility
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
Comment Utility
Admin, please close this question. I am not getting response! Thanx
0
 
LVL 25

Expert Comment

by:nauman_ahmed
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now