Wrox Programmer Forums
|
Visual Web Developer 2008 Discuss creating ASP.NET 3.5 sites with Microsoft's Visual Web Developer 2008. If your question is more specific to a piece of code than the Visual tool, see the ASP.NET 3.5 forums instead. If your question is specific to the "Express Edition" be sure to state that in your post.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2009, 12:48 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default I need Help Please just read

I am a rookie programmer,
I am trying to create a requiredfield validator using the custom control available in .Net. I know about the inbuilt validators, but the case is that I need to create custom server side validators, therefore I dont want to mix the inbuilt client side validation controls that come with dotnet and the custom server side validators that I need to build. This is why I need to create a custom serverside textbox required field validator. But all efforts failed.THis is what I tried.

protected void e_serverValidate(................................. ... args)
{
if(TextBox1.Text.Trim()=="")
args.IsValid=false;
else
args.isValid=true;
}
Please how am I suppose to write the appriopriate code . Csharp, thank you
 
Old March 18th, 2009, 01:02 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You are aware that the standard validators do validate on the server side as well as the client side, yes? And that you can turn the client-side validation off?

As far as I know, you cannot use the CustomValidator on non-existent input. In other words, if the input is empty, the custom validation method never fires. Therefore, I don't see how you can use custom server-side validation to validate if a field is empty or not.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; March 19th, 2009 at 02:55 PM..
 
Old March 20th, 2009, 02:29 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks that what I needed to hear that if the field is empty then the validation is not triggered, cuz I started to suspect that after trying all that I could think of,but you said that the standard validators also validate on the serverside, so how can I make like the standard required field validator validate on the server side instead of on the client side?
 
Old March 20th, 2009, 02:43 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by ysfkay View Post
but you said that the standard validators also validate on the serverside, so how can I make like the standard required field validator validate on the server side instead of on the client side?
You do not have to do anything special to enable server side validation. All of the standard validators validate on both the server side and client side by default.

You can optionally turn the client side validation off. However, you cannot turn the server side validation off. The server side validation always fires. (The actual method that performs the validation is part of the .NET source code.)

Of course, you should check the value of the IsValid property of the page in any methods you execute on postback.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; March 20th, 2009 at 04:46 PM..
 
Old March 20th, 2009, 05:11 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

By the way, in case you are interested in how server-side validation works behind the scenes:

When the page is validated, it triggers the Validate method on all of the validation controls on the page. The Validate method is part of the IValidator implementation of BaseValidator.

The Validate method in turn calls the EvaluateIsValid method, which is an abstract method which is overridden in any control that inherits BaseValidator. The following code shows the override from the RequiredFieldValidator class:

Code:
protected override bool EvaluateIsValid()
{
    string controlValidationValue = base.GetControlValidationValue(base.ControlToValidate);
    return ((controlValidationValue == null) || !controlValidationValue.Trim().Equals(this.InitialValue.Trim()));
}
As you can see, it returns true if there is a non-null value for the control that is being validated.

Again, this is all performed on the server side and is built-in functionality.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; March 20th, 2009 at 07:58 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need Help Please just read ysfkay BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 1 July 2nd, 2010 01:42 PM
I need Help Please just read ysfkay ASP.NET 3.5 Professionals 1 March 18th, 2009 02:05 PM
Read Only Form Is not Read only lryckman Access VBA 3 June 12th, 2007 06:30 AM
Read First!! I need you o help :-) Stephen Lam MySQL 1 April 15th, 2005 10:12 AM
Read first!!!Please help me!!!Thank you!!! wood000 Wrox Book Feedback 1 June 24th, 2004 09:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.