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. Javascript validation for DataGrid

Javascript validation for DataGrid

Scheduled Pinned Locked Moved ASP.NET
questionjavascripthelpannouncement
4 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.
  • K Offline
    K Offline
    krisko
    wrote on last edited by
    #1

    Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the update button, I do a postback to capture the data entered. However I dont want to do a postback when the textboxes are empty. How do I prevent this using Javascript? My main problem is with ClientIDs. This is a common problem and if it has been beaten to death, please bear with me as I am new to Web Development. Thanks in advance for any tips or pointers. Kris.

    M 1 Reply Last reply
    0
    • K krisko

      Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the update button, I do a postback to capture the data entered. However I dont want to do a postback when the textboxes are empty. How do I prevent this using Javascript? My main problem is with ClientIDs. This is a common problem and if it has been beaten to death, please bear with me as I am new to Web Development. Thanks in advance for any tips or pointers. Kris.

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

      Hi Kris, You can add a RequiredFieldValidator[^] to the column as you normally would with the textbox, and set the ControlToValidate property to the id of the textbox, not the clientID property, and the ASP.NET does the rest for you.

      K 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Kris, You can add a RequiredFieldValidator[^] to the column as you normally would with the textbox, and set the ControlToValidate property to the id of the textbox, not the clientID property, and the ASP.NET does the rest for you.

        K Offline
        K Offline
        krisko
        wrote on last edited by
        #3

        The problem I have is that it is okay to have one of the textboxes to be empty while the other one is filled. It is invalid only if both the textboxes are emtpy. I should prevent this condition. I thought RequiredFieldValidator works with a single control. How can I use to check if both the controls are empty and only then flag the condition. Besides does this result in a Postback - if it does, then it defeats the purpose. I am trying to do client side validation. Thanks.

        M 1 Reply Last reply
        0
        • K krisko

          The problem I have is that it is okay to have one of the textboxes to be empty while the other one is filled. It is invalid only if both the textboxes are emtpy. I should prevent this condition. I thought RequiredFieldValidator works with a single control. How can I use to check if both the controls are empty and only then flag the condition. Besides does this result in a Postback - if it does, then it defeats the purpose. I am trying to do client side validation. Thanks.

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

          Yes, the RequiredFieldValidator should only service a single control. IMHO, you can either go for a customvalidator as this validator does not require you to specify the ControlToValidate property and you can set the your client side function in the ClientValidationFunction property, or you can register your client side validation when the update button is clicked. The clientid of the textbox should be in the format <datagrid_id>$_ctl<row_number>$_<control_id>, if the id of the textbox is not specified, the datagrid will automatically add the suffix to the place of the control_id. If you are not familiar with the clientid value, you can also emit the clientid value of the textbox in the web page to a client side variable so that you can use the variable later in validation at the client side.

          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