Last post Sep 09, 2011 01:30 AM by WPHC
Nov 27, 2007 12:38 AM|jpmattis|LINK
I have done searching online for a solution to my problem to no avail and I am hoping someone here might be able to help.
I have a content page inherting from a masterpage. On the content page I want to display a google map.
<body onload="initialize('X Cordinate Here', 'Y Cordinate Here')" onunload="GUnload()">
Both functions need to be called.
The page that is going to render the map is recieving a variable from a QueryString which it then uses to pull the appropriate record on Page_Load from the database which has both the X & Y coordinates.
I have tried using literals and the clientscriptmanagers to execute the script to no avail. What does work is if I completely scrap using the MasterPage altogether and then add a RUNAT and ID attribute to the <BODY> tag and in the codebehind do an attribute.add
to the body tag. I would rather not do that though because then whats the point of using a masterpage? I am guessing that there is an easy way to do this and I am hoping one of you out there has the answer. If you can help, please post away.
I'm using C# with ASP.NET 2.0
Nov 27, 2007 04:58 AM|somnathmali|LINK
1. Add runat=Server to Body tag... this will create Generic Control variable that you can use in codebehind ...
<body runat="server" id="PageBody">
2. run PageBody variable to set the Attributes .. as
PageBody.Attributes.Add( "onload", "alert(1);");
Nov 27, 2007 05:08 AM|jpmattis|LINK
Yeah, I actually talked about doing that with the <body> tag in my orginal post (see above).
However in order to do that, I wouldn't be able to access the generic <body> tag in the MasterPage from the ContentPage.
The only way I would be able to do that would be by not using the MasterPage at all which is what I would rather not do. If anybody on here can tell me of a way to solve my problem while still using a MasterPage it would be much appreciated.
Thanks for the input though Somanthmali.
Nov 27, 2007 05:10 AM|jpmattis|LINK
This has definitely proven to be a challenging problem for myself.
Nov 27, 2007 04:53 PM|jpmattis|LINK
Nov 27, 2007 09:03 PM|jpmattis|LINK
I found the solution to my problem.
Set your masterpage body tag to:
<body id="mBody" runat="server">
Then add this on any page that uses the master and wants to access the body tag:
public void Page_Load(Object sender, EventArgs e)
//Inject onload and unload
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("mBody");
Jun 08, 2009 10:10 PM|dizzy77|LINK
Dec 22, 2009 10:54 PM|Dobly|LINK
This was EXACTLY the problem I was having. I had an hour of pulling my hair out trying to work it out, and then found this page after 30 seconds of searching.. Man I love the internet. :)
Thanks so much for your solution
Sep 09, 2011 01:30 AM|WPHC|LINK
Thank you - this is exactly what was needed! I appreciate you leaving the solution here on the forums!