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. Custom Validation inside Repeater

Custom Validation inside Repeater

Scheduled Pinned Locked Moved ASP.NET
help
7 Posts 3 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.
  • R Offline
    R Offline
    RaviKalyanK
    wrote on last edited by
    #1

    I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help

    Regards, Ravi K. Kalyan

    G A 2 Replies Last reply
    0
    • R RaviKalyanK

      I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help

      Regards, Ravi K. Kalyan

      G Offline
      G Offline
      Gamzun
      wrote on last edited by
      #2

      You can validate on OnItemDataBound event of repeater.

      Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

      1 Reply Last reply
      0
      • R RaviKalyanK

        I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help

        Regards, Ravi K. Kalyan

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        What is the problem with that. Repeater actually places the same html that you define in ItemTemplate and AlternateItemTemplate. You can easily use OnItemDataBound event to find the controls. Inside it write like this: if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternateItem) { TextBox tb = e.Item.FindControl("yourserversideiD"); tb.Attributes.Add("onblur", yourjavascript); } Like this way you can easily find any serverside control inside Repeater and apply your javascript. so try this out.. :rose:

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        R 1 Reply Last reply
        0
        • A Abhishek Sur

          What is the problem with that. Repeater actually places the same html that you define in ItemTemplate and AlternateItemTemplate. You can easily use OnItemDataBound event to find the controls. Inside it write like this: if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternateItem) { TextBox tb = e.Item.FindControl("yourserversideiD"); tb.Attributes.Add("onblur", yourjavascript); } Like this way you can easily find any serverside control inside Repeater and apply your javascript. so try this out.. :rose:

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          R Offline
          R Offline
          RaviKalyanK
          wrote on last edited by
          #4

          Guys, Thanks for the reply. All I need is a client side validation. Server side is just a matter of 20min for me... I'm looking for a client side validation. Thanks

          Regards, Ravi K. Kalyan

          A 1 Reply Last reply
          0
          • R RaviKalyanK

            Guys, Thanks for the reply. All I need is a client side validation. Server side is just a matter of 20min for me... I'm looking for a client side validation. Thanks

            Regards, Ravi K. Kalyan

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            Hey Ravi... Believe me.. I was really talking about client side validation in the code above. onblur is a client side event, I think. Just place your javascript there. Call the validation javascript from there. if you pass like this : txt.Attributes.Add("onblur", "javascript:func(this)") you will get the txtbox on the function. Also you might use txt.ClientId to pass the id. :)

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Simplify Code Using NDepend
            Basics of Bing Search API using .NET
            Microsoft Bing MAP using Javascript

            R 1 Reply Last reply
            0
            • A Abhishek Sur

              Hey Ravi... Believe me.. I was really talking about client side validation in the code above. onblur is a client side event, I think. Just place your javascript there. Call the validation javascript from there. if you pass like this : txt.Attributes.Add("onblur", "javascript:func(this)") you will get the txtbox on the function. Also you might use txt.ClientId to pass the id. :)

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Simplify Code Using NDepend
              Basics of Bing Search API using .NET
              Microsoft Bing MAP using Javascript

              R Offline
              R Offline
              RaviKalyanK
              wrote on last edited by
              #6

              My requirement is to validate the SSN in Save_Click event. NOT in "Onblur" event. I also have "Add Child" button using which I'm adding new Repeater.. So I can add N number of children before clicking on save button. And each repeater is having SSN1, SSN2 and SSN3 textboxes that I need to validate. Thanks for the replies. Ravi

              Regards, Ravi K. Kalyan

              A 1 Reply Last reply
              0
              • R RaviKalyanK

                My requirement is to validate the SSN in Save_Click event. NOT in "Onblur" event. I also have "Add Child" button using which I'm adding new Repeater.. So I can add N number of children before clicking on save button. And each repeater is having SSN1, SSN2 and SSN3 textboxes that I need to validate. Thanks for the replies. Ravi

                Regards, Ravi K. Kalyan

                A Offline
                A Offline
                Abhishek Sur
                wrote on last edited by
                #7

                Ok.. so for each SSN1, SSN2 and SSN3 you will be having one button.. So do like this :

                Button btn = e.Item.FindControl("yourbuttonid");
                TextBox SSN1 = e.Item.FindControl("SSN1ID");
                TextBox SSN2 = e.Item.FindControl("SSN2ID");
                TextBox SSN3 = e.Item.FindControl("SSN3ID");
                string script = "javascript:validate('" + SSN1.ClientId + "','" + SSN2.ClientId + "','" + SSN3.ClientId + "');";
                btn.Attributes.Add("onclick", script);

                Now in the page designer, place a script tag and add a function validate:

                function validate(ssn1id, ssn2id, ssn3id){
                var ssn1 = document.getElementById(ssn1id);
                var ssn2 = document.getElementById(ssn2id);
                var ssn3 = document.getElementById(ssn3id);

                // do the logic here.

                }

                I home this is what you wanted. :thumbsup:

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Simplify Code Using NDepend
                Basics of Bing Search API using .NET
                Microsoft Bing MAP using Javascript

                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