Link to home
Start Free TrialLog in
Avatar of Harshutrivedi
Harshutrivedi

asked on

moving client side validation to server side

Hi,

We have one big page having validations like mandetory field, date-time validation, range validation and so on...in the java script.  Now we want to move those validation to vb.net code.
It is like moving client side validation to server side validation. What would be the best approach to achieve this, if not best, what would be better approach for this? we are using asp.net 2.0 and vb.net as language.

Thank you
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a CustomValidator control. Set one of the controls as the ControlToValidate, set the ValidateEmpty to true. Then in the client side validation function, perform all the validation.

http://www.4guysfromrolla.com/articles/073102-1.aspx
asp.net has various validation control which can be used to replace your client-side validation code completely.
e.g. mandatory fields validation can be replaced using RequiredFieldValidator Control
range validation code can be replaced using RangeValidator control
Date validation can be replaced using CompareValidator

Check this: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx
Avatar of Harshutrivedi
Harshutrivedi

ASKER

I want to move client side validation to server side validation. There is already client side validation and running ok.
why do u want to change client script to server side script.  
>There is already client side validation and running ok.
Client side validation, as you said is being done using JavaScript. On the server side, you can not run JavaScript. VB.NET or C# are two usual options.
@rajeeshmca  : Well that decision is not in my hand. WE have to do it in serverside. Some time client disable javascript and all... but decision is not in my hand.

@CodeCruiser: Yes, so I am using vb.net. I want to know, whether there is any specific mechanisam or I have to write the function line by line for each javascript function? Meaning that, if I want client side valudation , i do not need to write javascript from begining, I can use RequiredValidation control. Like that, in vb.net, is it having any functionality or I have to write line by line for javascript functions?
Depends on the number and type of controls and the type of validation you are doing.

Refer to the examples in the link i posted.
Harshutrivedi:
Asp.net Controls work on client-side as well as server. So say if user browser has JS disabled RequiredFieldValidator will still work...but now using server-side validation. Ideally you don't have to write a single line of code. Just drag and drop RFV and hook it up to the control you want to validate.

Here is another link: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/validation/default.aspx
you will have to definitely write it line by line... no other go
Well, I have to use vb.net and not anything else. I think I will be looking at line by line, like for required field validation, i would be wrting, txt.text.length and all.

Can I check or set page.isvalid if all my validation is in vb.net?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I dont think u need to use these lines

txt.text.length

u can use the Vlidation controls which does most of the validations assigning the controlToValidate properrty to the respective controls