[asp.net] 页面生命周期中注册事件与重写页面方法
重写页面方法
一个自定义控件继承自ImageButton控件,在控件render之前设置其ImageUrl属性:protected override void OnPreRender( EventArgs e )
{
// setup inital image state
this.ImageUrl = PageContext.Theme.GetCollapsiblePanelImageURL( PanelID, DefaultState );
UpdateAttachedVisibility();
base.OnPreRender( e );
}
{
// setup inital image state
this.ImageUrl = PageContext.Theme.GetCollapsiblePanelImageURL( PanelID, DefaultState );
UpdateAttachedVisibility();
base.OnPreRender( e );
}
注册事件
某用户控件中包含一个asp:Label,在用户控件render之前设置该Label的Text属性:public ForumWelcome()
{
this.PreRender += new EventHandler( ForumWelcome_PreRender );
}
void ForumWelcome_PreRender( object sender, EventArgs e )
{
// 设置用户控件页面上Label的Text值
TimeNow.Text = String.Format( PageContext.Localization.GetText( "Current_Time" ),
YafDateTime.FormatTime( DateTime.Now ) );
}
{
this.PreRender += new EventHandler( ForumWelcome_PreRender );
}
void ForumWelcome_PreRender( object sender, EventArgs e )
{
// 设置用户控件页面上Label的Text值
TimeNow.Text = String.Format( PageContext.Localization.GetText( "Current_Time" ),
YafDateTime.FormatTime( DateTime.Now ) );
}