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. Advertising

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,160
    Peter Rilling
    Feb 29, 2004
  2. ~~~ .NET Ed ~~~
    Replies:
    5
    Views:
    1,342
    David Wainwright
    Mar 27, 2007
  3. John Kotuby

    Add body onload attribute from UserControl?

    John Kotuby, Apr 3, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    1,286
    Ben Rush
    Apr 5, 2007
  4. kw
    Replies:
    7
    Views:
    289
  5. David Otton

    window.onload and body.onload differences

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

Share This Page