Programmatically changing Div style on Master Page based on displayed Content Page

Posted on 2006-07-10
Medium Priority
Last Modified: 2008-09-03
I have a div on my master page which needs to have its CSS style changed based on which content page it is displaying.  How can I do this?
Question by:psk1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 1000 total points
ID: 17078483
Run the div as server control and do something like this

If i = 0 Then
            Me.div1.Attributes.CssStyle.Clear() 'Clear Css Styles
            Me.div1.Attributes.CssStyle.Add("Class", "secondCssClass") 'add the css class attribute
            Me.div1.Attributes.CssStyle.Add("Class", "firstCssClass")

        End If

of course this assumes you have 2 Css Classes named firstCssClass and secondCssClass

LVL 10

Accepted Solution

aki4u earned 1000 total points
ID: 17078524
System.Web.UI.HtmlControls.HtmlGenericControl divID =

Author Comment

ID: 17078773

My solution based on a hybrid of the above comments:

            Dim divID As System.Web.UI.HtmlControls.HtmlGenericControl = Me.Master.FindControl("divID")
            divID.Attributes.Add("class", "classname")

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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