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

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.

Who is Participating?
maby you should accept the answer then :)
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
naveenkhoslaAuthor Commented:
Thanks a lot

The solution worked for me.
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.

All Courses

From novice to tech pro — start learning today.