Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how can i change the bg color of a master page from one of its child page programatically

how can i change the bg color of a master page from one of its child page programatically

Scheduled Pinned Locked Moved ASP.NET
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S souravghosh18

    how can i change the bg color of a master page from one of its child page programatically Thanx in advance

    J Offline
    J Offline
    Jorgen Andersson
    wrote on last edited by
    #2

    Add this to you content.aspx <%@ MasterType VirtualPath="~/MasterPage.master" %> (using the correct name and path) then you can access your masterpage from the contentpage using Master.WhateverMasterControlYouWantToAccess.

    S K 2 Replies Last reply
    0
    • J Jorgen Andersson

      Add this to you content.aspx <%@ MasterType VirtualPath="~/MasterPage.master" %> (using the correct name and path) then you can access your masterpage from the contentpage using Master.WhateverMasterControlYouWantToAccess.

      S Offline
      S Offline
      souravghosh18
      wrote on last edited by
      #3

      First of all thanx for the response I have added the <@ MasterType VirtualPath="~/MasterPage.master" %> in the content page. and in the master page the body tag has an id="bodycol" and runat="server" Now to change the bgcolor of the master page what i should do. Master.bodycol.Attributes["bgcolor"]="Red"; is not working

      J 1 Reply Last reply
      0
      • S souravghosh18

        First of all thanx for the response I have added the <@ MasterType VirtualPath="~/MasterPage.master" %> in the content page. and in the master page the body tag has an id="bodycol" and runat="server" Now to change the bgcolor of the master page what i should do. Master.bodycol.Attributes["bgcolor"]="Red"; is not working

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #4

        You can use Master.bodycol.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Red"

        S 1 Reply Last reply
        0
        • J Jorgen Andersson

          You can use Master.bodycol.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Red"

          S Offline
          S Offline
          souravghosh18
          wrote on last edited by
          #5

          i have used your code but it is giving an error.that MasterPage.bodycol is not accessible in this context because it is Protected

          J 1 Reply Last reply
          0
          • J Jorgen Andersson

            Add this to you content.aspx <%@ MasterType VirtualPath="~/MasterPage.master" %> (using the correct name and path) then you can access your masterpage from the contentpage using Master.WhateverMasterControlYouWantToAccess.

            K Offline
            K Offline
            Karthick_gc
            wrote on last edited by
            #6

            Where to add this code <%@ MasterType VirtualPath="~/MasterPage.master" %> In master page or the web page?

            J 1 Reply Last reply
            0
            • K Karthick_gc

              Where to add this code <%@ MasterType VirtualPath="~/MasterPage.master" %> In master page or the web page?

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #7

              In the content page.

              K 1 Reply Last reply
              0
              • J Jorgen Andersson

                In the content page.

                K Offline
                K Offline
                Karthick_gc
                wrote on last edited by
                #8

                Where is the content page? I have only content place holder?

                J 1 Reply Last reply
                0
                • S souravghosh18

                  i have used your code but it is giving an error.that MasterPage.bodycol is not accessible in this context because it is Protected

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #9

                  True, you have to wrap it in a public or friend property and access the property from the content page.

                  S 1 Reply Last reply
                  0
                  • K Karthick_gc

                    Where is the content page? I have only content place holder?

                    J Offline
                    J Offline
                    Jorgen Andersson
                    wrote on last edited by
                    #10

                    The content page is what goes inside the content place holder. Maybe you should read[^] up on it a bit.

                    1 Reply Last reply
                    0
                    • S souravghosh18

                      how can i change the bg color of a master page from one of its child page programatically Thanx in advance

                      A Offline
                      A Offline
                      Amit Sk Sharma
                      wrote on last edited by
                      #11

                      Put all Master page content in a div control with ID and runat="server" inside form like : Form opening TAG DIV u will put all page stuff DIV close TAG Form Close tag and then use following in your content page code where u wish to change the bgColor for master page CType(Me.Page.FindControl("ctl00$div1"), HtmlGenericControl).Style.Add("background-color", "Yellow") where div1 is the DIV control ID in ctl00$div1

                      With Thanks & Regards Amit Sk Sharma

                      1 Reply Last reply
                      0
                      • J Jorgen Andersson

                        True, you have to wrap it in a public or friend property and access the property from the content page.

                        S Offline
                        S Offline
                        souravghosh18
                        wrote on last edited by
                        #12

                        i am using it like following, Public Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Master.bodytag.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Green" End Sub And it is giving the error how can it be wrapped in a friend property.

                        J 1 Reply Last reply
                        0
                        • S souravghosh18

                          i am using it like following, Public Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Master.bodytag.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Green" End Sub And it is giving the error how can it be wrapped in a friend property.

                          J Offline
                          J Offline
                          Jorgen Andersson
                          wrote on last edited by
                          #13

                          You can do it like this. Put this one in the master: Public WriteOnly Property ChangeColor() As Boolean Set(ByVal value As Boolean) bodytag.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Green" End Set End Property And in the contentpage you call it with: Public Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Master.ChangeColor = true End Sub I know, it's a bit ugly...

                          S 1 Reply Last reply
                          0
                          • J Jorgen Andersson

                            You can do it like this. Put this one in the master: Public WriteOnly Property ChangeColor() As Boolean Set(ByVal value As Boolean) bodytag.Style(System.Web.UI.HtmlTextWriterStyle.BackgroundColor) = "Green" End Set End Property And in the contentpage you call it with: Public Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Master.ChangeColor = true End Sub I know, it's a bit ugly...

                            S Offline
                            S Offline
                            souravghosh18
                            wrote on last edited by
                            #14

                            Thanx a lot sir for your constant guidance.At last it is working fine. Thanx again

                            J 1 Reply Last reply
                            0
                            • S souravghosh18

                              Thanx a lot sir for your constant guidance.At last it is working fine. Thanx again

                              J Offline
                              J Offline
                              Jorgen Andersson
                              wrote on last edited by
                              #15

                              You're welcome

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups