How to access ID in Master Page

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

    How to access ID in Master Page

    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.Attribut es.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]

    #2
    Re: How to access ID in Master Page

    Have you tried Page.FindContro l("MyBody")? Or, Master.FindCont rol (whichever
    the case may require)?
    Peter

    "tshad" <tshad@dslextre me.comwrote in message
    news:u1Dn67qtIH A.4716@TK2MSFTN GP06.phx.gbl...
    >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.Attribut es.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
    >
    >

    Comment

    • Madhur

      #3
      Re: How to access ID in Master Page

      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" <tshad@dslextre me.comwrote in message
      news:u1Dn67qtIH A.4716@TK2MSFTN GP06.phx.gbl...
      >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.Attribut es.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
      >
      >

      Comment

      Working...