Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing stylesheet in code behind on masterpage

Tags:

c#

css

asp.net

In maste page i set the stylesheet that defines the layout.

 <link id="layoutStylesheet" href="CSS/Layout3Col.css" rel="stylesheet" type="text/css" runat="server" />

I have a ShowDoc.aspx page that inherits the master page.
I want to load a different css file when a specific parameter is passed to ShowDoc.aspx in query string.

How can I do it?
Should I define a public property in the master page so that showDoc.aspx can access it and change the layoutStylesheet ?


1 Answers

You could find the stylesheet link using the Master property on the ShowDoc page in Page_Load and redefine the Href property there.

HtmlLink link = Page.Master.FindControl( "layoutStyleSheet" ) as HtmlLink;
link.Href = ...your chosen stylesheet...
like image 156
tvanfosson Avatar answered Apr 20 '26 13:04

tvanfosson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!