PageAdapter.RenderBeginHyperlink Method (HtmlTextWriter, String, Boolean, String, String)
Assembly: System.Web (in system.web.dll)
public: virtual void RenderBeginHyperlink ( HtmlTextWriter^ writer, String^ targetUrl, bool encodeUrl, String^ softkeyLabel, String^ accessKey )
public void RenderBeginHyperlink ( HtmlTextWriter writer, String targetUrl, boolean encodeUrl, String softkeyLabel, String accessKey )
public function RenderBeginHyperlink ( writer : HtmlTextWriter, targetUrl : String, encodeUrl : boolean, softkeyLabel : String, accessKey : String )
Not applicable.
Parameters
- writer
The HtmlTextWriter containing methods to render the target-specific output.
- targetUrl
The String value holding the target URL of the link.
- encodeUrl
true to use HtmlAttributeEncode to encode the stream output; otherwise, false.
- softkeyLabel
The String value to use as a soft key label.
- accessKey
The String value to assign to the accessKey attribute of the link to create.
The RenderBeginHyperlink method writes an opening hyperlink tag. When writer is an HtmlTextWriter object, this tag has the following format:
<a href="
targetUrl
" accessKey="
accessKey
">
The following code example demonstrates how to derive a class named CustomPageAdapter from the PageAdapter class and override the RenderBeginHyperlink method. RenderBeginHyperlink adds an attribute named src to a hyperlink, which contains a reference to the current page. All hyperlinks rendered in pages to which CustomPageAdapter is attached will have the src attribute.
import System.*;
import System.IO.*;
import System.Web.*;
import System.Web.UI.*;
import System.Web.UI.Adapters.*;
// A derived PageAdapter class.
public class CustomPageAdapter extends PageAdapter
{
// Override RenderBeginHyperlink to add an attribute that
// references the referring page.
public void RenderBeginHyperlink(HtmlTextWriter writer, String targetUrl,
boolean encodeUrl, String softkeyLabel, String accessKey)
{
String url = null;
// Add the src attribute, if referring page URL is available.
if (this.get_Page() != null && this.get_Page().get_Request() != null
&& this.get_Page().get_Request().get_Url() != null) {
url = this.get_Page().get_Request().get_Url().get_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");
} //RenderBeginHyperlink
} //CustomPageAdapter
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.