Calendar.OnPreRender(EventArgs) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Raises the PreRender event.
protected:
override void OnPreRender(EventArgs ^ e);
protected public:
override void OnPreRender(EventArgs ^ e);
protected override void OnPreRender (EventArgs e);
protected internal override void OnPreRender (EventArgs e);
override this.OnPreRender : EventArgs -> unit
Protected Overrides Sub OnPreRender (e As EventArgs)
Protected Friend Overrides Sub OnPreRender (e As EventArgs)
The following code example demonstrates how to override the OnPreRender method so that it always displays a three-point border in a custom Calendar server control.
<%@ 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom Calendar - OnPreRender - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom Calendar - OnPreRender - C# Example</h3>
<aspSample:CustomCalendarOnPreRender
id="Calendar1"
runat="server" />
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<!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 Calendar - OnPreRender - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom Calendar - OnPreRender - VB.NET Example</h3>
<aspSample:CustomCalendarOnPreRender id="Calendar1" runat="server" />
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomCalendarOnPreRender : System.Web.UI.WebControls.Calendar
{
protected override void OnPreRender(System.EventArgs e)
{
// Run the OnPreRender method on the base class.
base.OnPreRender(e);
// Display the Calendar with a 3 point border.
this.BorderWidth = System.Web.UI.WebControls.Unit.Point(3);
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomCalendarOnPreRender
Inherits System.Web.UI.WebControls.Calendar
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
' Run the OnPreRender method on the base class.
MyBase.OnPreRender(e)
' Display the Calendar with a 3 point border.
Me.BorderWidth = System.Web.UI.WebControls.Unit.Point(3)
End Sub
End Class
End Namespace
Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.
The OnPreRender method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
When overriding OnPreRender(EventArgs) in a derived class, be sure to call the base class's OnPreRender(EventArgs) method so that registered delegates receive the event.
Product | Versions |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: