语言

PageAdapter.RenderBeginHyperlink 方法

定义

向响应流呈现一个打开的超链接标记。

重载

名称 说明
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用于呈现特定于目标的输出的包含方法。

targetUrl
String

String保存链接的目标 URL 的值。

encodeUrl
Boolean

若要对流输出进行编码,则为 ;否则为 < a1/>。

softkeyLabel
String

String要用作软键标签的值。

示例

下面的代码示例演示如何派生从类命名 CustomPageAdapter 的 PageAdapter 类并重写 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用于呈现特定于目标的输出的包含方法。

targetUrl
String

String保存链接的目标 URL 的值。

encodeUrl
Boolean

若要对流输出进行编码,则为 ;否则为 < a1/>。

softkeyLabel
String

String要用作软键标签的值。

accessKey
String

String要分配给accessKey要创建的链接的属性的值。

例外

accessKey 长度超过一个字符。

示例

下面的代码示例演示如何派生从类命名 CustomPageAdapter 的 PageAdapter 类并重写 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.编写属性。

另请参阅

适用于