使用后面的代码更改css文件中类的属性值 [英] Change the property value of a class in css file using code behind

查看:94
本文介绍了使用后面的代码更改css文件中类的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要读取一个css文件并找到此css文件的特定类,然后更改该类的属性值(例如:color),并使用C#中的代码将其保存回css文件中.
有人可以帮我吗!

解决方案

1)谁给了你这个要求",因为这样做的人并不真正了解事情的原理.这是一个愚蠢的想法.如果要更新css,则应由开发人员或设计人员在文本编辑器中完成,就是这样.
2)如果要让用户有能力自定义他们在您网站上的体验,那么覆盖CSS并非可行之路.如果覆盖css,它将影响所有用户,而不仅是进行更改的用户.如果是这种情况,最好提供一个自定义配置数据库,该数据库将存储所有可配置的值,之后您可以编写一个管理器类以根据每个用户的首选项为每个用户动态生成CSS.
3)如果我对您要问的问题完全不满意,请使用改进问题"小部件来扩展您的查询.
干杯.


我认为您在理解需求方面有误......

如果更改现有的类属性,这将影响整个网站..

即使您想要对cs文件进行较小的更改,也可以使用

yourControl.Style.Add("PropertyName","PropertyValue");

如果要整个课程都用

yourControl.CssClass ="yourClassName";

如果要明智地存储所有样式,则最好将样式存储在数据库中.

Hi,
I have a requirement to read a css file and find a particular class of this css file and then change the property value(say:color) of the class and save it back to css file using code behind in C#.
Can anybody help me!!

解决方案

1) Who has given you this as a "requirement", because whoever did that doesn''t really know how things work. It is a silly idea. If the css is to be updated, it should be done in a text editor by a developer or designer and that''s that.
2) If the idea is to provide a user the ability to customize their experience on your site, then overwriting the css is NOT the way to go. If you overwrite the css, it will affect all users and not just the one making the changes. If this is the case, you are better off to provide a custom configuration database which will store all the configurable values after which you can write a manager class to generate the css dynamically for each user based on their preferences.
3) If I''m totally off base with what you are trying to ask, please use the Improve Question widget to expand on your query.
Cheers.


I think you''ve mistake in understanding requirement...

If you change in existing class property, this will affects entire web site..

Even though you want minor change in cs file then you can use

yourControl.Style.Add("PropertyName","PropertyValue");

If want entire entire class then use

yourControl.CssClass = "yourClassName";

If you want to store all style user wise then its better to store style in database..


这篇关于使用后面的代码更改css文件中类的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