PageAdapter.RenderBeginHyperlink 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將開頭的超連結標記呈現至回應資料流中。
多載
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) |
呈現開頭的超連結標記到回應資料流,其中包含的目標 URL。 |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
呈現開頭的超連結標記到回應資料流,其中包含目標 URL 和便捷鍵 (Access Key)。 |
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
。
範例
下列程式碼範例示範如何從 類別衍生名為 CustomPageAdapter
的 PageAdapter 類別,並覆寫 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 會寫入開啟的超連結標記。 當 為 HtmlTextWriter 時 writer
,此標籤的格式如下:
<a href="
targetUrl
">
給繼承者的注意事項
當您繼承自 PageAdapter 類別時,可以覆寫 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 方法,以撰寫不同格式的開頭超連結標記或寫入其他標記屬性。 例如, RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) 基底方法不會寫入 的屬性 softkeyLabel
。
另請參閱
適用於
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)
呈現開頭的超連結標記到回應資料流,其中包含目標 URL 和便捷鍵 (Access Key)。
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
長度超過一個字元。
範例
下列程式碼範例示範如何從 類別衍生名為 CustomPageAdapter
的 PageAdapter 類別,並覆寫 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 會寫入開啟的超連結標記。 當 是 HtmlTextWriter 物件時 writer
,此標籤的格式如下:
<a href="
targetUrl
" accessKey="
accessKey
">
給繼承者的注意事項
當您繼承自 PageAdapter 類別時,可以覆寫 RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 方法,以撰寫不同格式的開頭超連結標記或寫入其他標記屬性。 例如, RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) 基底方法不會寫入 的屬性 softkeyLabel
。
另請參閱
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應