473,396 Members | 2,147 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,396 software developers and data experts.

Reference body tag from code-behind?

In VS 2003, I am trying to set the onload property of the body tag to "". I
do this all the time from my Dreamweaver pages (one page aspx page). But in
a code-behind page I need to set a reference. How do I reference the <body>
tag?

I have the <bodyset as:

<body id="myBody" onload="document.forms[0].Textbox3.focus()">

I change this as:

myBody.Attributes.Add("onLoad","");

I get the error:

The type or namespace name 'myBody' could not be found (are you missing
a using directive or an assembly reference?)

I realize that I need to add a reference and tried to do:

protected System.Web.UI.HtmlControls.Body myBody;

I get the error:

The type or namespace name 'Body' does not exist in the class or
namespace 'System.Web.UI.HtmlControls' (are you missing an assembly
reference?)

What would the reference be?

Thanks,

Tom
Oct 19 '06 #1
8 3873
"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">
Oct 19 '06 #2
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
>What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">
You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom
Oct 19 '06 #3
tshad wrote:
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">

You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom
Dear Tom

I don't think it's possible because, as the error message points out,
there isn't a class in System.Web.UI.HtmlControls representing it.

In other words Microsoft have not provided any mechanism to access the
<body.. </bodyelement of the web page programmatically.

To be honest I don't see why this should be necessary. You probably
need to think about the approach you are taking in your solution. There
must be an easier and more direct way of carrying out the task using
normal web server controls.

Phil H

Oct 19 '06 #4
Also try an HtmlGenericControl. There is no html control specific to the
body tag...

--
Patrice

"tshad" <ts**********@ftsolutions.coma écrit dans le message de news:
ul**************@TK2MSFTNGP03.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
>"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
>>What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">

You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom

Oct 19 '06 #5
take this out of the body tag:

onload="document.forms[0].Textbox3.focus()"

assign onload event programmatically as needed
"tshad" <ts**********@ftsolutions.comwrote in message news:ul**************@TK2MSFTNGP03.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:ec**************@TK2MSFTNGP05.phx.gbl...
>"tshad" <ts**********@ftsolutions.comwrote in message news:ug**************@TK2MSFTNGP04.phx.gbl...
>>What would the reference be?

Ahem...

<body id="myBody" runat="server" onload="document.forms[0].Textbox3.focus()">

You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom

Oct 19 '06 #6
"Phil H" <go****@philphall.me.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
In other words Microsoft have not provided any mechanism to access the
<body.. </bodyelement of the web page programmatically.
Apart from the HtmlGenericControl object, of course... :-)
Oct 19 '06 #7
The declaration for the reference should be:

protected System.Web.UI.HtmlControls.HtmlGenericControl myBody;

If you declare it with any other class, it will not be recognised as the
same object, and you will just get a reference that is not attached to
anything.

tshad wrote:
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
>"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
>>What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">

You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom

Oct 19 '06 #8
"Phil H" <go****@philphall.me.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
tshad wrote:
>"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...

What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="document.forms[0].Textbox3.focus()">

You're right.

I missed the runat attribute. Fixed that.

But that doesn't help the reference problem. I still get the error.

Thanks,

Tom

Dear Tom

I don't think it's possible because, as the error message points out,
there isn't a class in System.Web.UI.HtmlControls representing it.

In other words Microsoft have not provided any mechanism to access the
<body.. </bodyelement of the web page programmatically.

To be honest I don't see why this should be necessary. You probably
need to think about the approach you are taking in your solution. There
must be an easier and more direct way of carrying out the task using
normal web server controls.
It is necessy as I am using the body tag to put focus on a textbox when the
page loads. But I need to change the onLoad event to either disable it or
jump to another control as I am hiding the control on the screen after the
initial Page_load.

As I mentioned, this is no problem in a single page design. But if there is
no way to do this using code-behind then this is just another reason why I
am glad I normally build my pages using DW instead of VS.

Thanks,

Tom
>
Phil H

Oct 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. ...
10
by: Tony Johansson | last post by:
Hello Experts!! This class template and main works perfectly fine. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter in...
2
by: Ben | last post by:
I have several pages written in aspx, but sometime the aspx page return the following error. And it hapeen, the whole web application gives this error, that means all the aspx files get affected....
0
by: Kaimar Seljamäe | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
1
by: Michel Couche | last post by:
Hello, I am starting the development of a newsletter The use of the class MailMessage of System.Net.Mail is quite straightforward for usual contact forms but my question here is "How can I...
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.