MetaGuru
MetaGuru

Reputation: 43873

How can I edit CSS on the fly with ASP.NET code?

Want to edit things like DIV size, color, positioning (absolute), height/width etc.

Upvotes: 0

Views: 1139

Answers (4)

TStamper
TStamper

Reputation: 30384

I'm not sure of what you're trying to do with the information given, but to add css on the fly you can use jQuery to add the class to an element with those certain specifications.. you can have jquery wait in the background for something to happen on the client and just add the class with that certain style

Example:

<style>
 p { margin: 8px; font-size:16px; }
.color { color:blue; }

</style>

<script>
   $(document).ready(function(){
     $("#button1").click(function(){ 
      $("p:last").addClass("color");
   });
</script>

<p>Hello</p>
 <p>and</p>
<p>Goodbye</p>

Upvotes: 0

Mark Brittingham
Mark Brittingham

Reputation: 28875

Ryan, you may want to look into Themes if you want to change the appearance of your site based on user preferences (Learning about Skins can help as well but master themes first). This is really the right approach in the ASP.NET model unless you are looking just to adapt some specific output to certain data conditions.

Upvotes: 0

Jethro Larson
Jethro Larson

Reputation: 2345

If by "on the fly" you mean while the user is interacting with the page then you're going to need to use some javascript. I suggest learning jQuery as it provides an easy and effective way interact with the DOM.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 191058

You can just output the CSS like any other with Response.Write or the <%= someValue %> methods.

Here are some of the other methods: http://cfouquet.blogspot.com/2006/06/making-dynamic-css-content-with-aspnet.html

Upvotes: 1

Related Questions