惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
小众软件
小众软件
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
MyScale Blog
MyScale Blog

博客园 - Francis Liang

Windows Azure存储容器私有,公共容器,公共Blob的区别 关于Windows Azure 地缘组(Affinity Groups) 使用Windows Azure创建和发布ASP.NET应用程序 创建并使用Windows Azure虚拟机模板 Windows Azure 设置虚拟机静态外网IP地址 Windows Azure 配置多个站点的虚拟网络连接 Windows Azure 虚拟网络配置(Site to Site) Windows Azure 虚拟网络配置(Point to Site) Microsoft Azure云计算第一步—试用帐户申请 拥抱云计算 《Microsoft Office SharePoint Server 2007 Best Practices》书评 修改MOSS2007内容查询部件实现自定义格式显示 [.NET Active Directory开发]根据NativeGuid获取DirectoryEntry实例 IISRESET命令功能新发现 Biztalk Server 2006安装配置 Web开发中对元素样式使用过滤器以增强其可视化效果 使用DIME协议上传文件 使用证书来做RSA非对称式加密 使用MSAgent代替传统的MessageBox提示来增用客户端用户体验
动态改变ASP.net页面标题和动态指定页面样式表
Francis Liang · 2006-02-22 · via 博客园 - Francis Liang

         如果需要让asp.net应用程序对用户留有一定有自定义空间,例如用户要对页面使用自己定义的样式表或标题,可以使用下面的方法来动态指定:
首先对ASPX文件中<HEAD>中的页面标题和样式表进行修改
Visual Studio 生成的代码:
    <title>WebForm1</Title>
    <LINK ref="stylesheet" type="text/css" href="control.css">
修改后的代码:
    <title runat="server" id="Title1">WebForm1</title>
    <LINK id="link1" runat="server" type=text/css" ref="stylesheet"></link>
我们将这两个HTML元素都加上runat=server,标记为服务器端控件以使我们能在服务器代码对其进行访问。

在WebForm1.aspx.cs文件,我们就可以使用C#代码来对其将行控制
private void Button1_Click(object sender,System.EventArgs e)
{
        Control ctrl=Page.FindControl("Title1");  //寻找我们刚才修改为runat=server的那个Title
        ((HtmlGenericControl)ctrl).InnerText="Hello";
        ctrl=Page.FindControl("link1");
         ((HtmlGenericControl)ctrl).Attributes.Add("href","control.css");

}

通过以上步骤即可实现动态改变ASP.net页面标题和动态指定页面样式表