PageAdapter.RenderBeginHyperlink Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Affiche une balise de lien hypertexte ouvrante dans le flux de réponse.
Surcharges
| Nom | Description |
|---|---|
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
Affiche une balise de lien hypertexte ouvrante qui inclut l’URL cible vers le flux de réponse. |
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Affiche une balise de lien hypertexte ouvrante qui inclut l’URL cible et une clé d’accès au flux de réponse. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
Affiche une balise de lien hypertexte ouvrante qui inclut l’URL cible vers le flux de réponse.
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)
Paramètres
- writer
- HtmlTextWriter
Méthodes HtmlTextWriter contenant pour afficher la sortie spécifique à la cible.
- encodeUrl
- Boolean
true
HtmlAttributeEncode(String) pour encoder la sortie du flux ; sinon, false.
Exemples
L’exemple de code suivant montre comment dériver une classe nommée CustomPageAdapter à partir de la PageAdapter classe et remplacer la RenderBeginHyperlink méthode. La RenderBeginHyperlink méthode ajoute un attribut nommé src à un lien hypertexte, qui contient une référence à la page active. Tous les liens hypertexte affichés dans les pages auxquelles CustomPageAdapter il est attaché auront l’attribut 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
Remarques
La RenderBeginHyperlink méthode écrit une balise de lien hypertexte ouvrante. Quand writer c’est HtmlTextWriterle cas, cette balise a le format suivant :
<a href="
targetUrl
">
Notes pour les héritiers
Lorsque vous héritez de la PageAdapter classe, vous pouvez remplacer la RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) méthode pour écrire un autre format pour une balise de lien hypertexte ouvrante ou pour écrire des attributs de balise supplémentaires. Par exemple, la RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) méthode de base n’écrit pas d’attribut pour softkeyLabel.
Voir aussi
S’applique à
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
Affiche une balise de lien hypertexte ouvrante qui inclut l’URL cible et une clé d’accès au flux de réponse.
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)
Paramètres
- writer
- HtmlTextWriter
Méthodes HtmlTextWriter contenant pour afficher la sortie spécifique à la cible.
- encodeUrl
- Boolean
true
HtmlAttributeEncode(String) pour encoder la sortie du flux ; sinon, false.
Exceptions
accessKey est plus long qu’un caractère.
Exemples
L’exemple de code suivant montre comment dériver une classe nommée CustomPageAdapter à partir de la PageAdapter classe et remplacer la RenderBeginHyperlink méthode.
RenderBeginHyperlink ajoute un attribut nommé src à un lien hypertexte, qui contient une référence à la page active. Tous les liens hypertexte affichés dans les pages auxquelles CustomPageAdapter il est attaché auront l’attribut 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
Remarques
La RenderBeginHyperlink méthode écrit une balise de lien hypertexte ouvrante. Lorsqu’il writer s’agit d’un HtmlTextWriter objet, cette balise a le format suivant :
<a href="
targetUrl
" accessKey="
accessKey
">
Notes pour les héritiers
Lorsque vous héritez de la PageAdapter classe, vous pouvez remplacer la RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) méthode pour écrire un autre format pour une balise de lien hypertexte ouvrante ou pour écrire des attributs de balise supplémentaires. Par exemple, la RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) méthode de base n’écrit pas d’attribut pour softkeyLabel.