共用方式為


Calendar.OnPreRender(EventArgs) 方法

定義

引發 PreRender 事件。

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)

參數

e
EventArgs

包含事件資料的 EventArgs

範例

下列程式碼範例示範如何覆寫 OnPreRender 方法,使其一律在自訂 Calendar 伺服器控制項中顯示三點框線。

<%@ 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

備註

引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件

OnPreRender 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

當在衍生類別中覆寫 OnPreRender(EventArgs) 時,請確定呼叫基底類別的 OnPreRender(EventArgs) 方法,使已註冊的委派能接收到事件。

適用於