Master pages with a onload command.

M

Mufasa

I have a master page with stuff in it. It includes the body tag and then the
asp:content tag. I want to hide some text when the page is loaded but is
made visible by a check box. All that code works fine. I have the text in a
<div> that I hide/unhide when a checkbox is clicked and it's all done at the
client level.

Problem is, to hide the text I need to call a javascript function on load.
The only place it seems to work is in the <body> command. But if I do that,
I get a warning about having a <body> command within a <div> command (the
div is part of my master page.)

Anyway around this? I would like to leave the stuff at the client side so it
responds immediately without a postback to the server.

TIA - Jeff.
 
R

Random

Take a look at the RegisterStartupScript method. Use that or declaratively
add your javascript call to the onload event with "window.onload = {name of
function, no parentheses}" Then it doesn't matter where your <body> tag is.
 
M

Mufasa

How do I set the attribute on the body tag?

Do I put a runat="server" and then add the attributes in the Page_Load
routine?

J.

Eliyahu Goldin said:
Move the <body> to the master page outside the div. You can always set up
the <body>'s attributes from the content page. Is it what you are after?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Mufasa said:
I have a master page with stuff in it. It includes the body tag and then
the asp:content tag. I want to hide some text when the page is loaded but
is made visible by a check box. All that code works fine. I have the text
in a <div> that I hide/unhide when a checkbox is clicked and it's all done
at the client level.

Problem is, to hide the text I need to call a javascript function on
load. The only place it seems to work is in the <body> command. But if I
do that, I get a warning about having a <body> command within a <div>
command (the div is part of my master page.)

Anyway around this? I would like to leave the stuff at the client side so
it responds immediately without a postback to the server.

TIA - Jeff.
 
E

Eliyahu Goldin

Yes, add runat="server". Also, give the body tag a unique id and then you
can refer it in the code-behind as
HtmlGenericControl myBodyTag.

And yes, you can add attributes in the Page_Load.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Mufasa said:
How do I set the attribute on the body tag?

Do I put a runat="server" and then add the attributes in the Page_Load
routine?

J.

Eliyahu Goldin said:
Move the <body> to the master page outside the div. You can always set up
the <body>'s attributes from the content page. Is it what you are after?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Mufasa said:
I have a master page with stuff in it. It includes the body tag and then
the asp:content tag. I want to hide some text when the page is loaded but
is made visible by a check box. All that code works fine. I have the text
in a <div> that I hide/unhide when a checkbox is clicked and it's all
done at the client level.

Problem is, to hide the text I need to call a javascript function on
load. The only place it seems to work is in the <body> command. But if I
do that, I get a warning about having a <body> command within a <div>
command (the div is part of my master page.)

Anyway around this? I would like to leave the stuff at the client side
so it responds immediately without a postback to the server.

TIA - Jeff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top