编程应用样式的一个asp.net网站 [英] programmatically apply style to an asp.net website
问题描述
用新的空缺网站应用程序的
我想通过持有的CSS属性的一些自定义值的外商投资企业到样式应用到aspx页面,我不知道这是更好的方法。
i would like to apply a style to the aspx Page via a fie that holds some custom values of css attributes ,i am not sure which is better approach.
我仍然在测试的概念,我有持有这些值的文件:
i am still testing the concept , i have a file that holds those values :
width;100px width;130px background-color;#aac93f
这些值都不难codeD,但产生的另一个应用程序
these values are not hardcoded but generated by another application
和我想将其读入的应用程序。
and i would like to read it into the application .
我能想到的只有两种方式,我知道:
i could think of the only two ways i know :
`File.ReadAllLines` or `File.ReadAllText`.
然后经由proccessed数据背后设置HTML元素的样式属性code
then through code behind set the html elements style properties via proccessed data
htmltag.Style.Add("width", setting1)....etc
或
我也可以加载从动态/编程数据的样式表
I could also load style sheet from dynamic /programmatic data
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<!-- and put a C# server code like below -->
<%=someVariableOrCsMethodReturnedValue%>
</head>
,以便将举行一个格式化的风格与加载的值。
so that will hold a formatted style with the loaded values.
是一路加载自定义值的CSS样式?
推荐答案
在&lt; style>标签也可以的用作服务器控件:
The <style> tag can also be used as server control:
<style type="text/css" runat="server" id="htmlCss"></style>
这将产生在页面类型HtmlGenericControl的领域。
This will generate a field of type HtmlGenericControl in the page.
在页面生命周期事件(的Page_Load,Page_Init等)中的一个,分配这样的文字CSS定义:
In one of the page life-cycle events (Page_Load, Page_Init, etc), assign the literal CSS definition like this:
var css = @"
body
{
background-color:#b0c4de;
}";
htmlCss.InnerHtml = css;
这篇关于编程应用样式的一个asp.net网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!