class is not visible

L

Lubomir

Hi,

I want to use a user control on my page. I want to reference to the control
class from the page’s code-behind.

I registered the control:

<%@ Register TagPrefix="uc1" TagName="ButtonList" Src="ButtonList.ascx" %>

The control is used in HTML code:
<uc1:ButtonList id="ButtonList" runat="server"></uc1:ButtonList>

In code-behind I access the control’s class:

public ButtonList initialStrip;

However, I get compiler error, namespace name “ButtonList†could not be found.


I am using the following directives in control’s aspx file:
<%@ Control Language="C#" Inherits="ButtonListCtrl.ButtonList"
Codebehind="ButtonList.ascx"%>

Control’s code-behind is:
namespace ButtonListCtrl
{
public class ButtonList : System.Web.UI.UserControl
{
…
}
}

What is needed to do to make this class visible from code-behind of the
container page?

Thank you for help.
Lubomir
 
J

John Saunders

Lubomir said:
Hi,

I want to use a user control on my page. I want to reference to the
control
class from the page's code-behind.

I registered the control:

<%@ Register TagPrefix="uc1" TagName="ButtonList" Src="ButtonList.ascx" %>

The control is used in HTML code:
<uc1:ButtonList id="ButtonList" runat="server"></uc1:ButtonList>

In code-behind I access the control's class:

public ButtonList initialStrip;

However, I get compiler error, namespace name "ButtonList" could not be
found.


I am using the following directives in control's aspx file:
<%@ Control Language="C#" Inherits="ButtonListCtrl.ButtonList"
Codebehind="ButtonList.ascx"%>

Control's code-behind is:
namespace ButtonListCtrl
{
public class ButtonList : System.Web.UI.UserControl
{
.
}
}

What is needed to do to make this class visible from code-behind of the
container page?

Reference it as Button:ListCtrl.ButtonList.

John Saunders
 
J

John Saunders

Lubomir said:
It didn't help. I get an error: Invalid token ":"

I meant:

public ButtonListCtrl.ButtonList initialStrip;

The colon was a typo.

John Saunders
 
M

Mike MacMillan

Lubmomir,
you can only reference your control in the ButtonListCtrl.ButtonList
format if the ButtonListCtrl is in a known assembly (ie, your control is
compiled into an assembly it can reference). if your control is simply a
webcontrol (.ascx) file, you cannot reference its custom properties in a
code behind...unless the control inherits from a common interface that
resides in an assembly. ex:

public class ButtonListCtrl : WebControl, IButtonList {
...
}

otherwise, you will only be able to reference your control as a
WebControl...

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top