如何在我们的用户控件应用样式表 [英] How to apply stylesheet in our user control

查看:97
本文介绍了如何在我们的用户控件应用样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个createa的用户控制和应用样式SHET。

I have createa a user control and apply a style shet.

当我在我的asp.net web窗体风格SHET将不适用添加该用户控件。我不想在我的asp.net页面中添加样式表文件的引用

When i add this user control on my asp.net web forms style shet will not apply. I don't want to add reference of stylesheet file in my asp.net page

PLS。帮帮我吧。

谢谢

推荐答案

链接样式表需要在HTML的HEAD部分得到应用。如果你不想在你的asp.net页面引用样式表直接您可以使用内嵌样式在你的用户控件或隐藏文件的用户控件code添加引用。下面code是在VB.NET,并从的这个论坛

Links to stylesheets need to be applied in the HEAD section of your html. If you don't want to reference the style sheet in your asp.net page directly you can either use inline styles in you user control or add the reference in the user controls code behind file. The following code is in VB.NET and was taken from an answer in this forum:

Dim Style As New HtmlControls.HtmlLink

With Style.Attributes
.Add("href", Me.ResolveUrl(Me.AppRelativeVirtualPath).Replace(" .ascx", ".css"))
.Add("type", "text/css")
.Add("rel", "stylesheet")
End With

Page.Header.Controls.Add(Style)

这篇关于如何在我们的用户控件应用样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