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. Disable DropDownList at ClientSide

Disable DropDownList at ClientSide

Scheduled Pinned Locked Moved ASP.NET
tutorial
9 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.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.

    function Disable() {

        var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>')
        var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>')
        var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>')
        var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>')
       
        if (chk.checked == true) {
    
            btn.disabled = true;
            ddl.disabled = true;
            txt.disabled = true;
        }
        else {
            btn.disabled = false;
            txt.disabled = false;
            ddl.disabled = false;
        }
    }
    

    Thanks and best regards

    A R 2 Replies Last reply
    0
    • N Naunt

      Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.

      function Disable() {

          var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>')
          var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>')
          var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>')
          var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>')
         
          if (chk.checked == true) {
      
              btn.disabled = true;
              ddl.disabled = true;
              txt.disabled = true;
          }
          else {
              btn.disabled = false;
              txt.disabled = false;
              ddl.disabled = false;
          }
      }
      

      Thanks and best regards

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      It works and it should work for drop down list also. Just check the spelling of the Control's Id and also check and confirm if ddl is not a null.

      Anurag Gandhi.
      http://www.gandhisoft.com
      Life is a computer program and every one is the programmer of his own life.
      My latest article: Group GridView Data

      N 1 Reply Last reply
      0
      • A Anurag Gandhi

        It works and it should work for drop down list also. Just check the spelling of the Control's Id and also check and confirm if ddl is not a null.

        Anurag Gandhi.
        http://www.gandhisoft.com
        Life is a computer program and every one is the programmer of his own life.
        My latest article: Group GridView Data

        N Offline
        N Offline
        Naunt
        wrote on last edited by
        #3

        Hi thanks for the reply I have already checked ddl, it is not null and the value is "[object HTMLSelectElement]". This is my control

        Thanks and best regards

        A 1 Reply Last reply
        0
        • N Naunt

          Hi thanks for the reply I have already checked ddl, it is not null and the value is "[object HTMLSelectElement]". This is my control

          Thanks and best regards

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          As Anurag suggested, please check the Id of the dropdown. Moreover, where you are calling this javascript method Disable() from? Just a Note : May be you know this. You can avoid if..else condition by using,

          btn.disabled = chk.checked ;
          txt.disabled = chk.checked ;
          ddl.disabled = chk.checked ;

          Arun Jacob My Technical Blog : Code.NET

          N 1 Reply Last reply
          0
          • A Arun Jacob

            As Anurag suggested, please check the Id of the dropdown. Moreover, where you are calling this javascript method Disable() from? Just a Note : May be you know this. You can avoid if..else condition by using,

            btn.disabled = chk.checked ;
            txt.disabled = chk.checked ;
            ddl.disabled = chk.checked ;

            Arun Jacob My Technical Blog : Code.NET

            N Offline
            N Offline
            Naunt
            wrote on last edited by
            #5

            Thanks :)

            Arun Jacob wrote:

            please check the Id of the dropdown.

            ID is correct and I got ddl(not null), the value is "[object HTMLSelectElement]"

            Arun Jacob wrote:

            where you are calling this javascript method Disable() from?

            The calling is at Checkbox onClick, I put this code in Page_load event:

            Dim chk As CheckBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox)
            chk.Attributes.Add("onclick", "Disable()")

            Thanks and best regards

            A 1 Reply Last reply
            0
            • N Naunt

              Thanks :)

              Arun Jacob wrote:

              please check the Id of the dropdown.

              ID is correct and I got ddl(not null), the value is "[object HTMLSelectElement]"

              Arun Jacob wrote:

              where you are calling this javascript method Disable() from?

              The calling is at Checkbox onClick, I put this code in Page_load event:

              Dim chk As CheckBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox)
              chk.Attributes.Add("onclick", "Disable()")

              Thanks and best regards

              A Offline
              A Offline
              Arun Jacob
              wrote on last edited by
              #6

              ddl.disabled = true; is correct and it should work. I hope AutoPostBack is false for CheckBox. Alternatively you can try,

              ddl.disabled = "disabled";

              Arun Jacob My Technical Blog : Code.NET

              N 1 Reply Last reply
              0
              • A Arun Jacob

                ddl.disabled = true; is correct and it should work. I hope AutoPostBack is false for CheckBox. Alternatively you can try,

                ddl.disabled = "disabled";

                Arun Jacob My Technical Blog : Code.NET

                N Offline
                N Offline
                Naunt
                wrote on last edited by
                #7

                Arun Jacob wrote:

                I hope AutoPostBack is false for CheckBox.

                Sure, AutoPostBack is false.

                ddl.disabled = "disabled";

                this doesn't work too :(

                A 1 Reply Last reply
                0
                • N Naunt

                  Arun Jacob wrote:

                  I hope AutoPostBack is false for CheckBox.

                  Sure, AutoPostBack is false.

                  ddl.disabled = "disabled";

                  this doesn't work too :(

                  A Offline
                  A Offline
                  Arun Jacob
                  wrote on last edited by
                  #8

                  Okay.Then you can debug the method by using,

                  debugger;

                  debug the code and try to explore ddl object so that you can find the issue.

                  Arun Jacob My Technical Blog : Code.NET

                  1 Reply Last reply
                  0
                  • N Naunt

                    Hi All, Please advise how to enable/disable DropDownList at ClientSide. I have the following function, it does work for textbox and button but not on dropdownlist.

                    function Disable() {

                        var chk = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("chkViewAll"), CheckBox).ClientID %>')
                        var btn = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("btnAdd"), Button).ClientID %>')
                        var ddl = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddList"), DropDownList).ClientID %>')
                        var txt = document.getElementById('<%= CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtName"), textbox).ClientID %>')
                       
                        if (chk.checked == true) {
                    
                            btn.disabled = true;
                            ddl.disabled = true;
                            txt.disabled = true;
                        }
                        else {
                            btn.disabled = false;
                            txt.disabled = false;
                            ddl.disabled = false;
                        }
                    }
                    

                    Thanks and best regards

                    R Offline
                    R Offline
                    Raman Ghantiyala
                    wrote on last edited by
                    #9

                    Use Dropdownlistname.visible=false property like in aspx page if(!page.ispostback) { Dropdownlistname.visible=false; }

                    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