How to access ID in Master Page

Discussion in 'ASP .Net' started by tshad, May 15, 2008.

  1. tshad

    tshad Guest

    I have the body tag of my page in my master page.

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

    In my control that is on the page, I want to set the onload event which I
    would do if it was in my control but it isn't:

    MyBody.Attributes.Add("onclick", "TestIt();");

    Is there a way to do this from the control?

    Doing this gives me the error:

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

    Thanks,

    Tom
     
    tshad, May 15, 2008
    #1
    1. Advertising

  2. Have you tried Page.FindControl("MyBody")? Or, Master.FindControl (whichever
    the case may require)?
    Peter

    "tshad" <> wrote in message
    news:...
    >I have the body tag of my page in my master page.
    >
    > <body id="MyBody" runat="server">
    >
    > In my control that is on the page, I want to set the onload event which I
    > would do if it was in my control but it isn't:
    >
    > MyBody.Attributes.Add("onclick", "TestIt();");
    >
    > Is there a way to do this from the control?
    >
    > Doing this gives me the error:
    >
    > Error 5 The name 'MyBody' does not exist in the current context
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    Peter Bromberg [C# MVP], May 15, 2008
    #2
    1. Advertising

  3. tshad

    Madhur Guest

    In the content page, include an @MasterType directive. This will cause the
    ..Master property to be automatically cast to the correct type so that you
    can access any of it's methods and/or properties.
    --
    MAdhur

    "tshad" <> wrote in message
    news:...
    >I have the body tag of my page in my master page.
    >
    > <body id="MyBody" runat="server">
    >
    > In my control that is on the page, I want to set the onload event which I
    > would do if it was in my control but it isn't:
    >
    > MyBody.Attributes.Add("onclick", "TestIt();");
    >
    > Is there a way to do this from the control?
    >
    > Doing this gives me the error:
    >
    > Error 5 The name 'MyBody' does not exist in the current context
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    Madhur, May 16, 2008
    #3
    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. Doug McCann
    Replies:
    1
    Views:
    1,150
    William Brogden
    Aug 5, 2004
  2. Zeba
    Replies:
    1
    Views:
    545
    Mark Rae
    Feb 22, 2007
  3. John
    Replies:
    4
    Views:
    422
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,502
    Nathan Sokalski
    Mar 4, 2010
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,548
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page