|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

March 18th, 2009, 01:48 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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
|

March 18th, 2009, 02:02 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
|
|
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.
Last edited by Lee Dumond : March 19th, 2009 at 03:55 PM.
|

March 20th, 2009, 03:29 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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?
|

March 20th, 2009, 03:43 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
|
|
Quote:
Originally Posted by ysfkay
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.
Last edited by Lee Dumond : March 20th, 2009 at 05:46 PM.
|

March 20th, 2009, 06:11 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
|
|
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.
Last edited by Lee Dumond : March 20th, 2009 at 08:58 PM.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |