[英]How to get the registered user control to code behind in c#?
I have register a page using the code 我已经使用代码注册了页面
<%@ Register TagPrefix="uc1" TagName="side" Src="side.ascx" %>
And called this by using the code 并使用代码将此称为
<uc1:side ID="Side1" runat="server"></uc1:side>
And i tried to acces the ID="Side1" in behind by using 我试图通过使用在后面访问ID =“ Side1”
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;
}
but gives the error 但是给出了错误
The name 'Side1' does not exist in the current context .
名称“ Side1”在当前上下文中不存在。
How will i resolve it by accessing the 'id' using 'protected System.Web.UI'. 如何使用“ protected System.Web.UI”访问“ id”来解决该问题。
Check the access modifier on your WebUserControl partial class definition (ie YourControl.ascx.cs file), it should be something like this: 检查您的WebUserControl子类定义(即YourControl.ascx.cs文件)上的访问修饰符,它应该是这样的:
public partial class SideControl : System.Web.UI.UserControl
{
// your code...
}
You can find more information about access modifiers here . 您可以在此处找到有关访问修饰符的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.