How/Where to add to the BODY TAG

T

tony obrien

Hi ,

I'm trying to add an "OnLoad=blahblah.setFocus()" thingy to an ASPX page.

Is there a PAGE object (or something) that allows me to add to the BODY tag
that finally gets rendered?

thanks,
tob
 
T

Teemu Keiski

Hi,

You'd specify the BODY tag with an ID and runat="server" attributes which
gives you server-side access to the control (which it is after it has those
declarative attributes ). You could then have a codebehind member for it
with type System.Web.UI.HtmlControls.HtmlGenericControl (or
HtmlContainerControl), which you can use to access the attributes of the
control
 
T

tony obrien

Hi,

You'd specify the BODY tag with an ID and runat="server" attributes
which gives you server-side access to the control (which it is after
it has those declarative attributes ). You could then have a
codebehind member for it with type
System.Web.UI.HtmlControls.HtmlGenericControl (or
HtmlContainerControl), which you can use to access the attributes of
the control

But in codeBehind if I "Dim aNewBody as HtmlControls.HtmlGenericControl"
then set its "InnerText" value to somehting like:
"ID="myBody" runat="server" bgColor="#fffffff" onLoad="someItem.setFocus
();"


How does ASPX knwo to replace the "original body" with mine??

its seems that there is no connection between the two using
HtmlControls.HtmlGenericControl ??

thanks,
tob
 
T

Teemu Keiski

Hi,

the code-behind member name must match to the ID you give to the control.
 
J

Jos

tony said:
But in codeBehind if I "Dim aNewBody as
HtmlControls.HtmlGenericControl" then set its "InnerText" value to
somehting like: "ID="myBody" runat="server" bgColor="#fffffff"
onLoad="someItem.setFocus ();"


How does ASPX knwo to replace the "original body" with mine??

its seems that there is no connection between the two using
HtmlControls.HtmlGenericControl ??

Use this tag:
<body ID="myBody" runat="server" bgColor="#ffffff">

Use this codeBehind:
Dim myBody As HtmlControls.HtmlGenericControl

The name "myBody" connects the two.

Then use this in your code:
myBody.Attributes.Add("onLoad","someItem.setFocus();")
 
T

tony obrien

Hi,

the code-behind member name must match to the ID you give to the
control.

Thanks... I think I'm close. here's what I've got (but doesn't work ;)

I added .. id="myBody" runat="server"
to the basic page.

Then in codebehind I have....

Dim newBody as new HtmlGenericControl
newBody = Page.FindControl("myBody")
newBody.Attributes("OnLoad") = "someItem.SetFocus();"


I can't find a list of the 'attributes' available for the BODY TAG, but I
have a feeling this is not working because the Attributes method does
recognize the "onLoad" ?

Can you help?
thanks,
tob
 
T

tony obrien

Use this tag:
<body ID="myBody" runat="server" bgColor="#ffffff">

Use this codeBehind:
Dim myBody As HtmlControls.HtmlGenericControl

The name "myBody" connects the two.

Then use this in your code:
myBody.Attributes.Add("onLoad","someItem.setFocus();")


Thanks, Jos.

I understand the concepts and connections but it still doesn't work.

Here's an new aspect you may have missed... the "something" I'm trying to
set focus to was pushed into a PLACEHOLDER.

So my thinking was that the <body> was THE place to set the focus since by
this point the browser has complete control, the object has to exist, etc
etc etc.

Other attempts trying to use Javascript in PAGE_LOAD, and elsewhere always
brought an error saying essentially ("We ain't got none of those on this
page!")... meaning the render had not taken place fully enough for the item
to even exist on the page yet.

I don't get any errors from your suggestion but the item still does not
receive the focus when the page has finished loading.

Does the PLACEHOLDER notion change anything you've suggested?

thanks, again
tob'
 
T

tony obrien

ANd should I be "seeing" this new attribute in a ViewSource window from the
browser? I am not.

thanks,
tob
 
T

tony obrien

Hi ,

I'm trying to add an "OnLoad=blahblah.setFocus()" thingy to an ASPX
page.

Is there a PAGE object (or something) that allows me to add to the
BODY tag that finally gets rendered?

thanks,
tob

Well, here's the answer.... given Jos' suggestions and some misspellings on
my part (Argh!), It STILL didn't work UNTIL I also turned off
"SmartNavigation"

I guess it overrides the ".focus()" and forces the page to be qhere IT
wants it to be.

Now the focus goes EXACTLY as Jos predicted.

Thanks, to all.

tob
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top