如何获得注册的用户控件code在c#的背后? [英] How to get the registered user control to code behind in c#?
本文介绍了如何获得注册的用户控件code在c#的背后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须使用code注册页
I have register a page using the code
<%@ Register TagPrefix="uc1" TagName="side" Src="side.ascx" %>
和使用code称之为
<uc1:side ID="Side1" runat="server"></uc1:side>
我试图用
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Session["UName"] != null || Session["UName"] != " ")
{
Side1.Visible = true;
}
else
Side1.Visible = true;
}
但给错误
侧面1这个名字并不在目前的情况下存在。
The name 'Side1' does not exist in the current context .
我将如何通过访问使用保护的System.Web.UI'的'身份证'解决它。
How will i resolve it by accessing the 'id' using 'protected System.Web.UI'.
推荐答案
请检查您WebUserControl部分类定义的访问修饰符(即YourControl.ascx.cs文件),它应该是这样的:
Check the access modifier on your WebUserControl partial class definition (ie YourControl.ascx.cs file), it should be something like this:
public partial class SideControl : System.Web.UI.UserControl
{
// your code...
}
您可以找到有关访问修饰符的更多信息<一个href=\"http://stackoverflow.com/questions/614818/what-is-the-difference-between-public-private-protected-and-nothing\">here.
You can find more information about access modifiers here.
这篇关于如何获得注册的用户控件code在c#的背后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文