Very simple question on Javascript with ASP button

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

    #1

    Very simple question on Javascript with ASP button

    Hi guys,

    I searched around without any clear answer. Tons of stuff, but nothing concrete.

    I am trying to call this Javascript function:

    function ButtonClicked()
    {
    alert("The button has been clicked.");
    }

    Calling it from an HTML button is no problem at all. But there is no way I can call that function from an ASP button. I tried from the HTML side or the aspx side.

    I understood that an ASP button run only on the server. But I can't believe you can't make that simple call. I really hate to use HTML button when the design with ASP on a Web Form is so fast and easy.

    Since I am a newbie, some code example will be appreciated.

    Briefly, I have an ASP button that I want to call the Javascript function "ButtonClic ked"

    Thanks

    Frag

  • Erwin Moller

    #2
    Re: Very simple question on Javascript with ASP button

    Frag wrote:
    [color=blue]
    > Hi guys,
    >
    > I searched around without any clear answer. Tons of stuff, but nothing
    > concrete.
    >
    > I am trying to call this Javascript function:
    >
    > function ButtonClicked()
    > {
    > alert("The button has been clicked.");
    > }
    >
    > Calling it from an HTML button is no problem at all. But there is no way I
    > can call that function from an ASP button. I tried from the HTML side or
    > the aspx side.
    >
    > I understood that an ASP button run only on the server. But I can't
    > believe you can't make that simple call. I really hate to use HTML button
    > when the design with ASP on a Web Form is so fast and easy.
    >
    > Since I am a newbie, some code example will be appreciated.
    >
    > Briefly, I have an ASP button that I want to call the Javascript function
    > "ButtonClic ked"
    >
    > Thanks
    >
    > Frag[/color]

    Hi Frag,

    I haven't got a clue what an ASP-button is, but if it is some HTML generated
    by a tool, just look into the code it produces.
    If you see <a href="">blabla</a> that is where you can try to add some
    simple code in the anchor, like onClick="".

    If the code is always generated dynamically, you should read in the specs
    how to add extra things to it (if possible).

    Regards,
    Erwin Moller

    Comment

    • kaeli

      #3
      OT: ASP.NET (was Re: Very simple question on Javascript with ASP button)

      In article <eCYPb.3$Uz.2@f e09.usenetserve r.com>, frag@frag.com
      enlightened us with...[color=blue]
      >
      > Calling it from an HTML button is no problem at all. But there is no way I can call that
      > function from an ASP button. I tried from the HTML side or the aspx side.[/color]

      Sure you can.
      Attach the script to it.




      Questions about dotnet best directed to
      msnews:microsof t.public.dotnet .scripting.

      Oh, and I don't use dotnet. I found the answer on Google in about a
      minute. Google is your friend.

      --
      --
      ~kaeli~
      If a book about failures doesn't sell, is it a success?



      Comment

      • Unregistered

        #4
        Re: Very simple question on Javascript with ASP button


        Public Sub btnCallJavascri pt_Click(ByVal sender As System.Object,
        ByVal e As System.EventArg s) Handles btnCallJavascri pt.Click

        lblScript.Text = "<SCRIPT
        language='Javas cript1.2'>popUp )
        </SCRIPT>"

        End Su

        Unregistered
        -----------------------------------------------------------------------
        Posted via http://www.forum4designers.co
        -----------------------------------------------------------------------
        View this thread: http://www.forum4designers.com/message36240.htm

        Comment

        • Randy Webb

          #5
          Re: Very simple question on Javascript with ASP button

          Unregistered wrote:[color=blue]
          > Public Sub btnCallJavascri pt_Click(ByVal sender As System.Object,
          > ByVal e As System.EventArg s) Handles btnCallJavascri pt.Click
          >
          > lblScript.Text = "<SCRIPT
          > language='Javas cript1.2'>popUp )
          > </SCRIPT>"[/color]

          Why do people continue to use the outdated language attribute? And when
          they do use it, they use a buggy version number without knowing the
          possible implications of it?

          <script language="javas cript1.2">
          a = 30;
          b = 40;
          if (a = b){
          alert('They are equal')
          }
          else{
          alert('They are not equal')
          }
          </script>

          Test the above in Netscape 4.xx, and then any other browser.
          [color=blue]
          >
          > End Sub
          >[/color]
          [color=blue]
          > Unregistered -
          > ------------------------------------------------------------------------
          > Posted via http://www.forum4designers.com
          > ------------------------------------------------------------------------
          > View this thread: http://www.forum4designers.com/message36240.html
          >[/color]

          You really should get a real newsreader and subscribe to
          new:comp.lang.j avascript and stop using a site that portrays itself as a
          "private forum" when it is anything but that.

          Its more a joke than anything else.


          --
          Randy
          Chance Favors The Prepared Mind
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          • Richard Cornford

            #6
            Re: Very simple question on Javascript with ASP button

            "Randy Webb" <hikksnotathome @aol.com> wrote in message
            news:WqOdneeSTr ZSLbbdRVn_iw@co mcast.com...
            <snip>[color=blue]
            ><script language="javas cript1.2">
            >a = 30;
            >b = 40;
            >if (a = b){
            >alert('They are equal')
            >}
            >else{
            >alert('They are not equal')
            >}
            ></script>
            >Test the above in Netscape 4.xx, and then any other browser.[/color]

            It might be best not to do the comparison with IceBrowser as it uses the
            Rhino javascript engine and the docs for Rhino say it will respect
            language="javas cript1.2" and use the alternative type-converting rules
            (though I have never tested that, not using the language attribute
            myself anymore).

            It is a bit unfair to use the text "They are equal" when the test you
            are performing is an assignment (not comparison), though it adequately
            illustrates the problem.

            Here are a few comparisons illustrations of the differences:-

            <html>
            <head>
            <title></title>
            </head>
            <body>
            <script language="javas cript1.2">
            if("40" == 40){
            document.write( '(&quot;40&quot ; == 40) is true.<br>')
            }else{
            document.write( '(&quot;40&quot ; == 40) is false.<br>')
            }
            if(0 == false){
            document.write( '(0 == false) is true.<br>')
            }else{
            document.write( '(0 == false) is false.<br>')
            }
            if("" == false){
            document.write( '(&quot;&quot; == false) is true.<br>')
            }else{
            document.write( '(&quot;&quot; == false) is false.<br>')
            }
            </script>
            </body>
            </html>
            [color=blue][color=green]
            >> Posted via http://www.forum4designers.com[/color][/color]
            <snip>[color=blue]
            >You really should get a real newsreader and subscribe to
            >new:comp.lang. javascript and stop using a site that portrays
            >itself as a "private forum" when it is anything but that.[/color]

            I think that they have abandoned the pretence that they are a private
            forum, though they have done little to dray attention to the reality and
            are maintaining a number of other deceptions related to that original
            one.

            But they have also stopped fully reporting comp.lang.javas cirpt. So,
            with no guarantee that any response made to someone posting from
            forum4designers .com will even be seen there, and knowing that any reply
            made will be garbled by inappropriate presentation, it is questionable
            whether it is worth anyone's effort to compose a worthwhile response to
            posts originating on that site.
            [color=blue]
            >Its more a joke than anything else.[/color]

            A bad joke.

            Richard.


            Comment

            • Randy Webb

              #7
              Re: Very simple question on Javascript with ASP button

              Richard Cornford wrote:[color=blue]
              > "Randy Webb" <hikksnotathome @aol.com> wrote in message
              > news:WqOdneeSTr ZSLbbdRVn_iw@co mcast.com...
              > <snip>
              >[color=green]
              >><script language="javas cript1.2">
              >>a = 30;
              >>b = 40;
              >>if (a = b){
              >>alert('They are equal')
              >>}
              >>else{
              >>alert('They are not equal')
              >>}
              >></script>
              >>Test the above in Netscape 4.xx, and then any other browser.[/color]
              >
              >
              > It might be best not to do the comparison with IceBrowser as it uses the
              > Rhino javascript engine and the docs for Rhino say it will respect
              > language="javas cript1.2" and use the alternative type-converting rules
              > (though I have never tested that, not using the language attribute
              > myself anymore).[/color]

              Just one more reason *not* to use the language attribute.

              [color=blue]
              > It is a bit unfair to use the text "They are equal" when the test you
              > are performing is an assignment (not comparison), though it adequately
              > illustrates the problem.[/color]

              In Netscape 4.xx with language="javas cript1.2", it does a comparison,
              not an assignment. Since they are not equal, it will alert that they are
              not equal. In modern browsers then it alerts they are equal because it
              can set the assignment, thus its true, so it alerts.

              Perhaps:

              <script language="javas cript1.2">
              a = 30;
              b = 40;
              if (a = b){
              alert('I honor it as an assignment')
              }
              else{
              alert('I honor it as a comparison')
              }
              </script>


              Might have been better alerts.

              <--snip-->
              [color=blue][color=green][color=darkred]
              >>>Posted via http://www.forum4designers.com[/color][/color]
              >
              > <snip>
              >[color=green]
              >>You really should get a real newsreader and subscribe to
              >>new:comp.lang .javascript and stop using a site that portrays
              >>itself as a "private forum" when it is anything but that.[/color]
              >
              >
              > I think that they have abandoned the pretence that they are a private
              > forum, though they have done little to dray attention to the reality and
              > are maintaining a number of other deceptions related to that original
              > one.[/color]

              I am not so sure they have. They censor out the part of the posts that
              we normally quote/complain about. Namely, the generated signature thats
              get posted. When viewing the post on the site, you do not see that
              section of the post. But they showed my signature line (and yours as well).



              Is this very thread, and if you look at the post that I replied to,
              there is no signature on it telling where it was posted from nor the
              link to the thread.

              [color=blue]
              > But they have also stopped fully reporting comp.lang.javas cirpt. So,
              > with no guarantee that any response made to someone posting from
              > forum4designers .com will even be seen there, and knowing that any reply
              > made will be garbled by inappropriate presentation, it is questionable
              > whether it is worth anyone's effort to compose a worthwhile response to
              > posts originating on that site.
              >[/color]

              And miss out on all this fun? You are kidding me, right? <g>

              Actually, they showed this entire thread (so far anyway). Will be
              interesting to see if anything from my post after gets "lost" or not.

              --
              Randy
              Chance Favors The Prepared Mind
              comp.lang.javas cript FAQ - http://jibbering.com/faq/

              Comment

              • Richard Cornford

                #8
                Re: Very simple question on Javascript with ASP button

                "Randy Webb" <hikksnotathome @aol.com> wrote in message
                news:etSdndZRwY U5l7HdRVn-vw@comcast.com. ..
                <snip>[color=blue]
                >In Netscape 4.xx with language="javas cript1.2", it does a comparison,[/color]
                <snip>

                You are right it does. How on earth can it decide when it is supposed to
                be doing comparison and when it is supposed to be doing assignment? I
                use the result of assignment expressions in - if - statements all the
                time. In practice it is not very important if the language attribute is
                not used at all but given how often I see scripts with version 1.2
                language attributes I am surprised we don't see more problems directly
                resulting from them (or could that just be the result of limited
                testing).

                <snip>[color=blue]
                >... . But they showed my signature line (and yours as well).[/color]

                Do they? I don't recall posting with a signature during the period in
                which they have been operating.

                <snip>[color=blue][color=green]
                >>... , it is questionable whether it is worth anyone's effort to
                >>compose a worthwhile response to posts originating on that site.
                >>[/color]
                >
                >And miss out on all this fun? You are kidding me, right? <g>[/color]
                <snip>

                I will copy and paste a pre-written standard response. No effort, no
                waste if it is not reported, potentially as much fun.

                Richard.


                Comment

                • Randy Webb

                  #9
                  Re: Very simple question on Javascript with ASP button

                  Richard Cornford wrote:[color=blue]
                  > "Randy Webb" <hikksnotathome @aol.com> wrote in message
                  > news:etSdndZRwY U5l7HdRVn-vw@comcast.com. ..
                  > <snip>
                  >[color=green]
                  >>In Netscape 4.xx with language="javas cript1.2", it does a comparison,[/color]
                  >
                  > <snip>
                  >
                  > You are right it does. How on earth can it decide when it is supposed to
                  > be doing comparison and when it is supposed to be doing assignment?[/color]

                  Its a bug in the if conditional in javascript1.2 specifically. So it
                  only shows itself when you do if(something=so methingElse) instead of
                  if(something==s omethingElse). I have never tested it in any other
                  conditionals (while and for loops).
                  [color=blue]
                  > I use the result of assignment expressions in - if - statements all the
                  > time. In practice it is not very important if the language attribute is
                  > not used at all but given how often I see scripts with version 1.2
                  > language attributes I am surprised we don't see more problems directly
                  > resulting from them (or could that just be the result of limited
                  > testing).[/color]

                  If its inside an if statement, it will do a comparison. Otherwise, it
                  does as its supposed to do. As far as I know, if (a=b) will always
                  result in true in modern browsers (the exception would be if a was read
                  only).
                  [color=blue]
                  > <snip>
                  >[color=green]
                  >>... . But they showed my signature line (and yours as well).[/color]
                  >
                  >
                  > Do they? I don't recall posting with a signature during the period in
                  > which they have been operating.[/color]

                  I am so used to seeing signatures at the bottom, that I mistook your
                  name for a signature. It shows mine, so its actively censoring what it
                  appends to the posts.
                  [color=blue]
                  > <snip>
                  >[color=green][color=darkred]
                  >>>... , it is questionable whether it is worth anyone's effort to
                  >>>compose a worthwhile response to posts originating on that site.
                  >>>[/color]
                  >>
                  >>And miss out on all this fun? You are kidding me, right? <g>[/color]
                  >
                  > <snip>
                  >
                  > I will copy and paste a pre-written standard response. No effort, no
                  > waste if it is not reported, potentially as much fun.[/color]

                  Post it when you get it written. Maybe we could add a very unique word
                  so that people could filter it out (much like the FAQ gets filtered by
                  some), but based on content instead of subject lines. Or better, a
                  unique phrase "forum4webdesig ner's site ........."


                  --
                  Randy
                  Chance Favors The Prepared Mind
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  • Richard Cornford

                    #10
                    Re: Very simple question on Javascript with ASP button

                    "Randy Webb" <hikksnotathome @aol.com> wrote in message
                    news:8PSdnXvXaq 0TL7Dd4p2dnA@co mcast.com...
                    <snip>[color=blue]
                    >... . As far as I know, if (a=b) will always
                    > result in true in modern browsers ...[/color]
                    <snip>

                    The evaluated result of an assignment expression is the value assigned:-

                    var obj;
                    if(obj = document.getEle mentById("someI D")){
                    ... //only if - obj - is assigned non-null value
                    }

                    - so it can type-convert to both true and false.

                    Richard.


                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: Very simple question on Javascript with ASP button

                      Randy Webb <hikksnotathome @aol.com> writes:

                      [ if (a=b) in JS1.2][color=blue]
                      > Its a bug in the if conditional in javascript1.2 specifically.[/color]

                      I like to think so too, but I guess it was considered a "feature".
                      I.e., it was deliberate. Good thing it was stopped in time!
                      [color=blue]
                      > As far as I know, if (a=b) will always result in true in modern
                      > browsers (the exception would be if a was read only).[/color]

                      .... or if b counts as false.
                      Try
                      var a=42;
                      var b=0;
                      if (a=b) {} else {alert("b false or JS 1.2 in effect");}

                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Randy Webb

                        #12
                        Re: Very simple question on Javascript with ASP button

                        Lasse Reichstein Nielsen wrote:
                        [color=blue]
                        > Randy Webb <hikksnotathome @aol.com> writes:
                        >
                        > [ if (a=b) in JS1.2]
                        >[color=green]
                        >>Its a bug in the if conditional in javascript1.2 specifically.[/color]
                        >
                        >
                        > I like to think so too, but I guess it was considered a "feature".
                        > I.e., it was deliberate. Good thing it was stopped in time![/color]

                        Netscape 4 was enough to drive a teetotaler to drink and an atheist to
                        religion. Yes, its a very good thing it was stopped :)

                        [color=blue][color=green]
                        >>As far as I know, if (a=b) will always result in true in modern
                        >>browsers (the exception would be if a was read only).[/color]
                        >
                        >
                        > .... or if b counts as false.
                        > Try
                        > var a=42;
                        > var b=0;
                        > if (a=b) {} else {alert("b false or JS 1.2 in effect");}[/color]

                        Yikes! Just when I thought I had it figured out, they type convert on
                        me. Sheesh. I think I will just stick to == and be happy :)

                        --
                        Randy
                        Chance Favors The Prepared Mind
                        comp.lang.javas cript FAQ - http://jibbering.com/faq/

                        Comment

                        Working...