Solved

Page not validating!

Posted on 2004-03-22
11
205 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

23 Experts available now in Live!

Get 1:1 Help Now