PageAdapter.RenderBeginHyperlink 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
向响应流呈现一个打开的超链接标记。
重载
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
呈现包含响应流的目标 URL 的打开超链接标记。 |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
呈现包含目标 URL 和响应流的访问密钥的打开超链接标记。 |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
呈现包含响应流的目标 URL 的打开超链接标记。
public:
virtual void RenderBeginHyperlink(System::Web::UI::HtmlTextWriter ^ writer, System::String ^ targetUrl, bool encodeUrl, System::String ^ softkeyLabel);
public virtual void RenderBeginHyperlink (System.Web.UI.HtmlTextWriter writer, string targetUrl, bool encodeUrl, string softkeyLabel);
abstract member RenderBeginHyperlink : System.Web.UI.HtmlTextWriter * string * bool * string -> unit
override this.RenderBeginHyperlink : System.Web.UI.HtmlTextWriter * string * bool * string -> unit
Public Overridable Sub RenderBeginHyperlink (writer As HtmlTextWriter, targetUrl As String, encodeUrl As Boolean, softkeyLabel As String)
参数
- writer
- HtmlTextWriter
包含用于呈现特定于目标的输出的方法的 HtmlTextWriter。
- encodeUrl
- Boolean
true
使用 HtmlAttributeEncode(String) 对流输出进行编码;否则,false
。
示例
下面的代码示例演示如何从 PageAdapter 类派生名为 CustomPageAdapter
的类并重写 RenderBeginHyperlink 方法。
RenderBeginHyperlink 方法将名为 src
的属性添加到超链接,其中包含对当前页的引用。 在附加 CustomPageAdapter
的页面中呈现的所有超链接都将具有 src
属性。
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" );
}
}
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Adapters
' A derived PageAdapter class.
Public Class CustomPageAdapter
Inherits PageAdapter
' Override RenderBeginHyperlink to add an attribute that
' references the referring page.
Public Overrides Sub RenderBeginHyperlink( _
ByVal writer As HtmlTextWriter, ByVal targetUrl As String, _
ByVal encodeUrl As Boolean, ByVal softkeyLabel As String, _
ByVal accessKey As String)
Dim url As String
' Add the src attribute, if referring page URL is available.
If Not (Page Is Nothing) Then
If Not (Page.Request Is Nothing) Then
If Not (Page.Request.Url Is Nothing) Then
url = Page.Request.Url.AbsoluteUri
If encodeUrl Then
url = HttpUtility.HtmlAttributeEncode(url)
End If
writer.AddAttribute("src", url)
End If
End If
End If
' Render the accessKey attribute, if requested.
If Not (accessKey Is Nothing) Then
If accessKey.Length = 1 Then
writer.AddAttribute("accessKey", accessKey)
End If
End If
' Add the href attribute, encode the URL if requested.
If (encodeUrl) Then
url = HttpUtility.HtmlAttributeEncode(targetUrl)
Else
url = targetUrl
End If
writer.AddAttribute("href", url)
' Render the hyperlink opening tag with the added attributes.
writer.RenderBeginTag("a")
End Sub
End Class
注解
RenderBeginHyperlink 方法写入一个打开的超链接标记。 当 writer
HtmlTextWriter时,此标记的格式如下:
<a href="
targetUrl
">
继承者说明
从 PageAdapter 类继承时,可以重写 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 方法,以便为打开的超链接标记编写其他格式或编写其他标记属性。 例如,RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 基方法不为 softkeyLabel
编写属性。
另请参阅
适用于
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
呈现包含目标 URL 和响应流的访问密钥的打开超链接标记。
public:
virtual void RenderBeginHyperlink(System::Web::UI::HtmlTextWriter ^ writer, System::String ^ targetUrl, bool encodeUrl, System::String ^ softkeyLabel, System::String ^ accessKey);
public virtual void RenderBeginHyperlink (System.Web.UI.HtmlTextWriter writer, string targetUrl, bool encodeUrl, string softkeyLabel, string accessKey);
abstract member RenderBeginHyperlink : System.Web.UI.HtmlTextWriter * string * bool * string * string -> unit
override this.RenderBeginHyperlink : System.Web.UI.HtmlTextWriter * string * bool * string * string -> unit
Public Overridable Sub RenderBeginHyperlink (writer As HtmlTextWriter, targetUrl As String, encodeUrl As Boolean, softkeyLabel As String, accessKey As String)
参数
- writer
- HtmlTextWriter
包含用于呈现特定于目标的输出的方法的 HtmlTextWriter。
- encodeUrl
- Boolean
true
使用 HtmlAttributeEncode(String) 对流输出进行编码;否则,false
。
例外
accessKey
长度超过一个字符。
示例
下面的代码示例演示如何从 PageAdapter 类派生名为 CustomPageAdapter
的类并重写 RenderBeginHyperlink 方法。
RenderBeginHyperlink 向超链接添加一个名为 src
的属性,其中包含对当前页的引用。 在附加 CustomPageAdapter
的页面中呈现的所有超链接都将具有 src
属性。
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" );
}
}
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Adapters
' A derived PageAdapter class.
Public Class CustomPageAdapter
Inherits PageAdapter
' Override RenderBeginHyperlink to add an attribute that
' references the referring page.
Public Overrides Sub RenderBeginHyperlink( _
ByVal writer As HtmlTextWriter, ByVal targetUrl As String, _
ByVal encodeUrl As Boolean, ByVal softkeyLabel As String, _
ByVal accessKey As String)
Dim url As String
' Add the src attribute, if referring page URL is available.
If Not (Page Is Nothing) Then
If Not (Page.Request Is Nothing) Then
If Not (Page.Request.Url Is Nothing) Then
url = Page.Request.Url.AbsoluteUri
If encodeUrl Then
url = HttpUtility.HtmlAttributeEncode(url)
End If
writer.AddAttribute("src", url)
End If
End If
End If
' Render the accessKey attribute, if requested.
If Not (accessKey Is Nothing) Then
If accessKey.Length = 1 Then
writer.AddAttribute("accessKey", accessKey)
End If
End If
' Add the href attribute, encode the URL if requested.
If (encodeUrl) Then
url = HttpUtility.HtmlAttributeEncode(targetUrl)
Else
url = targetUrl
End If
writer.AddAttribute("href", url)
' Render the hyperlink opening tag with the added attributes.
writer.RenderBeginTag("a")
End Sub
End Class
注解
RenderBeginHyperlink 方法写入一个打开的超链接标记。 当 writer
是 HtmlTextWriter 对象时,此标记具有以下格式:
<a href="
targetUrl
" accessKey="
accessKey
">
继承者说明
从 PageAdapter 类继承时,可以重写 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 方法,以便为打开的超链接标记编写其他格式或编写其他标记属性。 例如,RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 基方法不为 softkeyLabel
编写属性。