In the code behind: how to add a background attribute to the body tag.

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

    In the code behind: how to add a background attribute to the body tag.

    In the .master file I have:
    <body runat="server" id="MainBody">

    I need to add a background attribute to MainBody in the .master.vb file.

    But there it tells me that MainBody is not declared.

    Now I'll try anything to see if I can get a hint of how to proceed. So I
    try:

    Dim zz As Control = Master.FindCont rol("MainBody")

    But Master's value is nothing



    I try

    Dim zz As Control = FindControl("Ma inBody")

    Seems to find it but Control does not have a background attribute to set.



    So now I'm trying this NG.

    Any suggestions as to how I can add that attribute???



    Thanks

    ps I know background is deprecated


  • =?Utf-8?B?TG91aXMgU29tZXJz?=

    #2
    RE: In the code behind: how to add a background attribute to the body

    Assuming that "MainBody" is the ID of a ContentPlaceHol der on your masterpage

    ContentPlaceHol ders do not have any backround attribute. You should nest it
    inside a DIV or so and alter that attribute instead.


    "_Who" wrote:
    In the .master file I have:
    <body runat="server" id="MainBody">
    >
    I need to add a background attribute to MainBody in the .master.vb file.
    >
    But there it tells me that MainBody is not declared.
    >
    Now I'll try anything to see if I can get a hint of how to proceed. So I
    try:
    >
    Dim zz As Control = Master.FindCont rol("MainBody")
    >
    But Master's value is nothing
    >
    >
    >
    I try
    >
    Dim zz As Control = FindControl("Ma inBody")
    >
    Seems to find it but Control does not have a background attribute to set.
    >
    >
    >
    So now I'm trying this NG.
    >
    Any suggestions as to how I can add that attribute???
    >
    >
    >
    Thanks
    >
    ps I know background is deprecated
    >
    >
    >

    Comment

    • _Who

      #3
      Re: In the code behind: how to add a background attribute to the body

      Not on a ContentPlaceHol ders.
      It's on the <bodytag
      thanks

      "Louis Somers" <LouisSomers@di scussions.micro soft.comwrote in message
      news:C74894B5-95EA-4B7F-B7B4-6A5FE945B4B9@mi crosoft.com...
      Assuming that "MainBody" is the ID of a ContentPlaceHol der on your
      masterpage
      >
      ContentPlaceHol ders do not have any backround attribute. You should nest
      it
      inside a DIV or so and alter that attribute instead.
      >
      >
      "_Who" wrote:
      >
      >In the .master file I have:

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

      >>
      >I need to add a background attribute to MainBody in the .master.vb file.
      >>
      >But there it tells me that MainBody is not declared.
      >>
      >Now I'll try anything to see if I can get a hint of how to proceed. So I
      >try:
      >>
      >Dim zz As Control = Master.FindCont rol("MainBody")
      >>
      >But Master's value is nothing
      >>
      >>
      >>
      >I try
      >>
      >Dim zz As Control = FindControl("Ma inBody")
      >>
      >Seems to find it but Control does not have a background attribute to set.
      >>
      >>
      >>
      >So now I'm trying this NG.
      >>
      >Any suggestions as to how I can add that attribute???
      >>
      >>
      >>
      >Thanks
      >>
      >ps I know background is deprecated
      >>
      >>
      >>

      Comment

      • Usenet User

        #4
        Re: In the code behind: how to add a background attribute to the body tag.

        On Tue, 23 Sep 2008 10:13:56 -0400, "_Who"
        <CalWhoNOSPAN@r oadrunner.comwr ote:
        >In the .master file I have:
        ><body runat="server" id="MainBody">
        >
        >I need to add a background attribute to MainBody in the .master.vb file.
        >
        >But there it tells me that MainBody is not declared.
        >
        >Now I'll try anything to see if I can get a hint of how to proceed. So I
        >try:
        >
        >Dim zz As Control = Master.FindCont rol("MainBody")
        >
        >But Master's value is nothing
        >
        >
        >
        >I try
        >
        >Dim zz As Control = FindControl("Ma inBody")
        >
        >Seems to find it but Control does not have a background attribute to set.
        >
        >
        >
        >So now I'm trying this NG.
        >
        >Any suggestions as to how I can add that attribute???
        >
        >
        >
        >Thanks
        >
        >ps I know background is deprecated
        >
        Here are some solutions (sorry, I am using C#, not VB.NET):

        1) Put the following into your Page_Load or Page_PreRender
        (preferably) event handler method:

        HtmlGenericCont rol body = Me.Page.FindCon trol( "MainBody" ) as
        HtmlGenericCont rol;
        body.Attributes["bgcolor"] = "#ffffcc";

        2) To avoid looking up control by its name, declare it is explicitly
        on your code-behind file by adding a protected page member variable
        that has the same ID and correct object type:

        protected HtmlGenericCont rol MainBody;

        .....
        and then in your event handler:

        this.MainBody.A ttributes["bgcolor"] = "#ccffff";


        Keep in mind that you can add any custom attribute to any HTML control
        this way. Also, the safer method maybe like follows, although I am not
        sure why the above works as well:

        this.MainBody.A ttributes.Add( "myAttrib", "myValue" );

        rather than

        this.MainBody.A ttributes["myAttrib"] = "myValue";

        N-joy!

        Comment

        • _Who

          #5
          Re: In the code behind: how to add a background attribute to the body tag.

          Thanks that fixed it


          "Usenet User" <no.spam@no.way wrote in message
          news:eudid4ptm3 51djj567u3v11m0 18ni6iigm@4ax.c om...
          On Tue, 23 Sep 2008 10:13:56 -0400, "_Who"
          <CalWhoNOSPAN@r oadrunner.comwr ote:
          >
          >>In the .master file I have:
          >><body runat="server" id="MainBody">
          >>
          >>I need to add a background attribute to MainBody in the .master.vb file.
          >>
          >>But there it tells me that MainBody is not declared.
          >>
          >>Now I'll try anything to see if I can get a hint of how to proceed. So I
          >>try:
          >>
          >>Dim zz As Control = Master.FindCont rol("MainBody")
          >>
          >>But Master's value is nothing
          >>
          >>
          >>
          >>I try
          >>
          >>Dim zz As Control = FindControl("Ma inBody")
          >>
          >>Seems to find it but Control does not have a background attribute to set.
          >>
          >>
          >>
          >>So now I'm trying this NG.
          >>
          >>Any suggestions as to how I can add that attribute???
          >>
          >>
          >>
          >>Thanks
          >>
          >>ps I know background is deprecated
          >>
          >
          Here are some solutions (sorry, I am using C#, not VB.NET):
          >
          1) Put the following into your Page_Load or Page_PreRender
          (preferably) event handler method:
          >
          HtmlGenericCont rol body = Me.Page.FindCon trol( "MainBody" ) as
          HtmlGenericCont rol;
          body.Attributes["bgcolor"] = "#ffffcc";
          >
          2) To avoid looking up control by its name, declare it is explicitly
          on your code-behind file by adding a protected page member variable
          that has the same ID and correct object type:
          >
          protected HtmlGenericCont rol MainBody;
          >
          ....
          and then in your event handler:
          >
          this.MainBody.A ttributes["bgcolor"] = "#ccffff";
          >
          >
          Keep in mind that you can add any custom attribute to any HTML control
          this way. Also, the safer method maybe like follows, although I am not
          sure why the above works as well:
          >
          this.MainBody.A ttributes.Add( "myAttrib", "myValue" );
          >
          rather than
          >
          this.MainBody.A ttributes["myAttrib"] = "myValue";
          >
          N-joy!

          Comment

          Working...