ASP.Net - Both server and client validations on a single buton click

Posted on 2004-10-22
Medium Priority
Last Modified: 2010-04-17
Hi All,

In ASP.NET, I have a Submit Button. On the click of the button, I need to add a Javascript confirmation if a particular condition matches. The application should first do the required field validations, then check for the condition and then promt a confirmation to submit the form.
The submit should happen depending on the confirmation of the user.
Kindly help me out.
I tried this by includitn the following line in Page_Load()

this.btnSave.Attributes["onclick"] = "return fnConfirm(this);";

By doing this, the javascript confirmation works, but no other validations are fired.

Question by:naveenkhosla
LVL 21

Expert Comment

ID: 12378995
Put the validation on the form.onSubmit event:
this.MyForm["onSubmit"]="return fnConfirm(this);";

OR you can regester for the event in the HTML:

<form name='MyForm'  action=...  onSubmit="return fnConfirm(this)">

The fnConfirm function will take the form as a parameter and check each field for validity.  If a field is invalid, display a message and return FALSE.

If All are valid, then return true

Author Comment

ID: 12379185
Thanks a lot

The solution worked for me.

Accepted Solution

sirono earned 1000 total points
ID: 12380383
maby you should accept the answer then :)

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Simple Linear Regression
Introduction to Processes

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question