473,491 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using both server side validation and client side validation

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

Nov 19 '05 #1
1 2492
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" <vi***@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4489
by: earwicker | last post by:
I recently deployed a web application which contains a user registration form with the usual fields: name, address, email, password, etc. Each of the TextBoxes uses a validation control to verify...
4
2346
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
14
6266
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
3
13117
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of...
2
3704
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
3
2045
by: msnews.microsoft.com | last post by:
Hi All, I m facing problem in Server Side Validation. For Example The Scenario is I have two fields on the page 1 Country Dropdown List 2 Province Textbox 3 State Dropdown List
2
4492
by: dustbort | last post by:
I recently had a problem where my required field validator stopped working. But, the page still posted back and tried to insert a record into the database without performing server-side validation....
14
3539
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
1
4755
by: APA | last post by:
Well, I've figured out a way around this mess. I have no idea why it doesn't work the way I think it should but I do know how to get it to work. The scenario is that I have a form that has one...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.