Thursday, September 15, 2011
Body onload function in content page in asp.net
Do you like this story?
Body onload function in content page in asp.net
While working on one of the application, I had a master page & on one of the content page's body onload, I had to run a JS function.
To do this first you need to add an ID & runat attribute to the master page's body control. Like this:
In master page:
--code <body id="body" runat="server"> </body>
Now in content page, in the page load event, add this code:
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl body = this.Master.FindControl("body") as HtmlGenericControl;
body.Attributes.Add("onLoad", "alert('Hello World');");
}
I hope this simple tip will be helpful...
While working on one of the application, I had a master page & on one of the content page's body onload, I had to run a JS function.
To do this first you need to add an ID & runat attribute to the master page's body control. Like this:
In master page:
--code <body id="body" runat="server"> </body>
Now in content page, in the page load event, add this code:
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl body = this.Master.FindControl("body") as HtmlGenericControl;
body.Attributes.Add("onLoad", "alert('Hello World');");
}
I hope this simple tip will be helpful...
This post was written by: Fenil Desai
Fenil Desai is a professional blogger, ASP.NET Developer and a cricketer. Follow him on Twitter