[英]accessing web user controls (their id's) from code behind of a user control item
[英]Unable to access User Control's child controls from code behind
我正在尝试从后面的代码访问某些用户控件的子控件。 其中一些正在工作,而另一些则没有。 错误的用户控件没有设计器文件。 我想知道这是为什么吗? 如果是这样,那么我就不能从头开始创建某些控件,因为它们太复杂了,我的设计师在没有设计师文件的情况下就发送了这些控件,而且当他出城时我也无法将代码退还给他。
此外,在设计视图中没有设计器文件的情况下,它们看起来很棒。 但是当我写这样的东西:
Button1.Visible=false;
这表明Button1在当前上下文中不存在。 请告诉我该如何解决?
以下是错误的用户控件之一的标记:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="commentUI.ascx.cs" Inherits="commentUI" %>
<asp:Button ID="Button1" runat="server" Text="Button" />
代码隐藏文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class commentUI : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Visible = false;
}
}
尝试从头开始创建一个ascx,它也可以显示设计器。
借助@raja的提示,我找到了解决方案。 我将Inherits
属性更新为Inherits="MyProjectNamespace.User_Controls.commentUI"
并成功运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.