简体   繁体   English

如何使注册用户控件在C#中进行编码?

[英]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.

相关问题 如何在C#之后的代码中嵌入用户控件(ascx)? - How to embed user control (ascx) from code behind C#? 如何从C#背后的代码获取用户控件的更改的类名 - How to get changed class name of User Control from code behind C# 从 c# 中的代码访问用户控件属性和值 - Access user control properties and values from code behind in c# Visual Studio用户控件ASP,C#,代码隐藏问题 - Visual Studio User Control ASP, C#, Code Behind issue 如何在C#代码后面设置公共布尔值,请在.ascx用户控件中阅读? - How to set public bool value in C# code behind, read in .ascx User Control? 如何使用c#作为注册用户获取网站源代码? - How do I get the site source code as a registered user using c#? 执行 C# 代码并注册 JavaScript 启动脚本时,如何停止页面刷新? - How do I stop a page refresh when C# code behind is executed and a JavaScript startup script is registered? 如何在 Blazor 背后的 C# 代码中获取当前用户名? - How can I get the current user name in the C# code behind of Blazor? C#在透明控件后面获取像素 - C# Get pixels behind transparent control WPF C#MVC / MVP模式和用户控制代码背后 - WPF C# MVC/MVP pattern and user control code-behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM