Solved

alter master page HTML in codebehind of a user control

Posted on 2013-11-29
1
301 Views
Last Modified: 2013-12-04
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
0
Comment
Question by:websss
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39685305
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.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now