HtmlAnchor.RenderAttributes Method (HtmlTextWriter)

 

Renders the HtmlAnchor control's attributes to the specified HtmlTextWriter object.

Namespace:   System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

Protected Overrides Sub RenderAttributes (
	writer As HtmlTextWriter
)

Parameters

writer
Type: System.Web.UI.HtmlTextWriter

The HtmlTextWriter that contains the output stream to render on the client.

Exception Condition
HttpException

The HRef contains a malformed URL.

If the value of the HRef property is a malformed URL, the RenderAttributes method throws an HttpException exception.

The following code example demonstrates how to override the RenderAttributes method in a custom server control so that specific title text, accessible as a ToolTip, is always displayed for the HtmlAnchor control.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>Custom HtmlAnchor - RenderAttributes - Visual Basic Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      Top of Page
      &lt;<aspSample:CustomHtmlAnchorRenderAttributes
           id="HtmlAnchor1"
           runat="server"
           name="HtmlAnchor1">HtmlAnchor1</aspSample:CustomHtmlAnchorRenderAttributes>&gt;

      <h3>Custom HtmlAnchor - RenderAttributes - Visual Basic Example</h3>
      <p>Place the mouse pointer over the HtmlAnchor1 tag (above). A Title attribute was added from within the RenderAttributes override method.</p>
      <p>Jump to <a href="#HtmlAnchor2">HtmlAnchor2</a> below.</p>

      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
      <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>

      <p>Jump to <a href="#HtmlAnchor1">HtmlAnchor1</a> above.</p>
      <p>&nbsp;</p>Bottom of Page
      &lt;<aspSample:CustomHtmlAnchorRenderAttributes
           id="HtmlAnchor2"
           runat="server"
           name="HtmlAnchor2">HtmlAnchor2</aspSample:CustomHtmlAnchorRenderAttributes>&gt;
    </form>
  </body>
</html>
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomHtmlAnchorRenderAttributes
        Inherits System.Web.UI.HtmlControls.HtmlAnchor

        Protected Overrides Sub RenderAttributes(ByVal writer As System.Web.UI.HtmlTextWriter)

            ' Call the base class's RenderAttributes method.
            MyBase.RenderAttributes(writer)

            ' Write out the HtmlAnchor control's Title tag.
            writer.Write(" Title=""Text from RenderAttributes.""")
        End Sub
    End Class
End Namespace

.NET Framework
Available since 1.1
Return to top
Show: