• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

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
0
Harshutrivedi
Asked:
Harshutrivedi
  • 4
  • 3
  • 3
  • +1
1 Solution
 
CodeCruiserCommented:
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
0
 
guru_samiCommented:
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
0
 
HarshutrivediAuthor Commented:
I want to move client side validation to server side validation. There is already client side validation and running ok.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
rajeeshmcaCommented:
why do u want to change client script to server side script.  
0
 
CodeCruiserCommented:
>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.
0
 
HarshutrivediAuthor Commented:
@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?
0
 
CodeCruiserCommented:
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.
0
 
guru_samiCommented:
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
0
 
rajeeshmcaCommented:
you will have to definitely write it line by line... no other go
0
 
HarshutrivediAuthor Commented:
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?
0
 
CodeCruiserCommented:
Yes. In the codebehind event handler of the CustomValidator, you can use the e parameter to set whether or not the page is valid.
0
 
rajeeshmcaCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now