|
Say I have multiple check boxes and a Submit button and a send button in the .aspx page. once the user clicks on the Submit button, I like to do the client side validation to see whether some checkbox is selected, if not, a message box should be popped up to warn the user. If the validation passes, the OnBtnSummit_click event handler in the .aspx.cs file behind will do some processing based on the selected checkbox. The checkbox selection checking should only occur when Submit button is clicked. If the Send button is clicked, the validation checking shouldn't be performed.
Here, I don't want to do server-side validation and I don't want to write OnBtnSummit_click event handler in the
.aspx file.
It seems ASP.NET validation server control doesn't help in my case. Could anybody give me some suggestions?
|
|
|
This can get pretty involved.
There are many ways to go about things, I'll let you know what I do.
Use JavaScript to do client validation. You can use JavaScript's "alert" and "confirm" methods to pop up messages. The validation script will
1) set a hidden form variable value to indicate which button was clicked.
2) submit the form, or not, based on whether or not validation passes.
Then, in your server-side Page Load event, look at the hidden form variable's value, and then call the appropriate function.
In other words, create your "event handler" functions, but don't wire them up to the buttons. You call them based upon what you do in the JavaScript.
Let me know if this gives you something to work with. If not, just ask.
You might want to read through a couple of articles on my site dealing with ASP.NET, server vs. client.
|
|
|
|
|
thank you for your reply.
For the Send button, I set its CausesValidation property to false. This will not enforce the validation that the submit button is doing.
And I included a .NET customvalidator to do the validation, Then if it's sucessful, continue with the submit, else cancel it, my question comes from here, how to continue or cancel based on the validation results? shall I do the coding in the javascript function? I believe this can be done in several lines of code. Am I right? seems just a if/else statement. But no idea how to write the code
|
|
|
Thank you, i solved the problem by using document.form.submit.disabled = true;
|
|
|
You could also use JavaScript.
The JavaScript confirm() method returns a boolean. Simply "return" that boolean.
In your form declaration, you would add "onsubmit='return myfunction()'".
In "myfunction", you do a confirm:
var x = confirm("Do you really want to continue?")
return x;
If "x" is false, the form will not submit.
|
|
|
|
|
|
|
|
|
|