• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

alter master page HTML in codebehind of a user control

I have a master page with the following tag
<section id="bannerSection">

Open in new window

I'd like to put a user control on some of these master pages which alter this HTML to:
<section id="bannerSection"  style="background: url(Libraries/banners/slide1.jpg) no-repeat center center; ">

Open in new window

I presume the first thing i need to do is put run at server on the html control on the master page
<section id="bannerSection" runat="server">

Open in new window

but what code do i need to put in the Usercontrol to search for this div and alter it with the style...

Its a bit more involved with a CMS and different bg images etc, so i've stripped the question back to its basic form
but if i can do exactly what i've said above, i can figure the rest out myself so it works in the CMS
1 Solution
Carl TawnSystems and Integration DeveloperCommented:
You can access the control via the Pages reference to the Master, with something like:
HtmlGenericControl control = Page.Master.FindControl("wibble") as HtmlGenericControl;
control.Attributes.Add("style", "background-color:yellow;");

Open in new window

You'll need to include the System.Web.UI.HtmlControls namespace too.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now