add onload to <body id="bodyId" runat="server"> using C#?

Discussion in 'ASP .Net' started by Les Caudle, Nov 19, 2009.

  1. Les Caudle

    Les Caudle Guest

    I've got a Master Page with <body id="bodyId" runat="server">

    From one of the pages that uses the master page, I need to be able to add an
    onload to the body tag.

    I saw one suggestion for

    -------------
    1. Give the <body> tag an id, and make it run as a htmlcontrol

    <body id="myBody" runat="server">

    2. In your code-behind, create a reference to the body object, and attach the
    function you need to the "onload" event.

    Protected WithEvents myBody As
    System.Web.UI.HtmlControls.HtmlContainerControl

    body.Attributes("onload") = "myjavascriptfunction();"
    ----------------------

    Which seems to partially have the right idea, but of course I need C#.

    What's the best way to do this?

    My goal is to add a small javascript routine that when it detects a <blink> tag,
    will flash it on and off at an interval.

    The interval is set in the body tag html for my other sites, but I'm having
    trouble getting it to work for a site that uses Master pages.

    I've tried using
    Page.ClientScript.RegisterClientScriptBlock
    to register the coe that is called, and then
    Page.ClientScript.RegisterStartupScript
    to register the initial call that sets the interval, but so far, it isn't
    working.
    --
    Thanks in advance, Les Caudle
     
    Les Caudle, Nov 19, 2009
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. feng
    Replies:
    1
    Views:
    3,340
    Peter Rilling
    Feb 29, 2004
  2. z. f.
    Replies:
    1
    Views:
    578
    Mikhail Arkhipov \(MSFT\)
    Jun 25, 2004
  3. ~~~ .NET Ed ~~~
    Replies:
    5
    Views:
    1,755
    David Wainwright
    Mar 27, 2007
  4. John Kotuby

    Add body onload attribute from UserControl?

    John Kotuby, Apr 3, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    1,497
    Ben Rush
    Apr 5, 2007
  5. DC

    Add form runat=server tags in Composite Control

    DC, Dec 13, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    327
  6. kw
    Replies:
    7
    Views:
    470
  7. Peter Young

    body onload set server side

    Peter Young, Nov 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    711
    Peter Young
    Nov 14, 2004
  8. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    825
    Martin Honnen
    Nov 4, 2004
Loading...