How to save style-css values for Later use then Reload those values back

笑着哭i 提交于 2019-12-04 07:27:22

问题


Having a list of all SQL database-tables and their columns-names, each in List<string>

Via a dropDown list control I already chose a table and the columns it has, then after the first stage, where I have chosen the table and it's columns I am navigating to a page that's has a Graphical User interface like in this screenshot:

It will then as you could see in the picture, render an html table , with chosen columns as the htmlTable headers .

So now when result is displayed in that aspx page,

By using Jquery, I have managed to implement a test-tool.

This enables me to apply some style setting via Graphical User interface - on that table, and for now its just headers fonts-names , headers background-color and the columns width :

headers fonts .

fonts are being chosen by an AJAX ToolKit autoComplete Extender targeting a dedicated asp:TextBox with fonts names as its dataSource

So on textchange event - jQuery is binding selected value...accordingly for a preview .

Same for background

By using a jQuery color picker, which with it's event handler is doing the job of applying the selected color as the <tr> bgcolor ...etc '

Now that I have all chosen css values i need to use those for a webSite application

What is the simplest way to achieve this goal ?

I could think of generating it through a File.WriteAllText ,

So that way result will be a new File created with text generated text is a head section of .aspx webform page (auto generated via String.Format)

string formatedStyleStr = string.Format(" <style Type=\"text/css\"> #{0} { \r\twidth: {1};", ID values of jQuery's job);

That's the idea ...

As the new file name will be default with an extension .aspx...

Then write into it programmatically formatted string as you would manually write it

When usually starting a new empty website application.

So instead of using new form , you will "add an existing item "...

or other options I could do to achieve this result. i did not yet decide how to ...

only that i need it to hold these values that was selected ,

so as you will open this file to work on it via visual studio, you will have a kind of a template to start with (the initial style is created by the UI in the picture)

what approach is the one I should use ?

as i don't have enough experience in that field ....I wanted to ask did anyone think of it already ...and figured some ways to implement it.


回答1:


try this

ASPX

<style type="text/css" runat="server" id="AutogeneratedStyle"></style>

This will create a field - type HtmlGenericControl within the current page.

C# Code Behind

then just assign the literal CSS definition like this:

var generatedStyle= string.Format(

                   "-->#idOfElement here<---
                      {
                          background-color:{0};
                      }", someVariables);

AutogeneratedStyle.InnerHtml = generatedStyle;

hope it will help you gettng started



来源:https://stackoverflow.com/questions/13908695/how-to-save-style-css-values-for-later-use-then-reload-those-values-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!