复制代码 代码如下:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UcB.ascx.cs" Inherits="UcB" %>
<asp:TextBox runat="server"></asp:TextBox>
复制代码 代码如下:
IGetValue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for IGetValue
/// </summary>
namespace Insus.NET
{
public interface IGetValue
{
string GetValue();
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class UcB : System.Web.UI.UserControl,IGetValue
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetValue()
{
return this.TextBox1.Text.Trim();
}
}
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="UcA.ascx" TagName="UcA" TagPrefix="uc1" %>
<%@ Register Src="UcB.ascx" TagName="UcB" TagPrefix="uc2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
<fieldset>
<legend>UcA
</legend>
<uc1:UcA runat="server" />
</fieldset>
<fieldset>
<legend>UcB
</legend>
<uc2:UcB runat="server" />
</fieldset>
</form>
</body>
</html>
复制代码 代码如下:
IGetUserControl.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
/// <summary>
/// Summary description for IGetUserControl
/// </summary>
namespace Insus.NET
{
public interface IGetUserControl
{
UserControl GetUc();
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page,IGetUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public UserControl GetUc()
{
return this.UcB1;
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class UcA : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
IGetUserControl ucb = (IGetUserControl)this.Page;
IGetValue value = (IGetValue)ucb.GetUc();
Response.Write("<scr" + "ipt>alert('" + value.GetValue() + "')</scr" + "ipt>");
}
}
新闻热点
疑难解答
图片精选