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. Fire validation when a selectbox item is selected

Fire validation when a selectbox item is selected

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthelpquestion
11 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.
  • C CWIZO

    Hi, I have a web form that has some textboxes and a submit button that saves the form. I also have two selectboxes (drop down list) on the top of the page. The content of the form is changed when you select a different item in any of those two selectboxes (year and month). I have validators on the form that are working nice when I click the button (if an error accrues the submitting is canceled and a validationcontrol is shown). But when I change a item on a selectbox (AutoPostBack = true) the submit happens even dough there are errors on the form. What I would like to accomplish basically is that when you change the item validation accurse and if there are any errors cancel the submit (and show validation control). I have "hacked" a little and used this code to accomplish this (but this is a hack, and I am sure there is a right way to do this) Me.ddlMonth.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlMonth.Attributes.Add("language", "javascript") Me.ddlYear.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlYear.Attributes.Add("language", "javascript") Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

    C Offline
    C Offline
    CWIZO
    wrote on last edited by
    #2

    Anybody? Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us! -- modified at 2:40 Thursday 16th February, 2006

    1 Reply Last reply
    0
    • C CWIZO

      Hi, I have a web form that has some textboxes and a submit button that saves the form. I also have two selectboxes (drop down list) on the top of the page. The content of the form is changed when you select a different item in any of those two selectboxes (year and month). I have validators on the form that are working nice when I click the button (if an error accrues the submitting is canceled and a validationcontrol is shown). But when I change a item on a selectbox (AutoPostBack = true) the submit happens even dough there are errors on the form. What I would like to accomplish basically is that when you change the item validation accurse and if there are any errors cancel the submit (and show validation control). I have "hacked" a little and used this code to accomplish this (but this is a hack, and I am sure there is a right way to do this) Me.ddlMonth.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlMonth.Attributes.Add("language", "javascript") Me.ddlYear.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlYear.Attributes.Add("language", "javascript") Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #3

      can't you just check for error inside the submit and cancel there? 1 line of code equals many bugs. So don't write any!!

      C 1 Reply Last reply
      0
      • I Ista

        can't you just check for error inside the submit and cancel there? 1 line of code equals many bugs. So don't write any!!

        C Offline
        C Offline
        CWIZO
        wrote on last edited by
        #4

        Well that is what I am doing now... And that is a hack. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

        I 1 Reply Last reply
        0
        • C CWIZO

          Well that is what I am doing now... And that is a hack. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #5

          Not actually. Validator aren't required. There many ways to validate. And it can be argued that validators are not the best way to validate. My classes validate data not validators. So it depends on one's perception and programming style. Nick 1 line of code equals many bugs. So don't write any!! -- modified at 12:07 Thursday 16th February, 2006

          C 1 Reply Last reply
          0
          • I Ista

            Not actually. Validator aren't required. There many ways to validate. And it can be argued that validators are not the best way to validate. My classes validate data not validators. So it depends on one's perception and programming style. Nick 1 line of code equals many bugs. So don't write any!! -- modified at 12:07 Thursday 16th February, 2006

            C Offline
            C Offline
            CWIZO
            wrote on last edited by
            #6

            Well we are using client side validation (don't ask me why there is no server side), and so I need a solution for that... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

            I 1 Reply Last reply
            0
            • C CWIZO

              Well we are using client side validation (don't ask me why there is no server side), and so I need a solution for that... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #7

              how funny. I wont even go there. 1 line of code equals many bugs. So don't write any!!

              C 1 Reply Last reply
              0
              • I Ista

                how funny. I wont even go there. 1 line of code equals many bugs. So don't write any!!

                C Offline
                C Offline
                CWIZO
                wrote on last edited by
                #8

                Not my fault for that really... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

                I 1 Reply Last reply
                0
                • C CWIZO

                  Not my fault for that really... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

                  I Offline
                  I Offline
                  Ista
                  wrote on last edited by
                  #9

                  I know. I've had a contract at places with backwards thinking 1 line of code equals many bugs. So don't write any!!

                  1 Reply Last reply
                  0
                  • C CWIZO

                    Hi, I have a web form that has some textboxes and a submit button that saves the form. I also have two selectboxes (drop down list) on the top of the page. The content of the form is changed when you select a different item in any of those two selectboxes (year and month). I have validators on the form that are working nice when I click the button (if an error accrues the submitting is canceled and a validationcontrol is shown). But when I change a item on a selectbox (AutoPostBack = true) the submit happens even dough there are errors on the form. What I would like to accomplish basically is that when you change the item validation accurse and if there are any errors cancel the submit (and show validation control). I have "hacked" a little and used this code to accomplish this (but this is a hack, and I am sure there is a right way to do this) Me.ddlMonth.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlMonth.Attributes.Add("language", "javascript") Me.ddlYear.Attributes.Add("onchange", "if (typeof(Page_ClientValidate) == 'function'){if (Page_ClientValidate()==false)return false;}") Me.ddlYear.Attributes.Add("language", "javascript") Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

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

                    Hi there, Your hack is nice and IMHO it should be your choice. As you probably know that by design the snippet of client side validation script is automatically injected into the client side event onclick of the button, but not for the onchange event of the dropdownlist. The ASP.NET uses the static method GetClientValidateEvent of the internal class System.Web.UI.Util to get the script, then inject into the onclick attribute of the button when it is rendered. So you can see that the ASP.NET also uses the similar way like yours. For the dropdownlist, this thing does not happen so you have to do it on your own, so if you want, you can customize the built-in DropDownList control by overriding the AddAttributesToRender method, put your sample code in there after you check if the dropdownlist has the AutoPostBack enabled and there are validators in the page.

                    C 1 Reply Last reply
                    0
                    • M minhpc_bk

                      Hi there, Your hack is nice and IMHO it should be your choice. As you probably know that by design the snippet of client side validation script is automatically injected into the client side event onclick of the button, but not for the onchange event of the dropdownlist. The ASP.NET uses the static method GetClientValidateEvent of the internal class System.Web.UI.Util to get the script, then inject into the onclick attribute of the button when it is rendered. So you can see that the ASP.NET also uses the similar way like yours. For the dropdownlist, this thing does not happen so you have to do it on your own, so if you want, you can customize the built-in DropDownList control by overriding the AddAttributesToRender method, put your sample code in there after you check if the dropdownlist has the AutoPostBack enabled and there are validators in the page.

                      C Offline
                      C Offline
                      CWIZO
                      wrote on last edited by
                      #11

                      Thanks for your anwser. I will leave it as it is. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

                      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