Access to body ID of Master Page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    Access to body ID of Master Page

    In VS 2005,

    I need to get access to the body tag which I have set up on my Master Page
    as:

    <body ID="MyBody" runat="server">

    But when do something like:

    MyBody.Attribut e.Add("onload", "GetAccounts()" );

    But I get:

    Error 1 The name 'MyBody' does not exist in the current context

    I also tried Page.MyBody, but that doesn't work either.

    How can I put attributes on the body tag from a child page or control?

    Thanks,

    Tom


  • Mark Fitzpatrick

    #2
    Re: Access to body ID of Master Page

    You need to access the MasterPage property of your page or control, then
    cast it to the type of your MasterPage. The MasterPage property is cast to
    the MasterPage base type so it won't have any of the properties or controls
    you may create within the master page, unless you cast it to the specific
    master page type, like
    ((mysite.pages. mymaster)this.M asterPage).MyBo dy.Attribute.Ad d("onload","Get Accounts()");

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression



    "tshad" <tshad@dslextre me.comwrote in message
    news:%23VlBnVif IHA.748@TK2MSFT NGP04.phx.gbl.. .
    In VS 2005,
    >
    I need to get access to the body tag which I have set up on my Master Page
    as:
    >
    <body ID="MyBody" runat="server">
    >
    But when do something like:
    >
    MyBody.Attribut e.Add("onload", "GetAccounts()" );
    >
    But I get:
    >
    Error 1 The name 'MyBody' does not exist in the current context
    >
    I also tried Page.MyBody, but that doesn't work either.
    >
    How can I put attributes on the body tag from a child page or control?
    >
    Thanks,
    >
    Tom
    >
    >

    Comment

    • tshad

      #3
      Re: Access to body ID of Master Page


      "Mark Fitzpatrick" <markfitz@fitzm e.comwrote in message
      news:OKhfGbifIH A.4140@TK2MSFTN GP04.phx.gbl...
      You need to access the MasterPage property of your page or control, then
      cast it to the type of your MasterPage. The MasterPage property is cast to
      the MasterPage base type so it won't have any of the properties or
      controls you may create within the master page, unless you cast it to the
      specific master page type, like
      ((mysite.pages. mymaster)this.M asterPage).MyBo dy.Attribute.Ad d("onload","Get Accounts()");
      Not sure what you mean here.

      Is "mysite" my namespace? I tried that but got an error. I also can't find
      an entry that will allow my to put pages in. Also what is mymaster?

      Thanks,

      Tom
      >
      Hope this helps,
      Mark Fitzpatrick
      Microsoft MVP - Expression
      >
      >
      >
      "tshad" <tshad@dslextre me.comwrote in message
      news:%23VlBnVif IHA.748@TK2MSFT NGP04.phx.gbl.. .
      >In VS 2005,
      >>
      >I need to get access to the body tag which I have set up on my Master
      >Page as:
      >>
      ><body ID="MyBody" runat="server">
      >>
      >But when do something like:
      >>
      >MyBody.Attribu te.Add("onload" ,"GetAccounts() ");
      >>
      >But I get:
      >>
      >Error 1 The name 'MyBody' does not exist in the current context
      >>
      >I also tried Page.MyBody, but that doesn't work either.
      >>
      >How can I put attributes on the body tag from a child page or control?
      >>
      >Thanks,
      >>
      >Tom
      >>
      >>
      >

      Comment

      • Mark Rae [MVP]

        #4
        Re: Access to body ID of Master Page

        "tshad" <tshad@dslextre me.comwrote in message
        news:%23VlBnVif IHA.748@TK2MSFT NGP04.phx.gbl.. .
        How can I put attributes on the body tag from a child page or control?
        Master.FindCont rol("MyBody").A ttribute.Add("o nload","GetAcco unts()");


        --
        Mark Rae
        ASP.NET MVP


        Comment

        Working...