473,671 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing User Controls

4 New Member
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 2065
gpraghuram
1,275 Recognized Expert Top Contributor
I think this should have been under the .NET forum and not in C++ forum

Raghuram
Feb 11 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
I am moving this to the .NET forum.
Feb 11 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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
michael234
4 New Member
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
michael234
4 New Member
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
2566
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 user control folder so that they can be selected and loaded at run time also. These new controls will need to have access to many of the classes with there properties and methods within the complied code. Is this possible? This seems to be the...
1
3126
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 elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
3
1301
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 exactly the same way in that in the code behind page, I am using: Public Property sCVCCode() As String Get
6
2244
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 Public, I can access them, but the next time the controls are manipulated in the design mode, they are converted back to Protected. Is there an obvious/easy way around this? Thanks.
2
1705
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 = LoadControl("../UserControls/ISJob/uctlJobGeneral.ascx");
2
2050
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 contains a placeholder to that will contain any error messages to be displayed. If the first user control creates an error, I want to be able to push that error to the 2nd control to display it at the placeholder. I have tried Dim ctrlError as...
4
1681
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 Page_Load(s as Object, e as EventArgs) LoadControl("x.ascx")
7
2129
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. The number of controls that are displayed can be adjusted by the user so the controls are added to the page dynamically using the following code in the Page_Init event handler: For i as Integer = 1 to NumberOfControls
8
2178
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
3043
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 form Main Tab Control - This contains Main Tab Pages.
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.