Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : 76SmLpc9hKEhSkCChQ1Eu1
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Body OnLoad function in con...

Body OnLoad function in content page in ASP.NET

Nishant Rana Profile Picture Nishant Rana 11,322 Microsoft Employee

Hi,

I wanted to certain script to run in the onload of the body for my content page.

To do this we need to do the following

Add an id and runat attribute to the body tag in the MASTER page

<body id=”body” runat=”server”>

And in the Content page’s  page load handler

protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl body = this.Master.FindControl(“body”) as HtmlGenericControl;
body.Attributes.Add(“onLoad”, “alert(‘Hello World’);”);
}

Bye…


Posted in ASP.NET Tagged: ASP.NET

This was originally posted here.

Comments

*This post is locked for comments