HtmlAnchor.OnPreRender Method (EventArgs)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Raises the PreRender event and registers client script for generating a postback.

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

protected internal override void OnPreRender(
	EventArgs e
)

Parameters

e
Type: System.EventArgs

An EventArgs that contains the event data.

The following code example demonstrates how to override the OnPreRender method so that it always displays a Title tag in a custom HtmlAnchor server control.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" 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 - OnPreRender - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      Top of Page
      &lt;<aspSample:CustomHtmlAnchorOnPreRender
           id="HtmlAnchor1"
           runat="server"
           name="HtmlAnchor1">HtmlAnchor1</aspSample:CustomHtmlAnchorOnPreRender>&gt;

      <h3>Custom HtmlAnchor - OnPreRender - C# Example</h3>
      <p>&nbsp;</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:CustomHtmlAnchorOnPreRender
           id="HtmlAnchor2"
           runat="server"
           name="HtmlAnchor2">HtmlAnchor2</aspSample:CustomHtmlAnchorOnPreRender>&gt;
    </form>
  </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class CustomHtmlAnchorOnPreRender : System.Web.UI.HtmlControls.HtmlAnchor
    {
        protected override void OnPreRender(System.EventArgs e)
        {
            // Call the base OnPreRender method.
            base.OnPreRender(e);

            // Write out the HtmlAnchor control's Title tag.
            this.Title = "Text from OnPreRender.";
        }
    }
}

.NET Framework
Available since 1.1
Return to top
Show: