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

Changing css in masterpage

I have a masterpage that contains my all the css for my website, what i'm looking for is an easy way to change to other css files using a drop down box.

I would like the specific code needed to do this including the drop down box (just write it on a bare page)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" bare"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <asp:ContentPlaceHolder id="head" runat="server">
    <style type="text/css">
        @import "style.css";

Open in new window

1 Solution
Amandeep Singh BhullarCommented:
Check the discussion,

Hope this will help you
Add link with runat="server" to your master page:
  <link id="linkStyles" rel="stylesheet" type="text/css" runat="server" />

In code behind add SelectedIndexChanged event handler to your DropDownList:
void dropDownList1_SelectedIndexChanged(Object sender, EventArgs e)
  string stylesheet = // get stylesheet address e.g. Server.MapPath(ropDownList1.SelectedItem.Text)
  linkStyles.Href = stylesheet;
you can customize this javascript to use drop down.

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

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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