复制代码 代码如下:
UcB.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UcB.ascx.cs" Inherits="UcB" %>
<fieldset>
<legend>User control field</legend>
Catalog:
<asp:TextBox runat="server"></asp:TextBox><br />
Enabled:
<asp:CheckBox runat="server" /><br />
<asp:Button runat="server" Text="Process..." />
</fieldset>
复制代码 代码如下:
View Code
private Delegate _InsusData;
public Delegate InsusData
{
set
{
_InsusData = value;
}
}
复制代码 代码如下:
View Code
protected void Button1_Click(object sender, EventArgs e)
{
object[] data = new object[2];
data[0] = this.TextBox1.Text.Trim ();
data[1] = this.CheckBox1.Checked;
_InsusData.DynamicInvoke(data);
}
复制代码 代码如下:
View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UcB : System.Web.UI.UserControl
{
private Delegate _InsusData;
public Delegate InsusData
{
set
{
_InsusData = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
object[] data = new object[2];
data[0] = this.TextBox1.Text.Trim ();
data[1] = this.CheckBox1.Checked;
_InsusData.DynamicInvoke(data);
}
}
复制代码 代码如下:
PageB.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageB.aspx.cs" Inherits="PageB" %>
<%@ Register Src="UcB.ascx" TagName="UcB" TagPrefix="uc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
<uc1:UcB runat="server" />
<br />
<fieldset>
<legend>Page Content
</legend>
Show User Control Data:<br />
Catalog:
<asp:Label runat="server" Text=""></asp:Label>
<br />
Enabled:
<asp:CheckBox runat="server" Enabled="false" /><br />
</fieldset>
</form>
</body>
</html>
复制代码 代码如下:
private delegate void GetUserControlData(string catalog, bool isEnable);
复制代码 代码如下:
void ShowDataToPage(string catalog, bool isEnable)
{
this.Label1.Text = catalog;
this.CheckBox1.Checked = isEnable;
}
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
GetUserControlData obj = new GetUserControlData(ShowDataToPage);
this.UcB1.InsusData = obj;
}
复制代码 代码如下:
PageB.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PageB : System.Web.UI.Page
{
private delegate void GetUserControlData(string catalog, bool isEnable);
protected void Page_Load(object sender, EventArgs e)
{
GetUserControlData obj = new GetUserControlData(ShowDataToPage);
this.UcB1.InsusData = obj;
}
void ShowDataToPage(string catalog, bool isEnable)
{
this.Label1.Text = catalog;
this.CheckBox1.Checked = isEnable;
}
}
新闻热点
疑难解答
图片精选