本文整理汇总了C#中System.Web.UI.HtmlControls.HtmlLink.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlLink.RenderControl方法的具体用法?C# HtmlLink.RenderControl怎么用?C# HtmlLink.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.HtmlControls.HtmlLink
的用法示例。
在下文中一共展示了HtmlLink.RenderControl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToClientScriptManager
/// <summary>
/// Adds to client script manager.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="link">The link.</param>
private static void AddToClientScriptManager(Page page, HtmlLink link)
{
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(new StringBuilder()));
link.RenderControl(writer);
page.ClientScript.RegisterClientScriptBlock(typeof(Page),
writer.InnerWriter.ToString(), writer.InnerWriter.ToString());
}
示例2: IncludeCSS
/// <summary>
/// Includes an html markup like <link rel=Stylesheet type=text/css href=[YOUR_HREF] />
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="path"></param>
/// <param name="includeVersionBasedOnLastModifiedDate">adding the query param "v" = [yyyyMMddHHmmss] based on file last modified date</param>
/// <returns></returns>
public static IHtmlString IncludeCSS(this HtmlHelper htmlHelper, string path, bool includeVersionBasedOnLastModifiedDate = true)
{
string physicalPath = htmlHelper.ViewContext.HttpContext.Server.MapPath(path);
var fileInfo = new FileInfo(physicalPath);
if (!fileInfo.Exists) return new RawHtmlString(String.Empty);
var lastModifiedDate = fileInfo.LastWriteTime;
var sb = new StringBuilder();
using (var textWriter = new StringWriter(sb))
{
using (var htmlWriter = new HtmlTextWriter(textWriter))
{
var htmlLink = new HtmlLink();
htmlLink.Attributes["rel"] = "Stylesheet";
htmlLink.Href = String.Format("{0}?v={1:yyyyMMddHHmmss}", VirtualPathUtility.ToAbsolute(path), lastModifiedDate);
htmlLink.Attributes["type"] = "text/css";
htmlLink.RenderControl(htmlWriter);
}
}
return new RawHtmlString(sb.ToString());
}