Problems with javascript event lauch from VB.net control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phfle1
    New Member
    • Oct 2007
    • 27

    #1

    Problems with javascript event lauch from VB.net control

    Hi,

    I want to display the cursor as an hourglass on the click of a button in the form and use the following line to achieve that

    Me.btnRecherche .Attributes.Add ("onclick", "document.body. style.cursor = 'wait'; ")

    Sadly, it doesn't work. One strange thing is that when I write the following:

    Me.btnRecherche .Attributes.Add ("onclick", "document.body. style.cursor = 'wait'; alert(""ASASSAS "");")

    I do get the alert, but the cursor doesn't change.

    Is there something wrong with the line document.body.s tyle.cursor = 'wait'; ?

    Thanks,

    P
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by phfle1
    Hi,

    I want to display the cursor as an hourglass on the click of a button in the form and use the following line to achieve that

    Me.btnRecherche .Attributes.Add ("onclick", "document.body. style.cursor = 'wait'; ")

    Sadly, it doesn't work. One strange thing is that when I write the following:

    Me.btnRecherche .Attributes.Add ("onclick", "document.body. style.cursor = 'wait'; alert(""ASASSAS "");")

    I do get the alert, but the cursor doesn't change.

    Is there something wrong with the line document.body.s tyle.cursor = 'wait'; ?

    Thanks,

    P

    Hmm interesting...

    Try:

    Me.btnRecherche .Attributes.Add ("OnClick", "javascript:doc ument.body.styl e.cursor = 'wait'; ")

    This worked when I tested it in IE.

    Comment

    • phfle1
      New Member
      • Oct 2007
      • 27

      #3
      Thanks, but same result.

      If it can help you help me:

      I'm using VS2005
      It is a WEB asp .net application/form

      I used the same line in VS2003 with a similar project and it worked just fine :S

      Thanks,

      P

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by phfle1
        Thanks, but same result.

        If it can help you help me:

        I'm using VS2005
        It is a WEB asp .net application/form

        I used the same line in VS2003 with a similar project and it worked just fine :S

        Thanks,

        P
        I was using VS2005 as well.
        This is not a Server Side problem and doesn't really have anything to do with VS. It's a Client Side problem.

        This could mean that you have JavaScript turned off...or could mean that your browser doesn't support this....

        Maybe your page posts back before you really get a good look at the cursor?

        Comment

        • phfle1
          New Member
          • Oct 2007
          • 27

          #5
          Javascript is enabled and this code works in my browser (IE 6). I have tried it with a simple html page calling the javascript function.

          Originally posted by Frinavale
          Maybe your page posts back before you really get a good look at the cursor?
          Yeah I thought about that so I put an alert before and after the call :

          Me.btnRecherche .Attributes.Add ("onclick", "alert(""ASASSA S"");javascript :document.body. style.cursor = 'wait'; alert(""ASASSAS "");")

          Both alert are launched, but I don't see the hourglass between them.
          Maybe, as you say, it happens to fast, but it doesn't seem to be the case since when there is no alert I still have to wait to seconds to have post back and see the result.

          Strange...

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by phfle1
            Javascript is enabled and this code works in my browser (IE 6). I have tried it with a simple html page calling the javascript function.



            Yeah I thought about that so I put an alert before and after the call :

            Me.btnRecherche .Attributes.Add ("onclick", "alert(""ASASSA S"");javascript :document.body. style.cursor = 'wait'; alert(""ASASSAS "");")

            Both alert are launched, but I don't see the hourglass between them.
            Maybe, as you say, it happens to fast, but it doesn't seem to be the case since when there is no alert I still have to wait to seconds to have post back and see the result.

            Strange...
            Ok try this:
            Me.btnRecherche .Attributes.Add ("OnClick", "javascript:doc ument.body.styl e.cursor = 'wait'; return false;")

            This should prevent the postback to the server from ever happening....

            Comment

            • phfle1
              New Member
              • Oct 2007
              • 27

              #7
              It seems there's nothing that displays when I try this. As you said there is no post back so no answer :S.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by phfle1
                It seems there's nothing that displays when I try this. As you said there is no post back so no answer :S.

                I'm going to ask the JavaScript experts to have a look at this question.
                :)
                We'll get to the bottom of this!

                -Frinny

                Comment

                • phfle1
                  New Member
                  • Oct 2007
                  • 27

                  #9
                  thanks, really appreciated

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    [CODE=javascript]document.body.s tyle.cursor="wa it";[/CODE] should set the cursor to an hourglass. I'm not too familiar with .NET, so how does this code turn out in the browser (view source in the browser).

                    Comment

                    • phfle1
                      New Member
                      • Oct 2007
                      • 27

                      #11
                      Originally posted by acoder
                      [CODE=javascript]document.body.s tyle.cursor="wa it";[/CODE] should set the cursor to an hourglass. I'm not too familiar with .NET, so how does this code turn out in the browser (view source in the browser).
                      thanks, but that's what I used and didn't get any good result. I'll try to see the source.

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        Originally posted by acoder
                        [CODE=javascript]document.body.s tyle.cursor="wa it";[/CODE] should set the cursor to an hourglass. I'm not too familiar with .NET, so how does this code turn out in the browser (view source in the browser).
                        Does this work in all browsers?

                        Comment

                        • drhowarddrfine
                          Recognized Expert Expert
                          • Sep 2006
                          • 7434

                          #13
                          You are setting the style on <body>, correct? Then you must be within <body> for the 'wait' cursor to appear. Many times the full width/height of the body is covered with other elements. To test for this, move the style to some element like a <div> or <p> and see if it appears.

                          Comment

                          • phfle1
                            New Member
                            • Oct 2007
                            • 27

                            #14
                            Originally posted by drhowarddrfine
                            You are setting the style on <body>, correct? Then you must be within <body> for the 'wait' cursor to appear. Many times the full width/height of the body is covered with other elements. To test for this, move the style to some element like a <div> or <p> and see if it appears.
                            The call is made via a vb.net file that adds the event to a button(control) . I do not change anything in the asp .net file

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Originally posted by phfle1
                              The call is made via a vb.net file that adds the event to a button(control) . I do not change anything in the asp .net file

                              Drhowarddrfine is suggesting that you move the button into a panel with a set Height and Width.

                              A panel is rendered as a <div> tag when it is sent to the web browser (to verify this right click on the web page and selected "view source").

                              Once you've done this try the following:


                              Me.btnRecherche .Attributes.Add ("onclick", "document.getEl ementById('" +PNL_ThePanelYo urButtonIsIn.Cl ientID+"').styl e.cursor = 'wait';")

                              When testing this, make sure that your mouse is hovering over the panel that your button is in. To know where it is, I suggest setting the background colour of the panel to something like "Blue" so that you can see it.

                              Comment

                              Working...