在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//用委托的方法实现 //控件代码 public delegate void DelegateFunction( string sPageTitle ); private DelegateFunction delegateChangePageTitle = null; public DelegateFunction ChangePT { get { return delegateChangePageTitle; }set { delegateChangePageTitle = value; } } protected void BtEdit_Click( object sender, EventArgs e ) { if ( delegateChangePageTitle != null ) delegateChangePageTitle( "Edit" ); } protected void BtAdd_Click( object sender, EventArgs e ) { if ( delegateChangePageTitle != null ) delegateChangePageTitle( "Add" ); } //页面 后台代码 protected void Page_Load( object sender, EventArgs e ) { myWebControl11.ChangePT = ChangePT; } void ChangePT( string sTmp ) { this.Page.Title = sTmp; } //页面 前代码 <%@ Register src="myWebControl.ascx" tagname="myWebControl1" tagprefix="uc1" %> <uc1:myWebControl1 ID="myWebControl11" runat="server" /> //用事件的方法实现 控件定义事件 页面实现 //控件代码 //定义一个不含数据的事件处理方法 public event EventHandler ClickModifyTitle; protected void btCreateValue_Click( object sender, EventArgs e ) { ClickModifyTitle( this, EventArgs.Empty ); } //页面后台代码 protected void Page_Load( object sender, EventArgs e ) { myWebControl11.ClickModifyTitle +=new EventHandler(myWebControl11_ClickModifyTitle); } void myWebControl11_ClickModifyTitle( object sender, EventArgs e ) { this.Page.Title += new Random().Next( 1000, 9999 ).ToString(); }
|
请发表评论