How can I reference the body element from server side code if the body does not have an id?
ASP.NET Reference Body element server side
Collapse
X
-
Tags: None
-
Why do you want to reference the body element?Originally posted by ShadowLockeHow can I reference the body element from server side code if the body does not have an id?
Put a runat="server" in the <body> element to be able to access it from your server side code....normall y you don't need to access the body element though...
-Frinny -
But if it doesn't have an ID, you still can't access it.Originally posted by FrinavaleWhy do you want to reference the body element?
Put a runat="server" in the <body> element to be able to access it from your server side code....normall y you don't need to access the body element though...
-FrinnyComment
-
Ive created a web control that that needs to add and event listener for onkeydown to the body. What ive done for now is during the control rendering, just wrote the javascript out to the page that will do it from there. But i think it would be a much cleaner solution if i could access the body from the web control.Originally posted by FrinavaleWhy do you want to reference the body element?
Put a runat="server" in the <body> element to be able to access it from your server side code....normall y you don't need to access the body element though...
-FrinnyComment
-
-
I did the same thing and went through the same thought process as you...I originally tried accessing the <body> tag to do this... but I discovered that you don't need to use the <body> tag at all. You just attach an event to the window...Originally posted by ShadowLockeIve created a web control that that needs to add and event listener for onkeydown to the body. What ive done for now is during the control rendering, just wrote the javascript out to the page that will do it from there. But i think it would be a much cleaner solution if i could access the body from the web control.
eg (JavaScript code of course):
[code=javascript]
If(window.attac hEvent){
window.attachEv ent("onload","t heFunctionThatI sCalledDuringOn Load()");
}else
{
window.addEvent Listener("load" ,"theFunctionTh atIsCalledDurin gOnLoad()");
}
[/code]
-FrinnyComment
Comment