[英]Why I can't access to my own User Control?
Following this guideline , I've created my own User Control and registered into the webconfig: 按照此指南 ,我创建了自己的用户控件并注册到了webconfig中:
public partial class usercontrols_LinkBoxAttivita : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public int MyProp { get; set; }
}
On Home.ascx I've included this: 在Home.ascx上,我包含了以下内容:
<myOwnControls:LinkBoxAttivita ID="LinkBoxAttivita1" runat="server" />
It works, and it is rendered. 它起作用,并且被渲染。 Now, why on the codebehind of Home.ascx.cs I can't access to it?
现在,为什么在Home.ascx.cs的代码背后我无法访问它?
LinkBoxAttivita1 seems unexistent. LinkBoxAttivita1似乎不存在。 I want to set from here the MyProp value to it.
我想从这里设置MyProp值。
This is how I registered it: 这是我注册的方式:
<system.web>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add tagPrefix="myOwnControls" tagName="LinkBoxAttivita" src="~/usercontrols/LinkBoxAttivita.ascx" />
</controls>
</pages>
</system.web>
Have you dragged the UserControl
to the designer? 您是否已将
UserControl
拖到设计器中? Otherwise the designer won't create the @Register
directive, which is required for the page to recognize the user control. 否则,设计人员将不会创建
@Register
指令,该指令是页面识别用户控件所必需的。
How to: Include a User Control in an ASP.NET Web Page 如何:在ASP.NET网页中包含用户控件
Example (from MSDN): 示例(来自MSDN):
<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc" TagName="Spinner"
Src="~/Controls/Spinner.ascx" %>
<html>
<body>
<form runat="server">
<uc:Spinner id="Spinner1"
runat="server"
MinValue="1"
MaxValue="10" />
</form>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.