473,545 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing Body attribute

Is there a way during Page_Load to change or add an attribute to the Body
tag?

I want to be able to change the onLoad body attribute to do a focus on one
of my text boxes, such as:

onLoad="documen t.forms[0].txtLogon.focus ();"

The problem is I have my <body> in an include file and want to set the
onLoad attribute during Page_Load time.

Thanks,

Tom.
Nov 19 '05 #1
6 2036
just use javascript:

<script>documen t.body.onload = function()
{document.forms[0].txtLogon.focus ();};</script>

-- bruce (sqlwork.com)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uN******** ******@TK2MSFTN GP14.phx.gbl...
| Is there a way during Page_Load to change or add an attribute to the Body
| tag?
|
| I want to be able to change the onLoad body attribute to do a focus on one
| of my text boxes, such as:
|
| onLoad="documen t.forms[0].txtLogon.focus ();"
|
| The problem is I have my <body> in an include file and want to set the
| onLoad attribute during Page_Load time.
|
| Thanks,
|
| Tom.
|
|
Nov 19 '05 #2
There are ways, but why not just use Page.RegisterSt artupScript?

Dim str As New System.Text.Str ingBuilder
str.Append("<sc ript language=""Java Script"">")
str.Append(Syst em.Environment. NewLine)
str.Append("doc ument.forms[0].txtLogon.focus ();")
str.Append(Syst em.Environment. NewLine)
str.Append("</script>")
Page.RegisterSt artupScript("Se tFocus", str.ToString())

Nice function to have in a utility class...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uN******** ******@TK2MSFTN GP14.phx.gbl...
Is there a way during Page_Load to change or add an attribute to the Body
tag?

I want to be able to change the onLoad body attribute to do a focus on one
of my text boxes, such as:

onLoad="documen t.forms[0].txtLogon.focus ();"

The problem is I have my <body> in an include file and want to set the
onLoad attribute during Page_Load time.

Thanks,

Tom.

Nov 19 '05 #3
"bruce barker" <no***********@ safeco.com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
just use javascript:

<script>documen t.body.onload = function()
{document.forms[0].txtLogon.focus ();};</script>
I tried that in a small html file to test it and it doesn't seem to work (at
least not the way I did it).

*************** *************** *************** *************** ****
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="javas cript">
document.body.o nload = function(){docu ment.forms[0].txtEmail.focus ();};
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitl ed Document</title>
</head>
Email message: <input name="txtEmail" type="text" size="32" id="txtEmail" />

<body>
</body>
</html>
*************** *************** *************** *************** *****

Am I missing something?

Thanks,

Tom.

-- bruce (sqlwork.com)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uN******** ******@TK2MSFTN GP14.phx.gbl...
| Is there a way during Page_Load to change or add an attribute to the
Body
| tag?
|
| I want to be able to change the onLoad body attribute to do a focus on
one
| of my text boxes, such as:
|
| onLoad="documen t.forms[0].txtLogon.focus ();"
|
| The problem is I have my <body> in an include file and want to set the
| onLoad attribute during Page_Load time.
|
| Thanks,
|
| Tom.
|
|

Nov 19 '05 #4
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uw******** *****@TK2MSFTNG P12.phx.gbl...
There are ways, but why not just use Page.RegisterSt artupScript?

Dim str As New System.Text.Str ingBuilder
str.Append("<sc ript language=""Java Script"">")
str.Append(Syst em.Environment. NewLine)
str.Append("doc ument.forms[0].txtLogon.focus ();")
str.Append(Syst em.Environment. NewLine)
str.Append("</script>")
Page.RegisterSt artupScript("Se tFocus", str.ToString())
That is a great idea. I didn't know this existed. I started looking into
how this works and tried to create a small page that really does nothing,
but I wanted to look at how the RegisterStartup Script works. I am running
into the same error I have had before whenever I try to put a tag into a
string. I usually get an error.

Here is the page I am using:

