By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

Accessing User Controls

P: 4
Hi All,

Before i get into things I'm writing in C# using VS2003 with framework 1.1.

I am having a problem accessing a user control in the code behind.

I'm using the user control for some repetitive code and i need to access a public property.

.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes\inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. public class client : System.Web.UI.Page
  2. {
  3. protected ACTIVITY Activity1;
  4. //...
  5.  
  6. private void Page_Load(object sender, System.EventArgs e)
  7. {
  8. Activity1.sPage = "Client";
  9. //...
  10.  
  11.  
.ascx.cs
Expand|Select|Wrap|Line Numbers
  1. private string _sPage;
  2. public string sPage
  3. {
  4.     get    {
  5.         return _sPage;
  6.         }
  7.     set {
  8.         sPage = value;
  9.         }
  10. }
  11.  
  12.  
Error when compiling;

The type or namespace name 'ACTIVITY' could not be found (are you missing a using directive or an assembly reference?)


Any help would be much appreciated!
Feb 11 '08 #1
Share this Question
Share on Google+
5 Replies


gpraghuram
Expert 100+
P: 1,275
I think this should have been under the .NET forum and not in C++ forum

Raghuram
Feb 11 '08 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
I am moving this to the .NET forum.
Feb 11 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
Hi All,

Before i get into things I'm writing in C# using VS2003 with framework 1.1.

I am having a problem accessing a user control in the code behind.

I'm using the user control for some repetitive code and i need to access a public property.

.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes\inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
...
The type or namespace name 'ACTIVITY' could not be found (are you missing a using directive or an assembly reference?)


Any help would be much appreciated!
Hi there!

When you register your user control:
[code=asp]
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes\inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
Make sure that your referencing the proper directory.
For starters you should be using forward-slash "/" instead of back-slash "\" in your Src string:
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes/inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
Make sure that you have a directory in your project "includes".
If need be refer to it using reference notation....eg:
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="~/includes/inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  

Cheers!

-Frinny
Feb 11 '08 #4

P: 4
Thanks for the response.

I have changed the / as you recommended and i do have the folder structure setup.

The user control does compile and run, the only problem i am having is accessing the public property from the code behind in the page that "includes" the user control.

If you have any ideas why this may be happening or a direction i could look to it would be much appreciated!

Cheers,
Michael



Hi there!

When you register your user control:
[code=asp]
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes\inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
Make sure that your referencing the proper directory.
For starters you should be using forward-slash "/" instead of back-slash "\" in your Src string:
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="includes/inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  
Make sure that you have a directory in your project "includes".
If need be refer to it using reference notation....eg:
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagPrefix="uc" TagName="Activity" Src="~/includes/inc_Activity.ascx"   %>
  2.  
  3. <uc:ACTIVITY id="Activity1" runat="server" src="blank.html"></uc:ACTIVITY>
  4.  

Cheers!

-Frinny
Feb 11 '08 #5

P: 4
Hi Guys,

I have found a work around for my problem. The purpose of my behind code reference needs was to find out what page was using the user control through the public property. I found that i can set the value of the property through the aspx page.

Expand|Select|Wrap|Line Numbers
  1. <uc:inc_Activity id="inc_Activity1" runat="server" src="blank.html" sPage="Client"></uc:inc_Activity>
in doing this i now have no need to reference the user control through the code behind.

Cheers,
Michael
Feb 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.