Calling a method from a drop down control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doogie

    Calling a method from a drop down control

    If I run this code below in ASP.NET 2.0 it fails with an "Object
    Required" error and I have no idea why.

    Could someone tell me why this is failing? Then if I can get an
    answer to that, I would actually prefer to run a C# method instead of
    a javascript one and would like to figure out how to set that up (but
    I get the same error doing that too).

    <select id="cbCarriers " onchange="javas cript: test();">
    <option value='241'>3GP </option>
    <option value='441'>AAC </option>
    <option value='1115'>AB 1</option>
    </select>

    <script type="javascrip t">
    function test()
    {
    alert("this");
    }
    </script>

  • David Mark

    #2
    Re: Calling a method from a drop down control

    On Jul 13, 11:13 am, Doogie <dnlwh...@dtgne t.comwrote:
    If I run this code below in ASP.NET 2.0 it fails with an "Object
    Required" error and I have no idea why.
    >
    Could someone tell me why this is failing? Then if I can get an
    answer to that, I would actually prefer to run a C# method instead of
    a javascript one and would like to figure out how to set that up (but
    I get the same error doing that too).
    >
    <select id="cbCarriers " onchange="javas cript: test();">
    <option value='241'>3GP </option>
    <option value='441'>AAC </option>
    <option value='1115'>AB 1</option>
    </select>
    >
    <script type="javascrip t">
    function test()
    {
    alert("this");
    }
    </script>
    onchange="test( );"

    And don't do this for navigation. Keyboard and mousewheel users will
    hate it.

    As for .NET and C#, you will have to ask elsewhere.

    Comment

    • Benjamin Sattler

      #3
      Re: Calling a method from a drop down control

      Hi!

      Doogie <dnlwhite@dtgne t.comwrote:

      [snip]
      <select id="cbCarriers " onchange="javas cript: test();">
      ^^^
      [/snip]

      Have you tried and removed the space I'm pointing at?

      bye

      Comment

      • Daz

        #4
        Re: Calling a method from a drop down control

        On Jul 13, 4:13 pm, Doogie <dnlwh...@dtgne t.comwrote:
        If I run this code below in ASP.NET 2.0 it fails with an "Object
        Required" error and I have no idea why.
        >
        Could someone tell me why this is failing? Then if I can get an
        answer to that, I would actually prefer to run a C# method instead of
        a javascript one and would like to figure out how to set that up (but
        I get the same error doing that too).
        >
        <select id="cbCarriers " onchange="javas cript: test();">
        <option value='241'>3GP </option>
        <option value='441'>AAC </option>
        <option value='1115'>AB 1</option>
        </select>
        >
        <script type="javascrip t">
        function test()
        {
        alert("this");
        }
        </script>
        Try removing the "javascript : " clause from your function. It's not
        needed, as anything within the onchange attribute is automatically
        passed on to the JavaScript engine, as onchange is JavaScript.

        Comment

        • Doogie

          #5
          Re: Calling a method from a drop down control

          >
          onchange="test( );"
          >
          And don't do this for navigation. Keyboard and mousewheel users will
          hate it.
          >
          Not sure what you are getting at with the navigation...bu t I tried
          putting the onchange value like you have above and it still failed.

          Comment

          • Doogie

            #6
            Re: Calling a method from a drop down control

            [snip]
            >
            <select id="cbCarriers " onchange="javas cript: test();">
            >
            ^^^
            [/snip]
            >
            Have you tried and removed the space I'm pointing at?
            >
            Yes, I tried to remove that space so that there is no space between
            the : and 'test' and it still fails with the same error.

            Comment

            • Doogie

              #7
              Re: Calling a method from a drop down control

              Try removing the "javascript : " clause from your function. It's not
              needed, as anything within the onchange attribute is automatically
              passed on to the JavaScript engine, as onchange is JavaScript.- Hide quoted text -
              >
              - Show quoted text -
              I tried that and it didn't work...however I think I found my
              javascript issue...my <scripttag was incorrect...onc e I got it like
              this:

              <script language="JavaS cript" type="text/javascript">

              It worked fine. But, now I need to figure out a way to have this call
              a .NET method. Is that even possible with a client side control?

              Comment

              • Benjamin Sattler

                #8
                Re: Calling a method from a drop down control

                Doogie <dnlwhite@dtgne t.comwrote:

                [snip]
                It worked fine. But, now I need to figure out a way to have
                this call a .NET method. Is that even possible with a client
                side control?
                >
                I don't know, but maybe those guys can help you:

                microsoft.publi c.dotnet.langua ges.csharp

                Guess it's that group.

                Comment

                • David Mark

                  #9
                  Re: Calling a method from a drop down control

                  On Jul 13, 11:43 am, Doogie <dnlwh...@dtgne t.comwrote:
                  [snip]
                  >
                  <select id="cbCarriers " onchange="javas cript: test();">
                  >
                  ^^^
                  [/snip]
                  >
                  Have you tried and removed the space I'm pointing at?
                  >
                  Yes, I tried to remove that space so that there is no space between
                  the : and 'test' and it still fails with the same error.
                  Also change the type attribute of the script tag as noted by another
                  posted.

                  And as for the navigation issue, try it with the keyboard and/or a
                  mousewheel. SELECT tags are form inputs and not meant to be used as
                  menus. I know that there are millions of incompetent sites out there
                  doing this, but you shouldn't follow their lead. If you must do this,
                  pair the input with a button.

                  Comment

                  • Doogie

                    #10
                    Re: Calling a method from a drop down control

                    And as for the navigation issue, try it with the keyboard and/or a
                    mousewheel. SELECT tags are form inputs and not meant to be used as
                    menus. I know that there are millions of incompetent sites out there
                    doing this, but you shouldn't follow their lead. If you must do this,
                    pair the input with a button.
                    I'm using the select tag to create a drop down list. I actually am
                    not creating the tag myself, our company has a common method that you
                    can query the DB and return the values inside a string that is the
                    select tag itself. So I just reference the string variable in my html
                    and the drop down box is created. I don't believe I'm using it as a
                    menu in the sense of how you are describing but am not really sure.

                    Comment

                    • David Mark

                      #11
                      Re: Calling a method from a drop down control

                      On Jul 13, 12:21 pm, Doogie <dnlwh...@dtgne t.comwrote:
                      And as for the navigation issue, try it with the keyboard and/or a
                      mousewheel. SELECT tags are form inputs and not meant to be used as
                      menus. I know that there are millions of incompetent sites out there
                      doing this, but you shouldn't follow their lead. If you must do this,
                      pair the input with a button.
                      >
                      I'm using the select tag to create a drop down list. I actually am
                      not creating the tag myself, our company has a common method that you
                      can query the DB and return the values inside a string that is the
                      select tag itself. So I just reference the string variable in my html
                      and the drop down box is created. I don't believe I'm using it as a
                      menu in the sense of how you are describing but am not really sure.
                      What is it that you are doing in the onchange event? If you are
                      navigating to another page, that is a bad idea. That is what I was
                      referring to. It is a common and very irritating practice. I really
                      can't think of anything that should be done in the onchange event of a
                      select tag, but faux navigation menus are the worst example.


                      Comment

                      • Doogie

                        #12
                        Re: Calling a method from a drop down control

                        What is it that you are doing in the onchange event? If you are
                        navigating to another page, that is a bad idea. That is what I was
                        referring to. It is a common and very irritating practice. I really
                        can't think of anything that should be done in the onchange event of a
                        select tag, but faux navigation menus are the worst example.
                        Well, the select tag is inside a user control and so I need to get the
                        value of the item selected within it, so that when the user clicks on
                        the command button (also in that control), I have the proper value to
                        do a database call. So I want to grab that value and store it in a
                        variable inside the user control and pass it over to the actual page
                        that is using the user control. That's also why I would prefer to do
                        this inside .net instead of javascript so I can easily send that value
                        from the user control to the page that uses the control.

                        Comment

                        • David Mark

                          #13
                          Re: Calling a method from a drop down control

                          On Jul 13, 12:39 pm, Doogie <dnlwh...@dtgne t.comwrote:
                          What is it that you are doing in the onchange event? If you are
                          navigating to another page, that is a bad idea. That is what I was
                          referring to. It is a common and very irritating practice. I really
                          can't think of anything that should be done in the onchange event of a
                          select tag, but faux navigation menus are the worst example.
                          >
                          Well, the select tag is inside a user control and so I need to get the
                          value of the item selected within it, so that when the user clicks on
                          the command button (also in that control), I have the proper value to
                          Why not check the value when the user clicks the button?

                          Comment

                          • Doogie

                            #14
                            Re: Calling a method from a drop down control

                            Why not check the value when the user clicks the button?

                            That's a good idea too. However, since I am building this select tag
                            dynamically and it is a client side control, I'm thinking I'll have
                            issues trying to determine it's value in any case inside .net. I
                            might have to either stick with javascript or use a server side drop
                            down box.

                            Comment

                            • Daz

                              #15
                              Re: Calling a method from a drop down control

                              On Jul 13, 4:46 pm, Doogie <dnlwh...@dtgne t.comwrote:
                              Try removing the "javascript : " clause from your function. It's not
                              needed, as anything within the onchange attribute is automatically
                              passed on to the JavaScript engine, as onchange is JavaScript.- Hide quoted text -
                              >
                              - Show quoted text -
                              >
                              I tried that and it didn't work...however I think I found my
                              javascript issue...my <scripttag was incorrect...onc e I got it like
                              this:
                              >
                              <script language="JavaS cript" type="text/javascript">
                              >
                              It worked fine. But, now I need to figure out a way to have this call
                              a .NET method. Is that even possible with a client side control?
                              The language attribute has now been deprecated, as of HTML 4.0(?). You
                              only need to supply the type.

                              Comment

                              Working...