473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Accessing User Controls

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
5 2047
gpraghuram
1,275 Expert 1GB
I think this should have been under the .NET forum and not in C++ forum

Raghuram
Feb 11 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
I am moving this to the .NET forum.
Feb 11 '08 #3
Frinavale
9,735 Expert Mod 8TB
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
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
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

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

Similar topics

6
by: Earl Teigrob | last post by:
I am writing an application that dynamically loads user controls at run time based on user options. I would like to give my users the ability to build their own user controls and add them to my...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
3
by: Lynn | last post by:
Hello, I have some user controls on a page...one for the user to fill in name, address, etc., and the other for the user to fill in credit card information. I have built the user controls in...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
2
by: eagle | last post by:
How do I access a control, like a placeholder, from another page, or another user control that may be on the same page. For instance, I have a web page with 2 user controls. One user controls...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
8
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
2
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.