【发布时间】:2014-08-05 16:13:08
【问题描述】:
您好,我有一个 aspx 页面 ResourceCategories.aspx,我在其中注册了两个用户控件:
我的问题是我必须访问用户控件 2)downloadPopUp in 1)ctlCategories on btn click 事件。
protected void btnArrow_Click(object sender, EventArgs e)
{
//lblMessages.Text = String.Empty;
try
{
var userControl = FindControl("ctlPopUp") as UserControl;
}
catch (Exception ex)
{
}
}
我仍然将 usercontrol 值设为 null。如何访问它?我只能访问我在第一个用户控件中注册的第二个用户控件,但不能从主 aspx 页面访问。即;在 ResourceCenter.ascx 中注册。我不想将用户控件嵌套在另一个用户控件中。有没有办法?
【问题讨论】:
-
我认为你需要改写你的问题,你描述什么叫做什么是非常混乱的部分。此外,使用
try/catch捕获所有异常通常是不受欢迎的,尤其是当您的 catch 块为空时。 -
我不确定我是否理解... aspx 和 c# 代码是否显示相同的页面?如果是这种情况,你不需要使用
FindControl,你应该在后面的代码上有一个名为 ctlCategories 和 ctlPopUp 的属性 -
否...代码在 ResourceCenter.ascx.cs 页面中。我尝试使用类访问 ctlpopup var userControl = ((ResourceCategories)this.Page).FindControl("ctlPopUp") as UserControl;我得到的值仍然是 null
-
var userControl=ctlPopUp有效吗?正如我上面解释的那样,您需要更好地解释您的问题,以便清楚哪些代码与哪个文件一起使用。 -
OKie Mason... 我会试着解释一下。我必须尽快完成。 ASPX 主页面 ResourceCategories.aspx 有两个用户控件 ctlCategories(即 ResourceCenter.ascx usercontrol)和 ctlPopUp(DownLoadList.ascx usercontrol) 我需要的是 ResourceCenter.ascx 有一个按钮控件 btnArrow。点击 btnArrow_Click 我喜欢访问 ctlPopUp。希望它清楚