Client-side JavaScript code and ASP.NET controls

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

    #1

    Client-side JavaScript code and ASP.NET controls

    Hello,

    Is there any possibility using ASP.NET and Visual Studio.NET to create
    controls that response for simple JavaScript events such as OnClick and
    OnSelect? For example I need to change the color of a table cell when a
    certain button is selected. In this case there is no need to do a round-trip
    to the web server. I need to assign an event handler to the button's OnClick
    event. Does the VS.NET support this kind of events?

    Thanks for any suggestions,
    Leszek Taratuta


  • Chris Jackson

    #2
    Re: Client-side JavaScript code and ASP.NET controls

    It's the same with ASP.NET as it is with standard HTML - just add the
    onclick property to the markup of an input type=button. If you are using an
    asp:button (and I'm not sure why you would be, if you don't want the server
    to handle it, what is the point) then it actually does add an onclick
    attribute already, so this can lead to conflicts that some people have seen.
    If you need to dynamically insert script, just set runat=server and then use
    button.Attribut es.Add to attach a script (or set any other attribute, for
    that matter).

    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows XP
    Windows XP Associate Expert
    --
    "Leszek" <taratuta@5thbu siness.com> wrote in message
    news:eLgGG%23nZ DHA.2572@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > Hello,
    >
    > Is there any possibility using ASP.NET and Visual Studio.NET to create
    > controls that response for simple JavaScript events such as OnClick and
    > OnSelect? For example I need to change the color of a table cell when a
    > certain button is selected. In this case there is no need to do a[/color]
    round-trip[color=blue]
    > to the web server. I need to assign an event handler to the button's[/color]
    OnClick[color=blue]
    > event. Does the VS.NET support this kind of events?
    >
    > Thanks for any suggestions,
    > Leszek Taratuta
    >
    >[/color]


    Comment

    • Leszek

      #3
      Re: Client-side JavaScript code and ASP.NET controls

      Thanks for your reply!
      Do you know where I can find a sample code to create such a control?

      Leszek Taratuta

      "Steve C. Orr, MCSD" <Steve@Orr.ne t> wrote in message
      news:uaKQjpoZDH A.2632@TK2MSFTN GP09.phx.gbl...[color=blue]
      > I created such a control by inheriting from the standard ImageButton[/color]
      control[color=blue]
      > and using Attributes.Add to output the necessary javascript events.
      >
      > --
      > I hope this helps,
      > Steve C. Orr, MCSD
      > http://Steve.Orr.net
      > --------------------------------
      > Hire top notch developers to get your projects done right:
      > http://www.able-consulting.com
      > --------------------------------
      >
      >
      > "Leszek" <taratuta@5thbu siness.com> wrote in message
      > news:%2310vXnoZ DHA.2932@tk2msf tngp13.phx.gbl. ..[color=green]
      > > Thanks a lot!
      > >
      > > Can I use the functions to ease creation of roll-over buttons? Does[/color][/color]
      VS.NET[color=blue][color=green]
      > > support such a feature or do I need to create all JavaScript event[/color]
      > handlers[color=green]
      > > manually?
      > >
      > > Thanks,
      > > Leszek Taratuta
      > >
      > > "Steve C. Orr, MCSD" <Steve@Orr.ne t> wrote in message
      > > news:#0CQtNoZDH A.2020@TK2MSFTN GP10.phx.gbl...[color=darkred]
      > > > You can output any javascript dynamically from your code behind using[/color][/color]
      > such[color=green][color=darkred]
      > > > function as:
      > > >
      > > > RegisterStartup Script:
      > > >[/color]
      > >[/color]
      >[/color]
      http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue][color=green]
      > > frlrfSystemWebU IPageClassRegis terStartupScrip tTopic.asp[color=darkred]
      > > >
      > > > RegisterClientS criptBlock:
      > > >[/color]
      > >[/color]
      >[/color]
      http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue][color=green]
      > > frlrfSystemWebU IPageClassRegis terClientScript BlockTopic.asp[color=darkred]
      > > >
      > > > Attributes.Add:
      > > >[/color][/color]
      > http://www.flws.com.au/showusyourcod...To.asp?catID=5[color=green][color=darkred]
      > > >
      > > > --
      > > > I hope this helps,
      > > > Steve C. Orr, MCSD
      > > > http://Steve.Orr.net
      > > > --------------------------------
      > > > Hire top notch developers to get your projects done right:
      > > > http://www.able-consulting.com
      > > > --------------------------------
      > > >
      > > >
      > > > "Leszek" <taratuta@5thbu siness.com> wrote in message
      > > > news:eLgGG%23nZ DHA.2572@TK2MSF TNGP09.phx.gbl. ..
      > > > > Hello,
      > > > >
      > > > > Is there any possibility using ASP.NET and Visual Studio.NET to[/color][/color][/color]
      create[color=blue][color=green][color=darkred]
      > > > > controls that response for simple JavaScript events such as OnClick[/color][/color]
      > and[color=green][color=darkred]
      > > > > OnSelect? For example I need to change the color of a table cell[/color][/color][/color]
      when[color=blue]
      > a[color=green][color=darkred]
      > > > > certain button is selected. In this case there is no need to do a
      > > > round-trip
      > > > > to the web server. I need to assign an event handler to the button's
      > > > OnClick
      > > > > event. Does the VS.NET support this kind of events?
      > > > >
      > > > > Thanks for any suggestions,
      > > > > Leszek Taratuta
      > > > >
      > > > >
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Jacob Yang [MSFT]

        #4
        Re: Client-side JavaScript code and ASP.NET controls

        Hi Leszek,

        Based on my research, there is not an existed sample code in Microsoft Web
        Site. If you need sample code, I suggest you try Microsoft Advisory
        Service option. More detailed information regarding Microsoft Advisory
        Service can be found at the following link:

        http://support.microsoft.com/common/...fh;en-us;advis
        oryservice

        Best regards,

        Jacob Yang
        Microsoft Online Partner Support
        <MCSD>
        Get Secure! ¨C www.microsoft.com/security
        This posting is provided "as is" with no warranties and confers no rights.

        Comment

        • Leszek

          #5
          Re: Client-side JavaScript code and ASP.NET controls

          Thanks for your reply.
          I'll try to find such a control somewhere else, and then try the Microsoft
          Advisory Service.

          Thanks,
          Leszek Taratuta

          "Jacob Yang [MSFT]" <jiany@online.m icrosoft.com> wrote in message
          news:OazO$ZvZDH A.2116@cpmsftng xa06.phx.gbl...[color=blue]
          > Hi Leszek,
          >
          > Based on my research, there is not an existed sample code in Microsoft Web
          > Site. If you need sample code, I suggest you try Microsoft Advisory
          > Service option. More detailed information regarding Microsoft Advisory
          > Service can be found at the following link:
          >
          >[/color]
          http://support.microsoft.com/common/...fh;en-us;advis[color=blue]
          > oryservice
          >
          > Best regards,
          >
          > Jacob Yang
          > Microsoft Online Partner Support
          > <MCSD>
          > Get Secure! ¨C www.microsoft.com/security
          > This posting is provided "as is" with no warranties and confers no rights.
          >[/color]


          Comment

          Working...