PageAdapter.RenderBeginHyperlink Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Representa una etiqueta de hipervínculo de apertura para la secuencia de respuesta.
Sobrecargas
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
Representa una etiqueta de hipervínculo de apertura que incluye la dirección URL de destino para la secuencia de respuesta. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Representa una etiqueta de apertura de hipervínculo que incluye la dirección URL de destino y una clave de acceso a la secuencia de respuesta. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
Representa una etiqueta de hipervínculo de apertura que incluye la dirección URL de destino para la secuencia de respuesta.
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
HtmlTextWriter que contiene los métodos para representar el resultado específico del destino.
- encodeUrl
- Boolean
true
para utilizar HtmlAttributeEncode(String) para codificar la secuencia de salida; de lo contrario, false
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo derivar una clase denominada CustomPageAdapter
de la PageAdapter clase e invalidar el RenderBeginHyperlink método . El RenderBeginHyperlink método agrega un atributo denominado src
a un hipervínculo, que contiene una referencia a la página actual. Todos los hipervínculos representados en páginas a las que CustomPageAdapter
se adjunta tendrá el src
atributo .
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
Comentarios
El RenderBeginHyperlink método escribe una etiqueta de hipervínculo de apertura. Cuando writer
es HtmlTextWriter, esta etiqueta tiene el formato siguiente:
<a href="
targetUrl
">
Notas a los desarrolladores de herederos
Cuando hereda de la PageAdapter clase , puede invalidar el RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) método para escribir un formato diferente para una etiqueta de hipervínculo de apertura o para escribir atributos de etiqueta adicionales. Por ejemplo, el RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) método base no escribe un atributo para softkeyLabel
.
Consulte también
Se aplica a
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
Representa una etiqueta de apertura de hipervínculo que incluye la dirección URL de destino y una clave de acceso a la secuencia de respuesta.
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
HtmlTextWriter que contiene los métodos para representar el resultado específico del destino.
- encodeUrl
- Boolean
true
para utilizar HtmlAttributeEncode(String) para codificar la secuencia de salida; de lo contrario, false
.
Excepciones
accessKey
tiene más de un carácter.
Ejemplos
En el ejemplo de código siguiente se muestra cómo derivar una clase denominada CustomPageAdapter
de la PageAdapter clase e invalidar el RenderBeginHyperlink método . RenderBeginHyperlink agrega un atributo denominado src
a un hipervínculo, que contiene una referencia a la página actual. Todos los hipervínculos representados en páginas a las que CustomPageAdapter
se adjunta tendrá el src
atributo .
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
Comentarios
El RenderBeginHyperlink método escribe una etiqueta de hipervínculo de apertura. Cuando writer
es un HtmlTextWriter objeto, esta etiqueta tiene el formato siguiente:
<a href="
targetUrl
" accessKey="
accessKey
">
Notas a los desarrolladores de herederos
Cuando hereda de la PageAdapter clase , puede invalidar el RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) método para escribir un formato diferente para una etiqueta de hipervínculo de apertura o para escribir atributos de etiqueta adicionales. Por ejemplo, el RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) método base no escribe un atributo para softkeyLabel
.
Consulte también
Se aplica a
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de