codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Checkbox selection client-side validation in ASP.NET & C#  ipsoftware at 16:38 on Wednesday, January 05, 2005
 

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?

  Re: Checkbox selection client-side validation in ASP.NET & C#  tgreer at 19:47 on Wednesday, January 05, 2005
 

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.



  Re: Checkbox selection client-side validation in ASP.NET & C#  ipsoftware at 02:01 on Thursday, January 06, 2005
 

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


  Re: Checkbox selection client-side validation in ASP.NET & C#  ipsoftware at 02:40 on Thursday, January 06, 2005
 

Thank you, i solved the problem by using document.form.submit.disabled = true;

  Re: Checkbox selection client-side validation in ASP.NET & C#  tgreer at 14:57 on Thursday, January 06, 2005
 

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.










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Display swf file in pdf
•  A-Line Wedding Dresses
•  Re: how to create forum using asp.net with c# language?
•  Discount coach store
•  External hard drive recovery tips
•  Create Better Maps with Global Mapper
•  Re: How to display a message box when record is temporary stored in session/grid view
•  Sharing object in perl
•  Re: C++ Beginner question


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2012