我正在将用户控件动态加载到页面上。我通常是一个 vb.net 人,通常可以过得去,但这让我很难过。我试图在加载之前将变量从页面传递给控件。
这里是我调用控件的地方:
Control webUserControl = (Control)Page.LoadControl("~/controls/carousel-guards.ascx");
phGuardsList.Controls.Add(webUserControl);
我在 carousel-guards.ascx 上放置了以下属性:
public String PostCode
{
get
{
return this.PostCode;
}
set
{
this.PostCode = value;
}
}
但我似乎没有可用的 webUserControl.PostCode。
任何帮助将不胜感激
编辑 -当然,我必须引用控件。傻我!但是它不允许我用 carousel_guards 调用它:Error 96 The type or namespace name 'carousel_guards' could not be found (are you missing a using directive or an assembly reference?) C:\Development\Guards247\g247 Test\FindGuard.aspx.cs 197 13 g247 Test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace g247_Test.controls
{
public partial class carousel_guards : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public String PostCode
{
get
{
return this.PostCode;
}
set
{
this.PostCode = value;
}
}
}
}