I need to change the css file at runtime (no I don't mean changing the theme or applying a style to a control). The end user should be able to change the css file online and then save the changed css file.
Reading the css file is no problem but when I try to write the css file back I get an IOException. The file can't be accessed because another process is using it.
So how can I change the current css file at runtime? I already searched the forum but didn't get an answer...
Thank you for your post. Unfortunately your solution doesn't work because I work with asp.net themes. In the Page_PreInit Event I set the theme to use but even there I can't write to the css file.
I'd split out the CSS in the theme into two bits: those that are fixed (if any) and then the user editable bits. If ASP.NET has the css file locked, try using an @import to the user editable CSS file .
@import "user.css";
this too may also be locked. If so try keeping the user editable CSS outside of the theme folder:
mhachen
0 Points
3 Posts
Change CSS File at runtime
Jun 02, 2009 02:52 PM|LINK
Hi there
I need to change the css file at runtime (no I don't mean changing the theme or applying a style to a control). The end user should be able to change the css file online and then save the changed css file.
Reading the css file is no problem but when I try to write the css file back I get an IOException. The file can't be accessed because another process is using it.
So how can I change the current css file at runtime? I already searched the forum but didn't get an answer...
Hope you can help!
Thanks, Mike
Segundo
Star
10384 Points
1483 Posts
Re: Change CSS File at runtime
Jun 02, 2009 07:21 PM|LINK
Hi,
try this:
1.- save the css file name in the database.
2.- Load the css file by injecting code:
<
link href='css/<%=CurrentCss %>' rel="stylesheet" type="text/css" />code beside:
protected CurrentCss as string = "css1.css"
2.- create a copy of the original css file and modify as you need.
3.- save it as css2.css (by example)
4.- in the button_click, you can alter the CurrentCss variable to css2.css,
this way the new css will be loaded.
5.- Delete the old css1.css file
Any doubt, post your comment.
Blog: http://www.neuronasoft.net
shahed.kazi
All-Star
17839 Points
3600 Posts
Re: Change CSS File at runtime
Jun 02, 2009 10:25 PM|LINK
.NET World |Captcha Control
mhachen
0 Points
3 Posts
Re: Change CSS File at runtime
Jun 05, 2009 06:45 AM|LINK
Hi Segundo
Thank you for your post. Unfortunately your solution doesn't work because I work with asp.net themes. In the Page_PreInit Event I set the theme to use but even there I can't write to the css file.
Do you have any other idea?
Thank you again, Mike
Dave Sussman
All-Star
36478 Points
4841 Posts
ASPInsiders
MVP
Re: Change CSS File at runtime
Jun 05, 2009 07:38 AM|LINK
I'd split out the CSS in the theme into two bits: those that are fixed (if any) and then the user editable bits. If ASP.NET has the css file locked, try using an @import to the user editable CSS file .
@import "user.css";
this too may also be locked. If so try keeping the user editable CSS outside of the theme folder:
@import "../../UserCss/user.css"
mhachen
0 Points
3 Posts
Re: Change CSS File at runtime
Jun 05, 2009 07:59 AM|LINK
Hi Dave
I have tried your solution but as far as I know @Import page directive is to import namespaces only.
Thank you for your help, Mike
Dave Sussman
All-Star
36478 Points
4841 Posts
ASPInsiders
MVP
Re: Change CSS File at runtime
Jun 05, 2009 08:11 AM|LINK
I wasn't really clear about that as I didn't mean the page directive. @import is a CSS feature to include CSS files from other files. See http://webdesign.about.com/cs/css/qt/tipcssatimport.htm and http://css-discuss.incutio.com/?page=ImportHack.