*************** *************** *************** *************** *************** ******
<%@ Page Language="VB" trace="false" debug="true" AutoEventWireup ="true"
ContentType="te xt/html" ResponseEncodin g="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Import Namespace="Syst em.Web.Mail" %>
<html>
<script runat="server">
sub sendEmail_click ( sender as Object, e as EventArgs )
Call setFocus(txtLog on)
End Sub

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javas cript'>" & _
"document.getEl ementById('" + ctrl.ClientID & "').focus() ;</script>"

' Add the JavaScript code to the page.
Page.RegisterSt artupScript("Fo cusScript", focusScript)
End Sub

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Home Page</title>
<link href="staffing. css" rel="stylesheet " type="text/css">
</head>
<body>
<form id="Form1" runat="server">
<center>
<br>
<table width="500" border="0" cellspacing="0" cellpadding="2" >
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="114" colspan=2><span class="style1"> Simply enter your email
address below and we'll email you your password. </span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">E mail Address: </td>
<td><asp:textbo x id="txtLogon" runat="server" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value=" Send "
onClick="sendEm ail_click">&nbs p;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
</center>
</form>
</body>
</html>
*************** *************** *************** *************** *************** ****

I get the following error:
*************** *************** *************** *************** *******
Compiler Error Message: BC30648: String constants must end with a double
quote.

Source Error:

Line 11: ' Define the JavaScript function for the specified control.
Line 12: Dim focusScript As String = "<script language='javas cript'>" &
_
Line 13: "document.getEl ementById('" + ctrl.ClientID &
"').focus() ;</script>"
Line 14:
Line 15: ' Add the JavaScript code to the page.
*************** *************** *************** *************** **************

If I take out any character from "</script>" (doesn't matter which
character), I don't get the error.

So it obviously has nothing to do with the double quotes.

Why does this happen?

I am not even into the RegisterStartup Script yet, until I can solve this
question.

Thanks,

Tom
Nice function to have in a utility class...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uN******** ******@TK2MSFTN GP14.phx.gbl...
Is there a way during Page_Load to change or add an attribute to the Body
tag?

I want to be able to change the onLoad body attribute to do a focus on
one
of my text boxes, such as:

onLoad="documen t.forms[0].txtLogon.focus ();"

The problem is I have my <body> in an include file and want to set the
onLoad attribute during Page_Load time.

Thanks,

Tom.


Nov 19 '05 #5
Just a bug :)
http://support.microsoft.com/kb/316174/EN-US/

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OW******** ******@TK2MSFTN GP09.phx.gbl...
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uw******** *****@TK2MSFTNG P12.phx.gbl...
There are ways, but why not just use Page.RegisterSt artupScript?

Dim str As New System.Text.Str ingBuilder
str.Append("<sc ript language=""Java Script"">")
str.Append(Syst em.Environment. NewLine)
str.Append("doc ument.forms[0].txtLogon.focus ();")
str.Append(Syst em.Environment. NewLine)
str.Append("</script>")
Page.RegisterSt artupScript("Se tFocus", str.ToString())
That is a great idea. I didn't know this existed. I started looking into
how this works and tried to create a small page that really does nothing,
but I wanted to look at how the RegisterStartup Script works. I am running
into the same error I have had before whenever I try to put a tag into a
string. I usually get an error.

Here is the page I am using:

*************** *************** *************** *************** *************** *
***** <%@ Page Language="VB" trace="false" debug="true" AutoEventWireup ="true"
ContentType="te xt/html" ResponseEncodin g="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Import Namespace="Syst em.Web.Mail" %>
<html>
<script runat="server">
sub sendEmail_click ( sender as Object, e as EventArgs )
Call setFocus(txtLog on)
End Sub

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javas cript'>" & _
"document.getEl ementById('" + ctrl.ClientID & "').focus() ;</script>"

