Link to home
Start Free TrialLog in
Avatar of WingYip
WingYip

asked on

ASP.Net body onload event with master pages

Hi

Am using asp.net 3.5 with master pages.

I need to run some javascript to preload some images in the body onload event but I don't need to run this on every page.

The only body tag is in the master page (mp.master) for the site so currently the event runs for all content pages that whose masterpagefile is mp.master.

How can I run js code in the onload event of some pages only.

Can anyone help?

Wing
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

you can set runat="server" in the body tag into the maseter page... an set the onload event by each page...

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

and for each page where you want to set the body onload event...

Master.FindControl("bodyMaster").Attributes.Add("onload", "someJavavScript");
Avatar of WingYip
WingYip

ASKER

Have just picked this up again.
I am trying this but no joy as yet.  For a start, attributes is not a member of the control class so it doesn't compile.  The following compiles but doesnt find the body element.  

Dim cBody As HtmlGenericControl = Me.Page.Master.FindControl("bodyRpMaster")
        cBody.Attributes.Add("onload", "some_jscript")

have set the body in the master to "runat=server" and id to "bodyRpMaster"

I have put all this in the page load event.

Am wondering what to do next
ASKER CERTIFIED SOLUTION
Avatar of WingYip
WingYip

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial