【问题标题】:How to refer css file from visual webpart如何从可视化 webpart 引用 css 文件
【发布时间】:2014-10-21 02:27:12
【问题描述】:

我正在使用 Visual Studio 2012 和 SharePoint 2010。 我已添加映射到以下路径的 SharePoint 映射文件夹
{SharePointRoot}\Template\LAYOUTS\1033\STYLES
在其中,我添加了新文件夹,名称为项目和 css 文件。
我正在尝试使用以下

来引用此 css 文件
<SharePoint:CssLink ID="cssLink1" runat="server" DefaultUrl="~/Template/LAYOUTS/1033/STYLES/VisualWebPartProject/Stylesheet1.css" />

<SharePoint:CssRegistration runat="server" name~/Template/LAYOUTS/1033/STYLES/VisualWebPartProject/Stylesheet1.css" />

<link rel="stylesheet" type="text/css" href="~/Template/LAYOUTS/1033/STYLES/VisualWebPartProject/Stylesheet1.css"/>

Webpart 显示以下 CSSLink 和 CSSRegistration 错误
错误渲染控件 - CssRegistration1获取预览时发生错误

在所有这三种情况下,css 都没有应用到 webpart,但是当我在 ascx 页面上添加 css 代码时,它就会应用到 webpart。

你能告诉我需要做什么吗?

【问题讨论】:

    标签: css sharepoint sharepoint-2010 web-parts


    【解决方案1】:

    您为位于服务器布局文件夹中的 css 提供的路径不正确。您应该使用以/_layouts 为前缀的路径,而不是~/Template/LAYOUTS/_layouts 是 IIS SharePoint 网站中的虚拟目录,映射到服务器上的 Template/LAYOUTS 文件夹。

    试试这个:

    <SharePoint:CssRegistration name="/_layouts/1033/STYLES/VisualWebPartProject/Stylesheet1.css" ID="CustomCss" runat="server"/>
    

    【讨论】:

    • 嗨,我尝试了上面的代码,但没有成功。同样在 Visual Studio 的设计模式下,它显示 Webpart 显示错误“错误渲染控件 - CustomCss An error occurred while fetching preview” 感谢您花时间帮助我。
    • 服务器上可能没有这个css?您是否尝试过使用与链接标签相同的路径?
    • 是的,也尝试了链接标签,但没有成功。
    猜你喜欢
    • 2015-03-30
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 2014-05-31
    • 2011-06-28
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多