For example I need to change the body onload event in html.
In the asp.net file, we simply cast our master page as its class name.
in master page aspx we add the code below.
<body onload="<%=myloadstr %>" >
in master page cs code we add the code below.
we declare it as public to access the variable.
public string myloadstr = "";
And add the code below in your asp.net cs source file.
((myMasterPage)this.Master).myloadstr = "here some javascript for load";
myMasterPage is the name of my masterpage class. We cast our asp.net page its masterpage, with "this.Master".
6 comments:
Gosh, I love your provided options {helpful|interesting|cool} ...all positive? lol
what a great solution such its realy helpfull to me thanks a lot !!
Such a great solution! Clean, simple, and effective, thank you!
Excellent solution, but doesnt work on page without code behind for some reason.
for non code behind pages delare
<%@ MasterType TypeName='MasterPage' VirtualPath="~/MasterPage.master" %>
If you need this to work.
Alternatively if the master page class is delared as unique name.
e.g. public partial class _MasterPage : System.Web.UI.MasterPage
accessibility will be through _MasterPage.variables
ideal fo db connection object...
Post a Comment