467,877 Members | 1,234 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Master Pages, Javascript, and Body tag

PCK
My goal is to populate the body element so that I can add an onkeydown event.

<body onkeydown='x();'></body>

I am currently using master/content pages. I do not want this function on
every page using my master page. I want to be able to decide what pages get
this function on a page by page basis. Because of this I cannot just add the
text to the html side of the master page as it would cause unwanted results
on the pages where I do not want this function to fire. I do not care how
this is implemented as long as it works. It could be from the content page
calling a function in the master page or the individual content pages each
running the 1 or 2 lines of code to make this work. I just cannot get
anything to work.

Does anyone have any ideas? I have not been able to find anything.

Thanks is advance.

PCK
Sep 28 '06 #1
  • viewed: 1805
Share:
1 Reply
In the master page where your body tag sits, make the body a control by
giving the runat="server" attribute and a name.

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

In the Page_Load event of the container page

HtmlGenericControl mybody = (HtmlGenericControl)
Page.Master.FindControl("BodyTag");
mybody.Attributes.Add("onkeydown", "alert('hello world')");
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
"PCK" <PC*@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.com...
My goal is to populate the body element so that I can add an onkeydown
event.

<body onkeydown='x();'></body>

I am currently using master/content pages. I do not want this function on
every page using my master page. I want to be able to decide what pages
get
this function on a page by page basis. Because of this I cannot just add
the
text to the html side of the master page as it would cause unwanted
results
on the pages where I do not want this function to fire. I do not care how
this is implemented as long as it works. It could be from the content
page
calling a function in the master page or the individual content pages each
running the 1 or 2 lines of code to make this work. I just cannot get
anything to work.

Does anyone have any ideas? I have not been able to find anything.

Thanks is advance.

PCK

Sep 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Naveen K Kohli | last post: by
9 posts views Thread by Andy | last post: by
17 posts views Thread by Rob R. Ainscough | last post: by
17 posts views Thread by MeerkatInFrance | last post: by
7 posts views Thread by TheLongshot | last post: by
3 posts views Thread by JJ | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.