微软专家:ASP.Net页面中引用了Web 窗体用户控件,如何对其进行Code-Behind处理!
Web 窗体用户控件文件:WebUserControl1.ascx;WebUserControl1.ascx.cs
ASP.Net 页面文件:WebForm1.aspx;WebForm1.aspx.cs
我在WebForm1.aspx中加入了下列的语句:
<%@ Register TagPrefix="XWUC" TagName="demo" Src="WebUserControl1.ascx" %>
.....
<XWUC:demo id="wuc1" runat="server">
<asp:Panel ID="wucContainer" Runat="server"></asp:Panel>
<!--//
这里之所以有一个Panel控件,是我在后台加入WebUserControl1控件地时候,系统
提示我说:Controls.Add() 必须将控件放在有 runat="server" 标记的服务器控件中!
//--!>
我在WebForm1.aspx.cs 中加入下面的语句:
protected System.Web.UI.WebControls.Panel wucContainer;
protected WebUserControl1 wuc1;
private void Page_Load(object sender, System.EventArgs e)
{
wuc1 = (WebUserControl1)LoadControl("WebUserControl1.ascx");
wucContainer.Controls.Add(wuc1);
wuc1.text = DateTime.Now.ToString();
}
于是发现:页面上出现了2个WebUserControl,而我本意是想让我在后台声明的wuc1来处理前端页面中我写的标记<XWUC:demo>,而不是再添加一个!
请问,关于WebUserControl如何在页面以标记引用的时候,可以通过后台代码进行属性设置,事件处理!?