Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Client validation

Client validation

Scheduled Pinned Locked Moved ASP.NET
helptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pssuresh
    wrote on last edited by
    #1

    I have a form which has datagrid,checkboxes and radiobutton.Datagrid also contains checkboxes like what we see in mailbox.i want to do client side validation for checkboxes inside datagrid.If the user didnt select any checkboxes in datagrid and press delete, i have to throw an client side error.How to do this.any code snippets.I dont want checkboxs outside the datagrid to fire.

    M 1 Reply Last reply
    0
    • P pssuresh

      I have a form which has datagrid,checkboxes and radiobutton.Datagrid also contains checkboxes like what we see in mailbox.i want to do client side validation for checkboxes inside datagrid.If the user didnt select any checkboxes in datagrid and press delete, i have to throw an client side error.How to do this.any code snippets.I dont want checkboxs outside the datagrid to fire.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      There are a number of examples out there that you can consult. Below is just one of them: + You first need a method running on the client-side to do the checkbox status checking:

      function ValidateDeleteCheckbox(checkboxName)
      {
      var item = document.forms[0].elements[checkboxName];
      if(item != null)
      { if (item.length != null){
      for (var i=0; i<item.length; i++){
      if (item[i].checked)
      {
      return true;
      }
      }
      }
      else if(item.checked)
      {
      return true;
      }
      }

      return false;
      

      }

      I assume that each row has a check box called "chkItem" for the sake of simplicity:

      <input type="checkbox" name="chkItem" value=''>

      + Because you only need to check when the user presses the Delete button, so the above function is only called under such condition:

      this.btnDelete.Attributes.Add("onclick", "if(!ValidateDeleteCheckbox(\"chkItem\")){ alert(\"Please tick a checkbox\"); return false;}");

      In addition, you also can use a custom validator to do a checking to have a better way of displaying the error msg. And this custom validator should only be enabled when the user presses Delete:

      function Delete_OnClick()
      {
      window.document.getElementById("CustomValidator1").enabled = true;
      }

      function ClientValidate(source, arguments)
      {
      if(ValidateDeleteCheckbox("chkItem"))
      {
      arguments.IsValid = true
      }
      else
      {
      arguments.IsValid = false
      }
      window.document.getElementById("CustomValidator1").enabled = false;
      }

      Remember to assign the ClientValidate function to the custom validator's ClientValidationFunction property, and register the Delete_OnClick function for the button Click event:

      this.btnDelete.Attributes.Add("onclick", "Delete_OnClick();");

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups