Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using both server side validation and client side validation

Reply
Thread Tools

Using both server side validation and client side validation

 
 
=?Utf-8?B?dmlkeWE=?=
Guest
Posts: n/a
 
      06-02-2005
Hi,

I have a button which is a web control. I have some validation in javascript
for the button in .aspx file and some in the button onclick event in code
behind(C#). I need to get through both the java script validation as well as
the click in code behind? How can this be done ? Can I call the code behind
from the javascript function?
If not can i have a separate procedure in C# file and call it from the
javascript function? If so what is the syntax for it?
Please let me know even if it's silly as I am pretty new to .net

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      06-02-2005
Hi vidya,

In HTML, there is a "last chance" event that fires when a form is submitted,
called "onsubmit". If you create a JavaScript "onsubmit" event handler for
the form, a function that returns true or false, you can have a client-side
validation script that fires before the server-side validation. Here's an
example:

<form name="MyForm" action="ThisUrl" onsubmit="return myValidation(this)">

Any time you wire up a server-side event handler for a Web Control, what
happens is this: A client-side JavaScript event handler for the client-side
HTML form element of that Web Control is added to its HTML. That client-side
event handler puts data about what element fired the event and any
additional event-related data, into a couple of hidden HTML form fields that
are also added to the HTML form. The client-side event handler then submits
the form via JavaScript. This fires the "onsubmit" event of the client-side
HTML form. When you add a JavaScript "onsubmit" event handler to the form,
you are intercepting that form post event, and if your JavaScript function
returns true, the form is submitted. If it returns false, the form submit is
aborted.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"vidya" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have a button which is a web control. I have some validation in
> javascript
> for the button in .aspx file and some in the button onclick event in code
> behind(C#). I need to get through both the java script validation as well
> as
> the click in code behind? How can this be done ? Can I call the code
> behind
> from the javascript function?
> If not can i have a separate procedure in C# file and call it from the
> javascript function? If so what is the syntax for it?
> Please let me know even if it's silly as I am pretty new to .net
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute client-side code _after_ client-side validation? Bogdan ASP .Net 2 06-09-2008 01:31 PM
Client side script after client side validation with asp.net 2.0 Boss302 ASP .Net 0 11-21-2006 08:43 AM
client side validation and form submission on iis 6 (both 1.0 & 1.1 installed) Giri ASP .Net 1 12-24-2004 04:15 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Triggering both client and server side scripts Karim ASP .Net 3 11-26-2003 04:20 PM



Advertisments