Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Problem with RequiredFieldValidator
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem with RequiredFieldValidator

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Problem with RequiredFieldValidator
    Posted: 05 March 2005 at 3:33pm
I decided to use the RequiredFieldValidator control for input validation instead of JavaScript.
 
Code:
<ASP:TextBox id="txtEmail" runat="server">           
<asp:RequiredFieldValidator 
ControlToValidate="txtEmail"                           
Text="Enter Your Email Address!"              
Runat="Server" />
 
I have found out that the above input validation doesn't work in older version of Netscape. As you know, some older browsers will not work with JavaScript. How do I get the input validation above in ASP.Net to work with all browsers including very old versions?


Edited by Misty - 05 March 2005 at 3:36pm
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 05 March 2005 at 4:44pm
Well in Page_Load you could just use
 
If txtEmail.Trim() = String.Empty Then
Response.Write("<script>alert('Please enter an email address');</script.")
Exit Sub
End If
 
but if it's an email address don't you want to use a regular expressions validator to check its a valid email AND is not null?
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 05 March 2005 at 5:14pm
Mart, It didn't work. I got the following error message: Compiler Error Message: BC30456: 'txtEmail' is not a member of 'System.Web.UI.HtmlControls.HtmlForm'.
I used a regular expressions validator for the email field too.
 
Here's my code for this:
 
<asp:RegularExpressionValidator
ControlToValidate="txtEmail"
Text="Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}"
Runat="Server" />


Edited by Misty - 06 March 2005 at 12:59am
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 12:56am
Mart,
 
I finally solved my problem. I am just curious. Which do you prefer to use for input validation in ASP.Net: JavaScript or RequiredFieldValidator? I really like the way Required Expressions Validator works with email addresses. I wish that there was a way to force an user to re-enter the email address if it didn't exist. I have had several people who entered wrong email addresses in one of my forms before. It was really frustrating because I had to call them to find out the correct email address.
 
Here's the code that I put under Page Load:
 
If Page.IsPostBack = True Then
 
  'Check that all of the validation controls 
 'on this page indicate valid input
If Page.IsValid Then
'Add the data as a new record in the database 
Call AddValuesToDatabase()
      
Call AddValuesToEmail()
'Display the results "page" 
Call DisplayResults()
End If
End If
 


Edited by Misty - 06 March 2005 at 12:58am
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 3:45am
I don't prefer any of them, they all have their uses.
 
But to stop people entering the wrong email address why don't you send them an automated email to the address they entered with a verification code or something.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.