Question About .NET Controls and Javascript

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

    #1

    Question About .NET Controls and Javascript

    I have a TextBox on a Web form that I'll be accessing from code. However,
    I'd also like execute some Javascript when the control loses focus.

    I'm a little confused since the IDE does not seem to present javascript
    events when a control has the runat="server" specified. I know I can type it
    in but that wouldn't that be specifying my server-side handler rather than
    client script?

    I'm pretty sure I need this to be a server-side control but would like to
    connect some client-side script. Is this even possible?

    Thanks.

    --
    Jonathan Wood
    SoftCircuits Programming


  • Dina

    #2
    Re: Question About .NET Controls and Javascript

    On Jan 10, 9:28 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
    I have a TextBox on a Web form that I'll be accessing from code. However,
    I'd also like execute some Javascript when the control loses focus.
    >
    I'm a little confused since the IDE does not seem to present javascript
    events when a control has the runat="server" specified. I know I can type it
    in but that wouldn't that be specifying my server-side handler rather than
    client script?
    >
    I'm pretty sure I need this to be a server-side control but would like to
    connect some client-side script. Is this even possible?
    >
    Thanks.
    >
    --
    Jonathan Wood
    SoftCircuits Programminghttp ://www.softcircuit s.com
    You 'll have to add a Attributes.Add( "onclick", "javascript:fun ction")
    on the server side to associate a client event handler to a server
    control. {Just check on the syntax coz I've not worked on Web apps 4
    sometime.}

    Hope it helps.
    Regards, Dina

    Comment

    • Moe Sisko

      #3
      Re: Question About .NET Controls and Javascript

      Jonathan,

      "Jonathan Wood" <jwood@softcirc uits.comwrote in message
      news:O7Jf5E0UIH A.5160@TK2MSFTN GP05.phx.gbl...
      I'm pretty sure I need this to be a server-side control but would like to
      connect some client-side script. Is this even possible?
      Yes. This should get you going - "Using JavaScript Along with ASP.NET 2.0"
      http://msdn2.microsoft.com/en-us/library/aa479390.aspx

      HTH,
      Moe


      Comment

      • Eliyahu Goldin

        #4
        Re: Question About .NET Controls and Javascript

        Any attribute that is not recognized on server side will just be emitted to
        the client as it is. So

        <asp:Text ... abc="xyz" /will produce

        <input type="text" abx="xyz" />

        --
        Eliyahu Goldin,
        Software Developer
        Microsoft MVP [ASP.NET]



        "Jonathan Wood" <jwood@softcirc uits.comwrote in message
        news:O7Jf5E0UIH A.5160@TK2MSFTN GP05.phx.gbl...
        I have a TextBox on a Web form that I'll be accessing from code. However,
        I'd also like execute some Javascript when the control loses focus.
        >
        I'm a little confused since the IDE does not seem to present javascript
        events when a control has the runat="server" specified. I know I can type
        it
        in but that wouldn't that be specifying my server-side handler rather than
        client script?
        >
        I'm pretty sure I need this to be a server-side control but would like to
        connect some client-side script. Is this even possible?
        >
        Thanks.
        >
        --
        Jonathan Wood
        SoftCircuits Programming

        >

        Comment

        • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

          #5
          RE: Question About .NET Controls and Javascript

          For lost focus you would do:

          myTextBox.Attri butes.Add("onbl ur", "javascript:myf unction")

          -- Peter
          Site: http://www.eggheadcafe.com
          UnBlog: http://petesbloggerama.blogspot.com
          MetaFinder: http://www.blogmetafinder.com


          "Jonathan Wood" wrote:
          I have a TextBox on a Web form that I'll be accessing from code. However,
          I'd also like execute some Javascript when the control loses focus.
          >
          I'm a little confused since the IDE does not seem to present javascript
          events when a control has the runat="server" specified. I know I can type it
          in but that wouldn't that be specifying my server-side handler rather than
          client script?
          >
          I'm pretty sure I need this to be a server-side control but would like to
          connect some client-side script. Is this even possible?
          >
          Thanks.
          >
          --
          Jonathan Wood
          SoftCircuits Programming

          >
          >

          Comment

          • Jonathan Wood

            #6
            Re: Question About .NET Controls and Javascript

            Yep. Thanks!

            --
            Jonathan Wood
            SoftCircuits Programming


            "Dina" <dina.mrcool@gm ail.comwrote in message
            news:f79ff520-8a63-4a3e-ad33-7cec4191c461@e3 2g2000prn.googl egroups.com...
            On Jan 10, 9:28 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
            >I have a TextBox on a Web form that I'll be accessing from code. However,
            >I'd also like execute some Javascript when the control loses focus.
            >>
            >I'm a little confused since the IDE does not seem to present javascript
            >events when a control has the runat="server" specified. I know I can type
            >it
            >in but that wouldn't that be specifying my server-side handler rather
            >than
            >client script?
            >>
            >I'm pretty sure I need this to be a server-side control but would like to
            >connect some client-side script. Is this even possible?
            >>
            >Thanks.
            >>
            >--
            >Jonathan Wood
            >SoftCircuits Programminghttp ://www.softcircuit s.com
            >
            You 'll have to add a Attributes.Add( "onclick", "javascript:fun ction")
            on the server side to associate a client event handler to a server
            control. {Just check on the syntax coz I've not worked on Web apps 4
            sometime.}
            >
            Hope it helps.
            Regards, Dina

            Comment

            • Jonathan Wood

              #7
              Re: Question About .NET Controls and Javascript

              That article looks like just the thing I needed.

              However, there's one area that I didn't see it address: How to reference
              controls by name. Because if I have a TextBox with ID="txtLbs" it actually
              ends up with a name something like
              "ctl00_ctl00_Co ntentPlaceHolde r1_MainContent_ Wizard1_txtLbs" . I need to
              reference two controls from the javascript. I had to hard code these names
              because they could potentially change. Anyone have any ideas?

              Thanks.

              --
              Jonathan Wood
              SoftCircuits Programming


              "Moe Sisko" <nullwrote in message
              news:uJnDIy0UIH A.4868@TK2MSFTN GP03.phx.gbl...
              Jonathan,
              >
              "Jonathan Wood" <jwood@softcirc uits.comwrote in message
              news:O7Jf5E0UIH A.5160@TK2MSFTN GP05.phx.gbl...
              >I'm pretty sure I need this to be a server-side control but would like to
              >connect some client-side script. Is this even possible?
              >
              Yes. This should get you going - "Using JavaScript Along with ASP.NET
              2.0"
              http://msdn2.microsoft.com/en-us/library/aa479390.aspx
              >
              HTH,
              Moe
              >
              >

              Comment

              • Jonathan Wood

                #8
                Re: Question About .NET Controls and Javascript

                My concern was that it might match one of the ASP.NET control's server-side
                events/attributes. But perhaps most of those have different names.

                --
                Jonathan Wood
                SoftCircuits Programming


                "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgwro te in
                message news:ewni6e1UIH A.3676@TK2MSFTN GP06.phx.gbl...
                Any attribute that is not recognized on server side will just be emitted
                to
                the client as it is. So
                >
                <asp:Text ... abc="xyz" /will produce
                >
                <input type="text" abx="xyz" />
                >
                --
                Eliyahu Goldin,
                Software Developer
                Microsoft MVP [ASP.NET]

                >
                >
                "Jonathan Wood" <jwood@softcirc uits.comwrote in message
                news:O7Jf5E0UIH A.5160@TK2MSFTN GP05.phx.gbl...
                >I have a TextBox on a Web form that I'll be accessing from code. However,
                >I'd also like execute some Javascript when the control loses focus.
                >>
                >I'm a little confused since the IDE does not seem to present javascript
                >events when a control has the runat="server" specified. I know I can type
                it
                >in but that wouldn't that be specifying my server-side handler rather
                >than
                >client script?
                >>
                >I'm pretty sure I need this to be a server-side control but would like to
                >connect some client-side script. Is this even possible?
                >>
                >Thanks.
                >>
                >--
                >Jonathan Wood
                >SoftCircuits Programming
                >http://www.softcircuits.com
                >>
                >
                >

                Comment

                • Jonathan Wood

                  #9
                  Re: Question About .NET Controls and Javascript

                  Heh, I looked at a table of javascript events had didn't relate to onblur
                  being when a control lost focus. That name only makes sense in an odd sort
                  of way. Cool.

                  I also found a good article based on another suggestion. But do you have any
                  ideas how I would reference other controls from javascript, given that the
                  IDs of ASP.NET controls can change substantially by the time the HTML is
                  rendered?

                  Thanks!

                  --
                  Jonathan Wood
                  SoftCircuits Programming


                  "Peter Bromberg [C# MVP]" <pbromberg@yaho o.NoSpamMaam.co mwrote in message
                  news:A85D8A21-C7D9-4704-9D6B-13F17390D527@mi crosoft.com...
                  For lost focus you would do:
                  >
                  myTextBox.Attri butes.Add("onbl ur", "javascript:myf unction")
                  >
                  -- Peter
                  Site: http://www.eggheadcafe.com
                  UnBlog: http://petesbloggerama.blogspot.com
                  MetaFinder: http://www.blogmetafinder.com
                  >
                  >
                  "Jonathan Wood" wrote:
                  >
                  >I have a TextBox on a Web form that I'll be accessing from code. However,
                  >I'd also like execute some Javascript when the control loses focus.
                  >>
                  >I'm a little confused since the IDE does not seem to present javascript
                  >events when a control has the runat="server" specified. I know I can type
                  >it
                  >in but that wouldn't that be specifying my server-side handler rather
                  >than
                  >client script?
                  >>
                  >I'm pretty sure I need this to be a server-side control but would like to
                  >connect some client-side script. Is this even possible?
                  >>
                  >Thanks.
                  >>
                  >--
                  >Jonathan Wood
                  >SoftCircuits Programming
                  >http://www.softcircuits.com
                  >>
                  >>

                  Comment

                  • Jonathan Wood

                    #10
                    Re: Question About .NET Controls and Javascript

                    Looks like I got this working. I used the ClientID property to obtain the
                    final control ID.

                    Thanks!

                    --
                    Jonathan Wood
                    SoftCircuits Programming


                    "Jonathan Wood" <jwood@softcirc uits.comwrote in message
                    news:e2qTMv7UIH A.4092@TK2MSFTN GP06.phx.gbl...
                    That article looks like just the thing I needed.
                    >
                    However, there's one area that I didn't see it address: How to reference
                    controls by name. Because if I have a TextBox with ID="txtLbs" it actually
                    ends up with a name something like
                    "ctl00_ctl00_Co ntentPlaceHolde r1_MainContent_ Wizard1_txtLbs" . I need to
                    reference two controls from the javascript. I had to hard code these names
                    because they could potentially change. Anyone have any ideas?
                    >
                    Thanks.
                    >
                    --
                    Jonathan Wood
                    SoftCircuits Programming

                    >
                    "Moe Sisko" <nullwrote in message
                    news:uJnDIy0UIH A.4868@TK2MSFTN GP03.phx.gbl...
                    >Jonathan,
                    >>
                    >"Jonathan Wood" <jwood@softcirc uits.comwrote in message
                    >news:O7Jf5E0UI HA.5160@TK2MSFT NGP05.phx.gbl.. .
                    >>I'm pretty sure I need this to be a server-side control but would like
                    >>to connect some client-side script. Is this even possible?
                    >>
                    >Yes. This should get you going - "Using JavaScript Along with ASP.NET
                    >2.0"
                    >http://msdn2.microsoft.com/en-us/library/aa479390.aspx
                    >>
                    >HTH,
                    >Moe
                    >>
                    >>
                    >

                    Comment

                    Working...