3

我在母版页的 contentplace 持有者中添加了 uc,但是如何在母版页 .cs 文件中实例化用户控件以使其在母版页加载时可见

4

3 回答 3

3

如果您将其添加到 ContentPlaceHolder,并且子页面将内容添加到该 ContentPlaceHolder - 您的用户控件将不再出现。IOW,您添加的控件只是默认的。

如果您希望它始终可见,只需将其添加到 ContentPlaceHolder 之外。

于 2008-12-02T22:03:54.577 回答
0

我不肯定,但我认为您需要使用 Page.LoadControl() 在运行时将用户控件正式加载到页面。

于 2008-12-02T22:12:31.097 回答
0

如果我没看错,您在母版页中有一个控件,需要从子页中引用它来更改它的可见性?还是我把事情搞错了?

无论如何,这就是我在 VB .Net 中通常的做法,移植应该不会太难 ;-)

在 aspx 页面中:

<%@ Reference Control="~/path/to/my/customControl.ascx" %>

在代码隐藏中:

Dim customControl As ASP.customcontrol_ascx = Master.FindControl("customControl")
If customControl IsNot Nothing Then
    ...
End If
于 2008-12-03T01:48:48.430 回答