473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
1 1945
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gregtyndall | last post by:
I have a weird problem. I'm using a master page to hold a menu that I want to scroll as the user scrolls in the browser window so it will always be visible. First off, putting onsroll in the body...
6
by: Naveen K Kohli | last post by:
I have couple of javascript files that need to be referenced for each content page. So I am trying to put them on Master page. The problem is that content pages are not on one level of the site. I...
9
by: Andy | last post by:
Hey all, I'm building out my first project using asp.net v2.0 master pages. It seems that when you use master pages and try to reference document.body.scrollTop it allways = zero/0. The same code...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
17
by: MeerkatInFrance | last post by:
There comes a time when you know you are not going to be able to work something out yourself, however hard you try. I have reached that moment. I have a master page and a slave page (or whatever...
0
by: bluegrasslover | last post by:
I've gotten a couple of emails about this problem lately so I'm going to post the solution that someone emailed me a while back. When you create a master page visual studio automatically adds a...
7
by: TheLongshot | last post by:
I just recently converted a few pages of my application to using master pages. Problem is, in all of my content pages, the contents are centered. I can't figure out why. The markup in the...
3
by: JJ | last post by:
I am trying to convert applications built with .net framework 1.1 to use master pages. On a couple of aspx pages, I call certain javascript functions <body onresize="blah()"....> However, now...
1
by: sudip2008 | last post by:
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm This breaks this line from working properly window.opener.document.forms...... How can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.