Dheeraj Guglani
Dheeraj Guglani

Reputation: 23

How to generate css by database in asp.net..?

I want to change the content of style sheet dynamically like:

 .menu
{
 color: #333333;
 Font-size : 12px;
}

I want to change the color and font size dynamically. How to replace value of color (like #333333 to #ffffff) and font size (12px to 14px) dynamically.

I am finding the way to use variables in stylesheet, and assigning it to attributes that can make my work easy.

Waiting for reply with example.

Upvotes: 2

Views: 1231

Answers (3)

Deadcow
Deadcow

Reputation: 121

You may use JavaSctipt with JQuery:

$("#myButton").Click(function()
{
    $(".menu").css({"color":"#ffffff","font-size":"14px"});
});

Upvotes: 0

Imran Balouch
Imran Balouch

Reputation: 2170

I am not pretty much sure that you can use variables in stylesheets, what I think a way around for it is to generate the style sheet at run time and assign it to the page.

In you asp.net page you can have like:

<head>
    <title>WebForm1</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <asp:literal id="literalCss" runat="server"></asp:literal>
</head>

and than in your code behind you can use:

private void Page_Load(object sender, System.EventArgs e)
{
// create css file here for the specific user and save it in a folder,
// give a meaning full name to file, if user specific you can append user id in name like
string fileName = "cssFile_" + userid + ".css";
    literalCss.Text = @"<link href='/style/" + fileName + "' rel='stylesheet' type='text/css' />";
}

I hope it can help you out.

Upvotes: 0

VikciaR
VikciaR

Reputation: 3412

If you use asp.net, use inline html. Read here

<div style="font-size: <% Response.Write(i)%>">
        Hello World<br />
</div>

Upvotes: 1

Related Questions