Dynamically populating a DropDownList, AutoPostback and JavaScript error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    #16
    ah..it does not hit the breakpoint. and the script error is displayed only when I try to check the checkbox, not when the page loads.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #17
      Okay, it sounds like the JavaScript that preforms the AutoPostback is not working.

      I don't know why this would be the case. The only thing that I can think of is that your JavaScript is somehow invalid (maybe you didn't close the <script> tag?) But your JavaScript looks fine.

      Try removing your JavaScript from the page.
      Do you get the same error?

      What web browser are you using? What version is it?

      Are you using Ajax?
      If so are you using any Ajax enabled controls?
      These may be causing a problem...


      -Frinny

      Comment

      • user1980
        New Member
        • Dec 2009
        • 112

        #18
        Hi Frinny

        Thank you for your quick responses.

        I did try to remove the javascript from the page. it still gives me the error. I am currently using IE7 and I do not have any ajax controls.
        I did try to create a new checkbox list and even that gives me the same error.

        I created a new page and could figure out the how to create a dropdown when a checkbox is selected. It works fine. But my original page still has the error for the autopostback.

        Your help is greatly appreciated.
        Thank you...

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #19
          It's too bad that you were having such a hard time with your original page.
          At least the error isn't happening on your new aspx page.

          So, in the method that handles the AutoPostback for the CheckBoxList (list??) you need to create list items for your DropDownList based on what was checked/selected.

          (I'm not sure what language you're using.)

          There are two ways to do this. You can create generate ListItem objects and add them to your DropDownList's "Items" property. Or you can bind your DropDownList to a data source.

          -Frinny

          Comment

          • user1980
            New Member
            • Dec 2009
            • 112

            #20
            yeah. I did use the items property to make my dropdowns work and it works fine, but still could not figure out what is wrong with original page.

            Anyway thanks a lot for your help and support.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #21
              Ah, sorry I miss-read your response.
              You have figured out how to dynamically populate your DropDownList.
              Contrats!

              :)

              I have no idea what is wrong with your page.
              I can't see you page so....I'm kind of in the dark here.

              The only reasons that I can think of is that there is some sort of invalid JavaScript or Ajax on the page that is breaking the code that normally preforms the AutoPostback.

              Stuff like not closing the script tag or leaving out a curly brace ("}") or something.

              If you want to debug your original page, and you don't want to move your code into the new page, then (...I think I'm going to regret asking for this but...) please post the entire ASPX page code. **winces**

              -Frinny

              Comment

              • user1980
                New Member
                • Dec 2009
                • 112

                #22
                Thank you.

                But I am afraid I wont be able to post the aspx code as it has many fields that are pulled from a database.
                Anyway, I will try to move my code once I figure out a small issue that i have with my new page.

                My new issue, as mentioned earlier I have a checkbox list. But checking only one box should enable the dropdown.
                For example,
                • Web
                • Employees
                • Newspaper
                • Other


                As it is a checkbox list, a user can select any number of checkboxes. BUt my dropdwon should be enabled only when newspapers is checked.I see that whenever I select more than two checkboxes, the CheckBoxList1.S electedValue still has only one value. For example a user selects both web and newspaper, but the dropdown is not enabled as CheckBoxList1.S electedValue is Web.
                In my CheckBoxList1_S electedIndexCha nged, I am using
                Code:
                if (CheckBoxList1.SelectedValue == "NewsPaper"){//enable dropdown}
                Am I missing a logic here or is there any way to collect all the values that are checked
                Any help would be greatly appreciated.
                Please let me know if I am not clear.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #23
                  Loop through each item in the CheckBoxList and check if it is "NewsPaper" and if it is selected.

                  The thing is that the CheckBoxList is going to post back every time a check box is checked within it. Make sure you check to see if the DropDownList is already populated.

                  -Frinny

                  Comment

                  • user1980
                    New Member
                    • Dec 2009
                    • 112

                    #24
                    Hello Frinny

                    Thanks for all the help. I have accomplished all the required functionality. But still my script error exists, I tried to transfer my original page code to a new page...and again the script error pops up...still struggling to find out the cause.

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #25
                      Wish I could help but I'm in the dark here.
                      Can't see what you're doing.

                      -Frinny

                      Comment

                      • user1980
                        New Member
                        • Dec 2009
                        • 112

                        #26
                        yeah..I can understand. Wish I could share the .aspx file.
                        Anyway, I am debugging the code line by line...and trying to find my luck

                        Thank you..

                        Comment

                        • user1980
                          New Member
                          • Dec 2009
                          • 112

                          #27
                          Hurray, my code is working.
                          I had a sumbit button in my page with id='submit' and I did change the small letter 's' to capital letter 'S' and it working like a charm..
                          It was a silly thing but dont know why it caused the problem. Have found this solution online after hours of searching.
                          Thought this could help someone like me.

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #28
                            It's strange that this would cause a problem with JavaScript.
                            Regardless I'm glad you solved your problem :)

                            -Frinny

                            Comment

                            Working...