473,666 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="documen t.forms[0].Textbox3.focus ()">

I change this as:

myBody.Attribut es.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.H tmlControls.Bod y 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 3883
"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******** ******@TK2MSFTN GP04.phx.gbl...
What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="documen t.forms[0].Textbox3.focus ()">
Oct 19 '06 #2
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:ec******** ******@TK2MSFTN GP05.phx.gbl...
"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******** ******@TK2MSFTN GP04.phx.gbl...
>What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="documen t.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**@markNOSPA Mrae.comwrote in message
news:ec******** ******@TK2MSFTN GP05.phx.gbl...
"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******** ******@TK2MSFTN GP04.phx.gbl...
What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="documen t.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.H tmlControls representing it.

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

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 HtmlGenericCont rol. There is no html control specific to the
body tag...

--
Patrice

"tshad" <ts**********@f tsolutions.coma écrit dans le message de news:
ul************* *@TK2MSFTNGP03. phx.gbl...
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:ec******** ******@TK2MSFTN GP05.phx.gbl...
>"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******* *******@TK2MSFT NGP04.phx.gbl.. .
>>What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="docume nt.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="documen t.forms[0].Textbox3.focus ()"

assign onload event programmaticall y as needed
"tshad" <ts**********@f tsolutions.comw rote in message news:ul******** ******@TK2MSFTN GP03.phx.gbl...
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message news:ec******** ******@TK2MSFTN GP05.phx.gbl...
>"tshad" <ts**********@f tsolutions.comw rote in message news:ug******** ******@TK2MSFTN GP04.phx.gbl...
>>What would the reference be?

Ahem...

<body id="myBody" runat="server" onload="documen t.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****@philpha ll.me.ukwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
In other words Microsoft have not provided any mechanism to access the
<body.. </bodyelement of the web page programmaticall y.
Apart from the HtmlGenericCont rol object, of course... :-)
Oct 19 '06 #7
The declaration for the reference should be:

protected System.Web.UI.H tmlControls.Htm lGenericControl 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**@markNOSPA Mrae.comwrote in message
news:ec******** ******@TK2MSFTN GP05.phx.gbl...
>"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******* *******@TK2MSFT NGP04.phx.gbl.. .
>>What would the reference be?
Ahem...

<body id="myBody" runat="server"
onload="docume nt.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****@philpha ll.me.ukwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
tshad wrote:
>"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:ec******* *******@TK2MSFT NGP05.phx.gbl.. .
"tshad" <ts**********@f tsolutions.comw rote in message
news:ug******** ******@TK2MSFTN GP04.phx.gbl...

What would the reference be?

Ahem...

<body id="myBody" runat="server"
onload="documen t.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.H tmlControls representing it.

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

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
1745
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. In its member function, an object manages to destroy last reference to itself and thus destructs before the end of the member function.
10
2262
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 the class template so I know how many references I have to the body. In my case it's the Integer wrapper class which is the body. This template works for many different types. The one that I use is named Integer and is a Wrapper for an int. The...
2
500
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. Any ideas? Here is the error: Server Error in '/' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred...
0
1936
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 create SOAP client like this: public class StockService : SoapHttpClientProtocol {
1
4666
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 reference a CSS file in the header of my newsletter message ?" Here is where I am .... (1) I found a way to reference a web page in the body of the message (ref: http://www.systemwebmail.com/faq/3.2.aspx) Dim mail As New MailMessage()
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.