I am trying to access some of the user controls' child controls from code behind. Some of them is working while others not. Faulty user controls don't have designer files. I want to know if this is the reason? If so then I can't create some of the controls from scratch as they are too complex and my designer sent them without designer file and I can't give him back the code to correct as he went outside town.
Moreover they are looking great without designer file in design view. But when I write something like this:
Button1.Visible=false;
It's showing Button1 does not exist in current context. Please tell me how to solve this?
Following is the markup of one of the faulty User-Control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="commentUI.ascx.cs" Inherits="commentUI" %>
<asp:Button ID="Button1" runat="server" Text="Button" />
Code-Behind file:
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,它也可以显示设计器。
With the help of hint from @raja I found the solution. I updated Inherits
property to Inherits="MyProjectNamespace.User_Controls.commentUI"
and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.