Dynamically populating a DropDownList, AutoPostback and JavaScript error

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

    Dynamically populating a DropDownList, AutoPostback and JavaScript error

    hello,

    i am trying to create a request form using asp.net where when a user selects a checkbox, a dropdown should appear dynamically. I have seen few java-scripts in web, but I was wondering if I can achieve this without java-script.

    I tried to make the control invisible(<asp: DropDownList ID="DropDownLis t1" runat="server" AppendDataBound Items="True" Visible="False">) and in the onselectedindex changed event, tried to make the invisible property to true. But it did not help me.
    Also, I was trying to use postback for the page when a checkbox is selected(asp:Ch eckBoxList ID="chckbx" runat="server" AutoPostBack="t rue" onselectedindex changed="chckbx _SelectedIndexC hanged") and it throws me an error in IE saying the object does not support this property.


    Can somebody please help me with this. Thanks in advance.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Before you continue please take a look at this article on:
    How to use dynamic controls in ASP.NET.

    -Frinny

    Comment

    • user1980
      New Member
      • Dec 2009
      • 112

      #3
      thank you for the reply.

      I am able to understand the example in the link but could not really put it into working for my scenario.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Ok, in your scenario you need to do this when the user checks a checkbox.
        I'm assuming that you need to populate the drop down list with items depending on what the user has checked.

        This is not dynamically creating a control.

        What you need to do is dynamically populate the drop down list.

        What do you have currently that we can use as a starting point?

        -Frinny
        (PS please post code in code tags)

        Comment

        • user1980
          New Member
          • Dec 2009
          • 112

          #5
          Yes, I have to populate the dropdown based on the selection of checkbox.

          Here is my information. I have four sources of information as checkboxes, newspapers,web, employee and others. Now when a user checks newspapers, the dropdown must populate, tribune,WSjourn al,PJ star.

          And one more thing is if I put the autopostback ppty for checkbox to true, it throws me an error. This should be something very basic, am I missing something?
          Thanks for all your help.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Lets fix the error because you need to set the checkBoxList's autopostback=tr ue.
            Please post the error details.

            -Frinny

            Comment

            • user1980
              New Member
              • Dec 2009
              • 112

              #7
              the error appears only in IE, as a script error. I mean the page loads normally but on the left hand bottom corner, it says there is an error on the page. When i click on it, it tells me the the object does not support this property or method.
              When I try to debug the page without the autopostback property, it does not display any error.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Do you have any additional JavaScript on the page?

                -Frinny

                Comment

                • user1980
                  New Member
                  • Dec 2009
                  • 112

                  #9
                  yes, a one line javascript to open a pop-up window.

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Post that code please.

                    -Frinny

                    Comment

                    • user1980
                      New Member
                      • Dec 2009
                      • 112

                      #11
                      Code:
                      function window_open()
                            {
                             window.open("Codes.aspx","","menubar=no,status=no,scrollbars=yes,resizable=yes,toolbar=no,top=180,left=250,width=750,height=600");
                            }
                      the ap.net control that calls it,
                      Code:
                      <asp:Button runat="server" ID="btnlookup" Text="Code" OnClientClick="window_open()" CausesValidation="false" Width="90px" />

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        I don't see anything wrong with this JavaScript.
                        I'm going to ask that a JavaScript expert take a look at this.

                        Does this problem prevent your code from being executed?
                        If so, could you remove it while we are fixing your current problem with dynamically populating the DropDownList?

                        -Frinny

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          I'm going to ask that a JavaScript expert take a look at this.
                          I can’t find anything wrong, works as expected when inserted in plain text HTML.

                          Comment

                          • user1980
                            New Member
                            • Dec 2009
                            • 112

                            #14
                            my page executes normally. but I just wanted to get rid of the error and also wanted to postback the page when I check the checkbox.

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Well enable autopostback for the checkbox.
                              Put a break point on the method that handles the event and run the application.
                              Do you hit the break point?

                              -Frinny

                              Comment

                              Working...