现在的位置: 首页 > 综合 > 正文

[asp.net] 页面生命周期中注册事件与重写页面方法

2013年05月16日 ⁄ 综合 ⁄ 共 643字 ⁄ 字号 评论关闭
文章目录

重写页面方法

一个自定义控件继承自ImageButton控件,在控件render之前设置其ImageUrl属性:

protected override void OnPreRender( EventArgs 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 ) );
    
}

抱歉!评论已关闭.