동적으로 페이지에 사용자 정의 컨트롤을로드하고 있습니다. 나는 보통 vb.net 사람이고 일반적으로 얻을 수 있지만 이것은 저를 곤란하게합니다. 그것을로드하기 전에 페이지에서 컨트롤로 변수를 전달하려고합니다. 내가 회전 목마 - guards.ascx에 다음과 같은 속성을 넣었습니다페이지에서 제어 할 변수 전달하기
Control webUserControl = (Control)Page.LoadControl("~/controls/carousel-guards.ascx");
phGuardsList.Controls.Add(webUserControl);
:
public String PostCode
{
get
{
return this.PostCode;
}
set
{
this.PostCode = value;
}
}
하지만이되어 있지 않은 것 같습니다
Heres는 내가 컨트롤을 호출하고있어 어디 나에게 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;
}
}
}
}
속성을 작성한 방법에서 문제가 발생하면 자체 참조됩니다. 이것을 피하기 위해 보통 접두사가 '_'인 내부 멤버를 씁니다. – AMember