本文整理汇总了C#中System.Web.UI.Adapters.PageAdapter.RenderBeginHyperlink方法的典型用法代码示例。如果您正苦于以下问题:C# PageAdapter.RenderBeginHyperlink方法的具体用法?C# PageAdapter.RenderBeginHyperlink怎么用?C# PageAdapter.RenderBeginHyperlink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.Adapters.PageAdapter
的用法示例。
在下文中一共展示了PageAdapter.RenderBeginHyperlink方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderBeginHyperlink
//引入命名空间
using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;
// A derived PageAdapter class.
public class CustomPageAdapter : PageAdapter
{
// Override RenderBeginHyperlink to add an attribute that
// references the referring page.
public override void RenderBeginHyperlink(
HtmlTextWriter writer, string targetUrl,
bool encodeUrl, string softkeyLabel,
string accessKey )
{
string url = null;
// Add the src attribute, if referring page URL is available.
if( Page != null && Page.Request != null &&
Page.Request.Url != null )
{
url = Page.Request.Url.AbsoluteUri;
if( encodeUrl )
url = HttpUtility.HtmlAttributeEncode( url );
writer.AddAttribute( "src", url );
}
// Add the accessKey attribute, if caller requested.
if( accessKey != null && accessKey.Length == 1 )
writer.AddAttribute( "accessKey", accessKey );
// Add the href attribute, encode the URL if requested.
if( encodeUrl )
url = HttpUtility.HtmlAttributeEncode( targetUrl );
else
url = targetUrl;
writer.AddAttribute( "href", url );
// Render the hyperlink opening tag with the added attributes.
writer.RenderBeginTag( "a" );
}
}