Asp.net2.0关于Header/title/Metatages/Style操作的一点小技巧

来源:互联网 发布:英语教学软件 编辑:程序博客网 时间:2024/06/07 00:36
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
收集一些偶然看到的小Tips,先列一些在这儿,慢慢补充。

设置title : this.Header.title="这是个title测试";
如果用了MasterPage可以这样用: this.Page.title = SiteMap.CurrentNode.title;
动态设置Style
Style Style = new Style();
Style.ForeColor = System.Drawing.Color.Navy;
Style.BackColor = System.Drawing.Color.LightGray;

// Add the Style to the Header for the body of the page
this.Header.StyleSheet.CreateStyleRule(Style, null, "body");
动态加样式表: HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/CSS");
link.Attributes.Add("rel", "Stylesheet");
link.Attributes.Add("href", "~/newStyle.css");
this.Header.Controls.Add(link);
动态加meta tags : // Render: <meta name="keywords" content="Some words listed here" />
HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = "Some words listed here";
this.Header.Controls.Add(meta);

// Render: <meta name="robots" content="noindex" />
meta = new HtmlMeta();
meta.Name = "robots";
meta.Content = "noindex";
this.Header.Controls.Add(meta);

// Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" />
meta = new HtmlMeta();
meta.Name = "date";
meta.Content = DateTime.Now.ToString("yyyy-MM-dd");
meta.Scheme = "YYYY-MM-DD";
this.Header.Controls.Add(meta);

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击