PageAdapter.RenderBeginHyperlink Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Renderuje otwierający tag hiperłącza do strumienia odpowiedzi.
Przeciążenia
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
Renderuje otwierający tag hiperłącza, który zawiera docelowy adres URL strumienia odpowiedzi. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Renderuje otwierający tag hiperłącza, który zawiera docelowy adres URL i klucz dostępu do strumienia odpowiedzi. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
Renderuje otwierający tag hiperłącza, który zawiera docelowy adres URL strumienia odpowiedzi.
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)
Parametry
- writer
- HtmlTextWriter
Metody HtmlTextWriter zawierające renderowanie danych wyjściowych specyficznych dla elementu docelowego.
- encodeUrl
- Boolean
true
do kodowania HtmlAttributeEncode(String) strumienia danych wyjściowych; w przeciwnym razie false
.
Przykłady
W poniższym przykładzie kodu pokazano, jak utworzyć klasę o nazwie CustomPageAdapter
z PageAdapter klasy i zastąpić metodę RenderBeginHyperlink . Metoda RenderBeginHyperlink dodaje atrybut o nazwie src
do hiperłącza, który zawiera odwołanie do bieżącej strony. Wszystkie hiperlinki renderowane na stronach, do których CustomPageAdapter
jest dołączony, będą miały src
atrybut .
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
Uwagi
Metoda RenderBeginHyperlink zapisuje otwierający tag hiperłącza. Gdy writer
ma wartość HtmlTextWriter, ten tag ma następujący format:
<a href="
targetUrl
">
Uwagi dotyczące dziedziczenia
Gdy dziedziczysz z PageAdapter klasy, możesz zastąpić metodę RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) , aby napisać inny format dla otwierającego tagu hiperłącza lub napisać dodatkowe atrybuty tagu. Na przykład metoda podstawowa RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) nie zapisuje atrybutu dla softkeyLabel
.
Zobacz też
Dotyczy
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
Renderuje otwierający tag hiperłącza, który zawiera docelowy adres URL i klucz dostępu do strumienia odpowiedzi.
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)
Parametry
- writer
- HtmlTextWriter
Metody HtmlTextWriter zawierające renderowanie danych wyjściowych specyficznych dla elementu docelowego.
- encodeUrl
- Boolean
true
do kodowania HtmlAttributeEncode(String) strumienia danych wyjściowych; w przeciwnym razie false
.
- accessKey
- String
Wartość, która ma zostać przypisana String do accessKey
atrybutu linku do utworzenia.
Wyjątki
accessKey
jest dłuższy niż jeden znak.
Przykłady
W poniższym przykładzie kodu pokazano, jak utworzyć klasę o nazwie CustomPageAdapter
z PageAdapter klasy i zastąpić metodę RenderBeginHyperlink . RenderBeginHyperlink Dodaje atrybut o nazwie src
do hiperłącza, który zawiera odwołanie do bieżącej strony. Wszystkie hiperlinki renderowane na stronach, do których CustomPageAdapter
jest dołączony, będą miały src
atrybut .
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
Uwagi
Metoda RenderBeginHyperlink zapisuje otwierający tag hiperłącza. Gdy writer
jest obiektem HtmlTextWriter , ten tag ma następujący format:
<a href="
targetUrl
" accessKey="
accessKey
">
Uwagi dotyczące dziedziczenia
Gdy dziedziczysz z PageAdapter klasy, możesz zastąpić metodę RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) , aby napisać inny format dla otwierającego tagu hiperłącza lub napisać dodatkowe atrybuty tagu. Na przykład metoda podstawowa RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) nie zapisuje atrybutu dla softkeyLabel
.
Zobacz też
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla