【问题标题】:Unable to access User Control's child controls from code behind无法从后面的代码访问用户控件的子控件
【发布时间】:2014-04-06 16:11:20
【问题描述】:

我正在尝试从后面的代码访问一些用户控件的子控件。其中一些正在工作,而另一些则没有。有缺陷的用户控件没有设计器文件。我想知道是不是这个原因?如果是这样,那么我无法从头开始创建一些控件,因为它们太复杂了,我的设计师在没有设计文件的情况下发送了它们,我无法在他出城时将代码返回给他进行更正。

此外,如果没有设计视图中的设计器文件,它们看起来很棒。但是当我写这样的东西时:

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;
    }
}

【问题讨论】:

    标签: c# asp.net .net webforms user-controls


    【解决方案1】:

    尝试从头开始创建一个 ascx 来显示设计器。

    【讨论】:

      【解决方案2】:

      在@raja 的提示的帮助下,我找到了解决方案。我将 Inherits 属性更新为 Inherits="MyProjectNamespace.User_Controls.commentUI" 并且成功了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-11
        • 1970-01-01
        • 2011-09-05
        • 1970-01-01
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多