Solved

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

Posted on 2006-07-10
3
1,024 Views
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?
0
Comment
Question by:psk1
3 Comments
 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 250 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
        Else
            Me.div1.Attributes.CssStyle.Clear()
            Me.div1.Attributes.CssStyle.Add("Class", "firstCssClass")

        End If

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

HTH
0
 
LVL 10

Accepted Solution

by:
aki4u earned 250 total points
ID: 17078524
System.Web.UI.HtmlControls.HtmlGenericControl divID =
            (System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divID");
        divID.Attributes.Add("class","test");
0
 
LVL 2

Author Comment

by:psk1
ID: 17078773
Thanks!

My solution based on a hybrid of the above comments:

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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