OnPreRender Method

CheckBoxList.OnPreRender Method

Configures the CheckBoxList control prior to rendering on the client.

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

protected internal override void OnPreRender(
	EventArgs e


Type: System.EventArgs
An EventArgs that contains the event data.

The OnPreRender method is used primarily by control developers in custom controls that derive from the CheckBoxList class. The OnPreRender method allows derived classes to handle the PreRender event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

The OnPreRender method performs any necessary prerendering steps prior to saving view state and rendering content for the CheckBoxList. The individual list items contained in the CheckBoxList control are initialized for rendering using the current AutoPostBack, CausesValidation, and ValidationGroup values.

Notes to Inheritors

When overriding OnPreRender in a derived class, be sure to call the base class's OnPreRender method so that registered delegates receive the event.

The following code example demonstrates how to override the CreateControlStyle method in a custom server control so that it always returns a new instance of the TableStyle class for the CheckBoxList.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Custom CheckBoxList - OnPreRender - C# Example</title>
    <form id="Form1" method="post" runat="server">
      <h3>Custom CheckBoxList - OnPreRender - C# Example</h3>

        id="CheckBoxList1" runat="server">
        <asp:ListItem Selected="True">Item 1</asp:ListItem>
        <asp:ListItem>Item 2</asp:ListItem>
        <asp:ListItem>Item 3</asp:ListItem>
        <asp:ListItem>Item 4</asp:ListItem>
        <asp:ListItem>Item 5</asp:ListItem>
        <asp:ListItem>Item 6</asp:ListItem>



using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class CustomCheckBoxListOnPreRender : CheckBoxList
        protected override void OnPreRender(EventArgs e)
            // Run the OnPreRender method on the base class.

            // Display the Calendar with a 3 point border.
            this.BorderWidth =  Unit.Point(3);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft