How/Where to add to the BODY TAG

Discussion in 'ASP .Net Web Controls' started by tony obrien, Jul 5, 2004.

  1. tony obrien

    tony obrien Guest

    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
     
    tony obrien, Jul 5, 2004
    #1
    1. Advertising

  2. tony obrien

    Teemu Keiski Guest

    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

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke



    "tony obrien" <> wrote in message
    news:Xns951D64AF5F6F3tobsourcecodeinccom@216.196.97.136...
    > 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
     
    Teemu Keiski, Jul 5, 2004
    #2
    1. Advertising

  3. tony obrien

    tony obrien Guest

    "Teemu Keiski" <> wrote in
    news::

    > 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
     
    tony obrien, Jul 5, 2004
    #3
  4. tony obrien

    Teemu Keiski Guest

    Hi,

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

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "tony obrien" <> wrote in message
    news:Xns951D68BDE616Etobsourcecodeinccom@216.196.97.136...
    > "Teemu Keiski" <> wrote in
    > news::
    >
    > > 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
     
    Teemu Keiski, Jul 5, 2004
    #4
  5. tony obrien

    Jos Guest

    tony obrien wrote:
    > "Teemu Keiski" <> wrote in
    > news::
    >
    >> 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 ??


    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();")

    --

    Jos
     
    Jos, Jul 5, 2004
    #5
  6. tony obrien

    tony obrien Guest

    "Teemu Keiski" <> wrote in
    news:#:

    > 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
     
    tony obrien, Jul 5, 2004
    #6
  7. tony obrien

    tony obrien Guest

    >
    > 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'
     
    tony obrien, Jul 5, 2004
    #7
  8. tony obrien

    tony obrien Guest

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

    thanks,
    tob
     
    tony obrien, Jul 5, 2004
    #8
  9. tony obrien

    tony obrien Guest

    tony obrien <> wrote in
    news:Xns951D64AF5F6F3tobsourcecodeinccom@216.196.97.136:

    > 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
     
    tony obrien, Jul 5, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    893
    John C. Bollinger
    Jan 27, 2006
  2. Mark Rae

    Add an attribute to the tag <body>?

    Mark Rae, Oct 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    336
    Gustavo Arriola
    Oct 31, 2006
  3. ~~~ .NET Ed ~~~
    Replies:
    5
    Views:
    1,403
    David Wainwright
    Mar 27, 2007
  4. Kees de Winter

    Add JavaScript functions to body tag

    Kees de Winter, May 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    419
  5. _Who
    Replies:
    4
    Views:
    815
Loading...

Share This Page