Partilhar via


PageAdapter.RenderBeginHyperlink Método

Definição

Renderiza uma marca de hiperlink de abertura para o fluxo de resposta.

Sobrecargas

RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)

Renderiza uma marca de hiperlink de abertura que inclui a URL de destino para o fluxo de resposta.

RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)

Renderiza uma marca de hiperlink de abertura que inclui a URL de destino e uma chave de acesso para o fluxo de resposta.

RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)

Renderiza uma marca de hiperlink de abertura que inclui a URL de destino para o fluxo de resposta.

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)

Parâmetros

writer
HtmlTextWriter

O HtmlTextWriter que contém métodos para renderizar a saída específica do destino.

targetUrl
String

O valor String que contém a URL de destino do link.

encodeUrl
Boolean

true usar HtmlAttributeEncode(String) para codificar a saída do fluxo; caso contrário, false.

softkeyLabel
String

O valor String a ser usado como um rótulo de chave reversível.

Exemplos

O exemplo de código a seguir demonstra como derivar uma classe chamada CustomPageAdapter da classe PageAdapter e substituir o método RenderBeginHyperlink. O método RenderBeginHyperlink adiciona um atributo chamado src a um hiperlink, que contém uma referência à página atual. Todos os hiperlinks renderizados em páginas às quais CustomPageAdapter está anexado terão o atributo 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

Comentários

O método RenderBeginHyperlink grava uma marca de hiperlink de abertura. Quando writer é HtmlTextWriter, essa marca tem o seguinte formato:

<a href=" targetUrl ">

Notas aos Herdeiros

Quando você herda da classe PageAdapter, pode substituir o método RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) para escrever um formato diferente para uma marca de hiperlink de abertura ou para gravar atributos de marca adicionais. Por exemplo, o método base RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) não grava um atributo para softkeyLabel.

Confira também

Aplica-se a

RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)

Renderiza uma marca de hiperlink de abertura que inclui a URL de destino e uma chave de acesso para o fluxo de resposta.

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)

Parâmetros

writer
HtmlTextWriter

O HtmlTextWriter que contém métodos para renderizar a saída específica do destino.

targetUrl
String

O valor String que contém a URL de destino do link.

encodeUrl
Boolean

true usar HtmlAttributeEncode(String) para codificar a saída do fluxo; caso contrário, false.

softkeyLabel
String

O valor String a ser usado como um rótulo de chave reversível.

accessKey
String

O valor String a ser atribuído ao atributo accessKey do link a ser criado.

Exceções

accessKey é maior que um caractere.

Exemplos

O exemplo de código a seguir demonstra como derivar uma classe chamada CustomPageAdapter da classe PageAdapter e substituir o método RenderBeginHyperlink. RenderBeginHyperlink adiciona um atributo chamado src a um hiperlink, que contém uma referência à página atual. Todos os hiperlinks renderizados em páginas às quais CustomPageAdapter está anexado terão o atributo 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

Comentários

O método RenderBeginHyperlink grava uma marca de hiperlink de abertura. Quando writer é um objeto HtmlTextWriter, essa marca tem o seguinte formato:

<a href=" targetUrl " accessKey=" accessKey ">

Notas aos Herdeiros

Quando você herda da classe PageAdapter, pode substituir o método RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) para escrever um formato diferente para uma marca de hiperlink de abertura ou para gravar atributos de marca adicionais. Por exemplo, o método base RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) não grava um atributo para softkeyLabel.

Confira também

Aplica-se a