ImageButton.OnPreRender Method (EventArgs)


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

Determines whether the image has been clicked 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 object that contains the event data.

The OnPreRender method is used primarily by control developers when deriving a custom class from the ImageButton control.

The following code example demonstrates how to override the OnPreRender method so that it always displays a thin border in a custom ImageButton server control.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. The first part of the code sample must be copied into an empty text file that has an .aspx extension. The second part must be in a .cs file (for C#) or a .vb file (for Visual Basic). For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ 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"
<html xmlns="" >
        <title>Custom ImageButton - OnPreRender - C# Example</title>
    <script runat="server">
      void ImageButton1_Command(Object sender, CommandEventArgs e) 
        // Redirect to the Microsoft home page.
        <form id="Form1" method="post" runat="server">
            <h3>Custom ImageButton - OnPreRender - C# Example</h3>

              AlternateText="Microsoft Home" 
              ImageUrl="" />

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

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

            // Always display the ImageButton with a thin border.
            this.BorderWidth =  Unit.Point(1);

.NET Framework
Available since 1.1
Return to top