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

L

Les Caudle

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top