PageAdapter.RenderBeginHyperlink Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vykreslí levou značku hypertextového odkazu do streamu odpovědí.
Přetížení
| Name | Description |
|---|---|
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
Vykreslí počáteční značku hypertextového odkazu, která obsahuje cílovou adresu URL streamu odpovědi. |
| RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Vykreslí počáteční značku hypertextového odkazu, která obsahuje cílovou adresu URL a přístupový klíč ke streamu odpovědí. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
Vykreslí počáteční značku hypertextového odkazu, která obsahuje cílovou adresu URL streamu odpovědi.
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
Obsahující HtmlTextWriter metody pro vykreslení výstupu specifického pro cíl.
- encodeUrl
- Boolean
true
HtmlAttributeEncode(String) pro kódování výstupu datového proudu, jinak . false
Příklady
Následující příklad kódu ukazuje, jak odvodit třídu pojmenovanou CustomPageAdapter z PageAdapter třídy a přepsat metodu RenderBeginHyperlink . Metoda RenderBeginHyperlink přidá atribut pojmenovaný src do hypertextového odkazu, který obsahuje odkaz na aktuální stránku. Všechny hypertextové odkazy vykreslené na stránkách, ke kterým CustomPageAdapter je připojeno, budou mít src atribut.
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
Poznámky
Metoda RenderBeginHyperlink zapíše počáteční značku hypertextového odkazu. Pokud writer je HtmlTextWritertato značka, má následující formát:
<a href="
targetUrl
">
Poznámky pro dědice
Když dědíte z PageAdapter třídy, můžete přepsat metodu RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) pro zápis jiného formátu pro levou značku hypertextového odkazu nebo napsat další atributy značky. Například RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) základní metoda nezapisuje atribut pro softkeyLabel.
Viz také
Platí pro
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
Vykreslí počáteční značku hypertextového odkazu, která obsahuje cílovou adresu URL a přístupový klíč ke streamu odpovědí.
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
Obsahující HtmlTextWriter metody pro vykreslení výstupu specifického pro cíl.
- encodeUrl
- Boolean
true
HtmlAttributeEncode(String) pro kódování výstupu datového proudu, jinak . false
- accessKey
- String
Hodnota String , která se má přiřadit k accessKey atributu odkazu, který se má vytvořit.
Výjimky
accessKey je delší než jeden znak.
Příklady
Následující příklad kódu ukazuje, jak odvodit třídu pojmenovanou CustomPageAdapter z PageAdapter třídy a přepsat metodu RenderBeginHyperlink .
RenderBeginHyperlink přidá atribut pojmenovaný src do hypertextového odkazu, který obsahuje odkaz na aktuální stránku. Všechny hypertextové odkazy vykreslené na stránkách, ke kterým CustomPageAdapter je připojeno, budou mít src atribut.
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
Poznámky
Metoda RenderBeginHyperlink zapíše počáteční značku hypertextového odkazu. Pokud writer je HtmlTextWriter objekt, má tato značka následující formát:
<a href="
targetUrl
" accessKey="
accessKey
">
Poznámky pro dědice
Když dědíte z PageAdapter třídy, můžete přepsat metodu RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) pro zápis jiného formátu pro levou značku hypertextového odkazu nebo napsat další atributy značky. Například RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) základní metoda nezapisuje atribut pro softkeyLabel.