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. Validation in TextBox controls in asp.net

Validation in TextBox controls in asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nethelp
7 Posts 4 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.
  • A Offline
    A Offline
    aaraaayen 0
    wrote on last edited by
    #1

    Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,

    Prya

    C L 2 Replies Last reply
    0
    • A aaraaayen 0

      Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,

      Prya

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      ASP.NET has validator controls built in, you can define a validation group, a validator for each text field, and messages to show by the textboxes, and in a group in one part of the page. There's a RequiredFieldValidator, a RegularExpressionValidator, and even a CustomValidator, which can be used to run any javascript you like.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      A 1 Reply Last reply
      0
      • C Christian Graus

        ASP.NET has validator controls built in, you can define a validation group, a validator for each text field, and messages to show by the textboxes, and in a group in one part of the page. There's a RequiredFieldValidator, a RegularExpressionValidator, and even a CustomValidator, which can be used to run any javascript you like.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        A Offline
        A Offline
        aaraaayen 0
        wrote on last edited by
        #3

        Thanks a lot for your reply. But, if i use required field validator then, have to use 35-40 that much of validators. sometimes if there is a textbox for more than 100 then also v have to use more than 100 of required field validator. so is there any possiblity in javascript, for validating all the textboxes should not be empty.

        Prya

        C 1 Reply Last reply
        0
        • A aaraaayen 0

          Thanks a lot for your reply. But, if i use required field validator then, have to use 35-40 that much of validators. sometimes if there is a textbox for more than 100 then also v have to use more than 100 of required field validator. so is there any possiblity in javascript, for validating all the textboxes should not be empty.

          Prya

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You can write a custom validator that iterates over all the textboxes, I suppose. But, in the end, given the code that's needed to get a reference to a textbox, it would still be quicker to put the actual validation into a single function, which means you're again better off using the built in stuff. You may be able to recursively iterate over the document looking for textboxes and check if they are empty, but I don't believe it's worthwhile.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • A aaraaayen 0

            Hi friends, I am working in asp.net 2.0. in my page i am having 35-40 textboxes. I want to validate for all the textboxes ie., if the textbox is empty is should give proper message. i want to validate it through javascript. Please give me suggestion. Expecting help. Thank in Advance, Regards,

            Prya

            L Offline
            L Offline
            Laxmikant Lad
            wrote on last edited by
            #5

            hi write function in javascript and on form load event add attribute onblur to this function or else on button click u can call js function in which u will check whether any textbox is empty

            A 1 Reply Last reply
            0
            • L Laxmikant Lad

              hi write function in javascript and on form load event add attribute onblur to this function or else on button click u can call js function in which u will check whether any textbox is empty

              A Offline
              A Offline
              aaraaayen 0
              wrote on last edited by
              #6

              Hi, Thanks. you told that add function in javascript. but we have to specify the name of the textbox in that function know. Then we have to write for every textbox? Can you please explain me. Thanks and Regards,

              Prya

              V 1 Reply Last reply
              0
              • A aaraaayen 0

                Hi, Thanks. you told that add function in javascript. but we have to specify the name of the textbox in that function know. Then we have to write for every textbox? Can you please explain me. Thanks and Regards,

                Prya

                V Offline
                V Offline
                Vsree
                wrote on last edited by
                #7

                hello Write as in Page_Load() txt1.Attributes.Add("onblur","javascript:checkValid(this);"); txt2.Attributes.Add("onblur","javascript:checkValid(this);"); ....(write for all textboxes) txt40.Attributes.Add("onblur","javascript:checkValid(this);"); In javascript function checkValid(txtSamp) { if(txtSamp.value =="") alert('Please enter value'); } Here the function you are calling for all the textboxes is the same,but the arguement differs...'this' keyword refers to the textbox object for which you are calling the function(no need for the name in this function). Hope this helps you ~VSree

                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