' Add the JavaScript code to the page.
Page.RegisterSt artupScript("Fo cusScript", focusScript)
End Sub

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Home Page</title>
<link href="staffing. css" rel="stylesheet " type="text/css">
</head>
<body>
<form id="Form1" runat="server">
<center>
<br>
<table width="500" border="0" cellspacing="0" cellpadding="2" >
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="114" colspan=2><span class="style1"> Simply enter your email
address below and we'll email you your password. </span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">E mail Address: </td>
<td><asp:textbo x id="txtLogon" runat="server" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value=" Send "
onClick="sendEm ail_click">&nbs p;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
</center>
</form>
</body>
</html>
*************** *************** *************** *************** *************** *
***
I get the following error:
*************** *************** *************** *************** *******
Compiler Error Message: BC30648: String constants must end with a double
quote.

Source Error:

Line 11: ' Define the JavaScript function for the specified control.
Line 12: Dim focusScript As String = "<script language='javas cript'>" & _
Line 13: "document.getEl ementById('" + ctrl.ClientID &
"').focus() ;</script>"
Line 14:
Line 15: ' Add the JavaScript code to the page.
*************** *************** *************** *************** **************

If I take out any character from "</script>" (doesn't matter which
character), I don't get the error.

So it obviously has nothing to do with the double quotes.

Why does this happen?

I am not even into the RegisterStartup Script yet, until I can solve this
question.

Thanks,

Tom

Nice function to have in a utility class...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uN******** ******@TK2MSFTN GP14.phx.gbl...
Is there a way during Page_Load to change or add an attribute to the Body tag?

I want to be able to change the onLoad body attribute to do a focus on
one
of my text boxes, such as:

onLoad="documen t.forms[0].txtLogon.focus ();"

The problem is I have my <body> in an include file and want to set the
onLoad attribute during Page_Load time.

Thanks,

Tom.



Nov 19 '05 #6
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Om******** ******@TK2MSFTN GP14.phx.gbl...
Just a bug :)
http://support.microsoft.com/kb/316174/EN-US/
I just love MS.

They say it is by design. One of those undocumented feature, I suppose.

What is interesting is that I see examples on the net all the time that
build strings that is supposed to dynamically put the Javascript on a page
and they "never" do this (add the "chr(60) &" in place of the "<"). I
wonder why that is.

Thanks,

Tom.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OW******** ******@TK2MSFTN GP09.phx.gbl...
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uw******** *****@TK2MSFTNG P12.phx.gbl...
> There are ways, but why not just use Page.RegisterSt artupScript?
>
> Dim str As New System.Text.Str ingBuilder
> str.Append("<sc ript language=""Java Script"">")
> str.Append(Syst em.Environment. NewLine)
> str.Append("doc ument.forms[0].txtLogon.focus ();")
> str.Append(Syst em.Environment. NewLine)
> str.Append("</script>")
> Page.RegisterSt artupScript("Se tFocus", str.ToString())


That is a great idea. I didn't know this existed. I started looking
into
how this works and tried to create a small page that really does nothing,
but I wanted to look at how the RegisterStartup Script works. I am
running
into the same error I have had before whenever I try to put a tag into a
string. I usually get an error.

Here is the page I am using:

*************** *************** *************** *************** *************** *
*****
<%@ Page Language="VB" trace="false" debug="true" AutoEventWireup ="true"
ContentType="te xt/html" ResponseEncodin g="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ Import Namespace="Syst em.Web.Mail" %>
<html>
<script runat="server">
sub sendEmail_click ( sender as Object, e as EventArgs )
Call setFocus(txtLog on)
End Sub

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javas cript'>" & _
"document.getEl ementById('" + ctrl.ClientID &
"').focus() ;</script>"

' Add the JavaScript code to the page.
Page.RegisterSt artupScript("Fo cusScript", focusScript)
End Sub

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Home Page</title>
<link href="staffing. css" rel="stylesheet " type="text/css">
</head>
<body>
<form id="Form1" runat="server">
<center>
<br>
<table width="500" border="0" cellspacing="0" cellpadding="2" >
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="114" colspan=2><span class="style1"> Simply enter your
email
address below and we'll email you your password. </span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">E mail Address: </td>
<td><asp:textbo x id="txtLogon" runat="server" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value=" Send "
onClick="sendEm ail_click">&nbs p;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
</center>
</form>
</body>
</html>

