PageAdapter.RenderBeginHyperlink Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Esegue il rendering di un tag collegamento ipertestuale di apertura nel flusso di risposta.
Overload
| Nome | Descrizione |
|---|---|
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
Esegue il rendering di un tag collegamento ipertestuale di apertura che include l'URL di destinazione per il flusso di risposta. |
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Esegue il rendering di un tag collegamento ipertestuale di apertura che include l'URL di destinazione e una chiave di accesso al flusso di risposta. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
Esegue il rendering di un tag collegamento ipertestuale di apertura che include l'URL di destinazione per il flusso di risposta.
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)
Parametri
- writer
- HtmlTextWriter
Oggetto HtmlTextWriter contenente i metodi per eseguire il rendering dell'output specifico della destinazione.
- encodeUrl
- Boolean
true per codificare HtmlAttributeEncode(String) l'output del flusso; in caso contrario, false.
Esempio
Nell'esempio di codice seguente viene illustrato come derivare una classe denominata CustomPageAdapter dalla PageAdapter classe ed eseguire l'override del RenderBeginHyperlink metodo . Il RenderBeginHyperlink metodo aggiunge un attributo denominato src a un collegamento ipertestuale, che contiene un riferimento alla pagina corrente. Tutti i collegamenti ipertestuali visualizzati nelle pagine alle quali CustomPageAdapter è collegato avranno l'attributo 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
Commenti
Il RenderBeginHyperlink metodo scrive un tag collegamento ipertestuale di apertura. Quando writer è HtmlTextWriter, questo tag ha il formato seguente:
<a href="
targetUrl
">
Note per gli eredi
Quando si eredita dalla PageAdapter classe , è possibile eseguire l'override del RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) metodo per scrivere un formato diverso per un tag collegamento ipertestuale di apertura o per scrivere attributi di tag aggiuntivi. Ad esempio, il RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) metodo di base non scrive un attributo per softkeyLabel.
Vedi anche
Si applica a
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
Esegue il rendering di un tag collegamento ipertestuale di apertura che include l'URL di destinazione e una chiave di accesso al flusso di risposta.
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)
Parametri
- writer
- HtmlTextWriter
Oggetto HtmlTextWriter contenente i metodi per eseguire il rendering dell'output specifico della destinazione.
- encodeUrl
- Boolean
true per codificare HtmlAttributeEncode(String) l'output del flusso; in caso contrario, false.
Eccezioni
accessKey è più lungo di un carattere.
Esempio
Nell'esempio di codice seguente viene illustrato come derivare una classe denominata CustomPageAdapter dalla PageAdapter classe ed eseguire l'override del RenderBeginHyperlink metodo .
RenderBeginHyperlink aggiunge un attributo denominato src a un collegamento ipertestuale, che contiene un riferimento alla pagina corrente. Tutti i collegamenti ipertestuali visualizzati nelle pagine alle quali CustomPageAdapter è collegato avranno l'attributo 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
Commenti
Il RenderBeginHyperlink metodo scrive un tag collegamento ipertestuale di apertura. Quando writer è un HtmlTextWriter oggetto, questo tag ha il formato seguente:
<a href="
targetUrl
" accessKey="
accessKey
">
Note per gli eredi
Quando si eredita dalla PageAdapter classe , è possibile eseguire l'override del RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) metodo per scrivere un formato diverso per un tag collegamento ipertestuale di apertura o per scrivere attributi di tag aggiuntivi. Ad esempio, il RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) metodo di base non scrive un attributo per softkeyLabel.