Dynamically setting CSS values using ASP.NET
Is keeping the CSS file on the image server an option? If that it possible, you could make all the image references relative, and then you just need to update the link to the css file.
<link rel="stylesheet" href="<%= ConfigurationManager.AppSettings("css-server") %>style.css" />
If you still want to send or generate a css file dynamically:
css files don't have to end in css. aspx is fine. You could do this:
<link rel="stylesheet" href="style.aspx" />
and then in your style.aspx page:
protected void page_load(){
Response.ContentType = "text/css";
if (ConfigurationManager.AppSettings("css-server") == "local") {
Server.Transfer("css/local.css");
} else {
Server.Transfer("css/production.css");
}
}
If you still want to dynamically generate a css file, I'd use an HttpHandler, set the contenttype to "text/css", then generate the css with Response.Write. If you insist on having the page end in css, you could always register css to go to asp.net in IIS, then on incoming requests in global.asax application_Begin request, if the file ends in .css, use httpcontext.current.rewritepath to your handler.
This will have a net effect of style.css being dynamically generated at runtime.
CSS Style not being set Dynamically in ASP.NET Code behind
It was actually a simple error. I've used the wrong code to change the css class of the span named "followbtn_mainbtn".
I replaced this
followbtn_mainbtn.Attributes.CssStyle.Add("className", "follow-btner-no-hoverer");
with this
followbtn_mainbtn.Attributes["class"] = "follow-btner-no-hoverer";
Voila! Done deal. Thanks for all your answers and comments though :)
Change css dynamically from controller
You can use your model or ViewBag
.
In controller pass your data into an object like circle.MarginLeft = 12
or use ViewBag['marginLeft'] = 12
and in your .cshtml
file set
<div class="circle" style="margin-left:@ViewBag.marginLeft"></div>
or
<div class="circle" style="margin-left:@Model.marginLeft"></div>
Related Topics
Get Transactionscope to Work with Async/Await
C# Sha-1 VS. PHP Sha-1...Different Results
How to Display Formatted Code in Webpage
Hmac Sha256 in C# VS Hmac Sha256 in Swift Don't Match
Format Number Like Stack Overflow (Rounded to Thousands with K Suffix)
How to Manipulate Images at the Pixel Level in C#
Setting Generic Type at Runtime
SQL Error: Incorrect Syntax Near the Keyword 'User'
ASP.NET Core Return JSON with Status Code
How to Use Jwt in MVC Application for Authentication and Authorization
How to Return Text from Native (C++) Code
Remove CSS Class in Code Behind
Arkit Body Tracking Using Xamarin and C# Inaccurate
What Are Checked Exceptions in Java/C#
How to Indefinitely Pause a Thread
Why Is the Iteration Variable in a C# Foreach Statement Read-Only