Question

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;
    }
}
Was it helpful?

Solution 2

With the help of hint from @raja I found the solution. I updated Inherits property to Inherits="MyProjectNamespace.User_Controls.commentUI" and it worked.

OTHER TIPS

Try creating an ascx from scratch which shows the designer as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top