ImageButton.OnPreRender Method
.NET Framework 3.0
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)
Assembly: System.Web (in system.web.dll)
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.
Note: |
|---|
| 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 Page Code Model. |
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" 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 ImageButton - OnPreRender - VJ# Example</title>
<script runat="server">
void ImageButton1_Command(Object sender, CommandEventArgs e)
{
// Redirect to the Microsoft home page.
get_Response().Redirect("http://www.microsoft.com/");
} //ImageButton1_Command
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ImageButton - OnPreRender - VJ# Example</h3>
<aspSample:CustomImageButtonOnPreRender
id="ImageButton1"
runat="server"
OnCommand="ImageButton1_Command"
AlternateText="Microsoft Home"
ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />
</form>
</body>
</html>
...
package Samples.AspNet.JSL.Controls;
public class CustomImageButtonOnPreRender
extends System.Web.UI.WebControls.ImageButton
{
protected void OnPreRender(System.EventArgs e)
{
// Run the OnPreRender method on the base class.
super.OnPreRender(e);
// Always display the ImageButton with a thin border.
this.set_BorderWidth(System.Web.UI.WebControls.Unit.Point(1));
} //OnPreRender
} //CustomImageButtonOnPreRender
Community Additions
ADD
Show:
Note: