PageAdapter.RenderBeginHyperlink 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
呈現回應數據流的開頭超連結標記。
多載
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
轉譯開頭的超連結標記,其中包含響應數據流的目標 URL。 |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
轉譯開頭的超連結標記,其中包含目標 URL 和響應數據流的存取密鑰。 |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)
轉譯開頭的超連結標記,其中包含響應數據流的目標 URL。
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)
參數
- writer
- HtmlTextWriter
HtmlTextWriter 包含用來呈現目標特定輸出的方法。
- encodeUrl
- Boolean
true
使用 HtmlAttributeEncode(String) 來編碼數據流輸出;否則,false
。
範例
下列程式代碼範例示範如何從 PageAdapter 類別衍生名為 CustomPageAdapter
的類別,並覆寫 RenderBeginHyperlink 方法。
RenderBeginHyperlink 方法會將名為 src
的屬性新增至超連結,其中包含目前頁面的參考。 在附加 CustomPageAdapter
的頁面中轉譯的所有超鏈接都會有 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
備註
RenderBeginHyperlink 方法會寫入開頭的超連結標記。 當 writer
HtmlTextWriter時,此標籤格式如下:
<a href="
targetUrl
">
給繼承者的注意事項
當您繼承自 PageAdapter 類別時,可以覆寫 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 方法,為開啟的超連結標記撰寫不同的格式,或撰寫其他標記屬性。 例如,RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 基底方法不會為 softkeyLabel
撰寫屬性。
另請參閱
適用於
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
轉譯開頭的超連結標記,其中包含目標 URL 和響應數據流的存取密鑰。
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)
參數
- writer
- HtmlTextWriter
HtmlTextWriter 包含用來呈現目標特定輸出的方法。
- encodeUrl
- Boolean
true
使用 HtmlAttributeEncode(String) 來編碼數據流輸出;否則,false
。
例外狀況
accessKey
長度超過一個字元。
範例
下列程式代碼範例示範如何從 PageAdapter 類別衍生名為 CustomPageAdapter
的類別,並覆寫 RenderBeginHyperlink 方法。
RenderBeginHyperlink 會將名為 src
的屬性新增至超連結,其中包含目前頁面的參考。 在附加 CustomPageAdapter
的頁面中轉譯的所有超鏈接都會有 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
備註
RenderBeginHyperlink 方法會寫入開頭的超連結標記。 當 writer
是 HtmlTextWriter 物件時,此標籤格式如下:
<a href="
targetUrl
" accessKey="
accessKey
">
給繼承者的注意事項
當您繼承自 PageAdapter 類別時,可以覆寫 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 方法,為開啟的超連結標記撰寫不同的格式,或撰寫其他標記屬性。 例如,RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 基底方法不會為 softkeyLabel
撰寫屬性。