用户控制页面:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:CheckBox id ="MyCheckBox" runat="server"/>
后面的代码:
using System;
public partial class WebUserControl : System.Web.UI.UserControl
{
private string _myProperty;
public string MyProperty
{
get { return this._myProperty; }
set { this._myProperty = value; }
}
public bool IsChecked
{
get
{
return this.MyCheckBox.Checked;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
在您的转发器页面:
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc1" TagName="WebUserControl" %>
中继器内部:
<asp:Repeater id="repeaterCategories" runat="server">
<ItemTemplate>
...
<uc1:WebUserControl runat="server" ID="WebUserControl" MyProperty="My_ID_Value" />
...
</ItemTemplate>
</asp:Repeater>
您可以在 Web 用户控件上添加任意数量的属性。