*************** *************** *************** *************** *************** *
***

I get the following error:
*************** *************** *************** *************** *******
Compiler Error Message: BC30648: String constants must end with a double
quote.

Source Error:

Line 11: ' Define the JavaScript function for the specified control.
Line 12: Dim focusScript As String = "<script language='javas cript'>"

&
_
Line 13: "document.getEl ementById('" + ctrl.ClientID &
"').focus() ;</script>"
Line 14:
Line 15: ' Add the JavaScript code to the page.
*************** *************** *************** *************** **************

If I take out any character from "</script>" (doesn't matter which
character), I don't get the error.

So it obviously has nothing to do with the double quotes.

Why does this happen?

I am not even into the RegisterStartup Script yet, until I can solve this
question.

Thanks,

Tom
>
> Nice function to have in a utility class...
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "tshad" <ts**********@f tsolutions.com> wrote in message
> news:uN******** ******@TK2MSFTN GP14.phx.gbl...
>> Is there a way during Page_Load to change or add an attribute to the Body >> tag?
>>
>> I want to be able to change the onLoad body attribute to do a focus on
>> one
>> of my text boxes, such as:
>>
>> onLoad="documen t.forms[0].txtLogon.focus ();"
>>
>> The problem is I have my <body> in an include file and want to set the
>> onLoad attribute during Page_Load time.
>>
>> Thanks,
>>
>> Tom.
>>
>>
>
>



Nov 19 '05 #7

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

Similar topics

7
2521
by: Michel | last post by:
Hi folks, I wonder if what I have in mind is possible, maybe even not all that complicated: I have an image, which is a yellow circle. I want this yellow circle to change color by having 3 sliders (RGB) on a website and a button to process it. Is this at all possible and could someone point me in the right direction or
24
3465
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two frames have been loaded by using a javascript statement from the "navigation" frame, as shown below: top.window.ccs_logo.src =...
3
6611
by: Luis | last post by:
Hello I'm opening a window with a SWF inside (no HTML, just the SWF) but in the title bar appears something like http://www.server.com/myDir/myWeb/Flash/myFlash.swf i'd like to write something like "Wow!! look thos flash!!!". Could I do that from the function who launch it??? with something like this?
8
3154
by: Margaret MacDonald | last post by:
I'm a js novice trying to teach myself. I'm using Flanagan's 'Javascript, the definitive guide' from O'Reilly as a text. But either I'm dopier than usual or its layout doesn't match my learning style very well, because I seem to be having a dreadful time getting to grips with even the simplest things. Currently, I'm trying to change the...
2
1619
by: jdi | last post by:
I'm trying to change the value of the id attribute of the page's <body> tag AFTER the tag is outputted. i've two ways and both don't work 1) document.getElementById("body").setAttribute("id", "hello"); 2) document.getElementsByTagName("body").setAttribute("id","hello");
31
5667
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a calendar, 7 across by whatever needed down, and I manually create it each month - not a big deal. Every day I go in and darken the background color of...
4
3461
by: Doug van Vianen | last post by:
Hi, I have the following coding on a web page. It causes two pictures (pic1.jpg and pic2.jpg) to show, one above the other and then when one clicks on the top picture is squeezes to the left (as its width is reduced) to show the bottom picture. Then when the bottom picture is clicked the top picture expands to the right to cover the...
12
4511
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in another forum from Peter Huang that said that an id="bg" as follows... <body MS_POSITIONING="GridLayout" runat="server" id="bg"> then we could do...
2
2009
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name of the group that will receive the e-mail. I pass this.form to a function to validate the other data before handing it off to a script to...
0
7479
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
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...
0
7926
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...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3468
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...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
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
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
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...

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.