473,666 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to reference Webcontrols and HtmlControls in .aspx page from within .ascx user control

dh
As a simple example, I can't seem to be able to reference a label
called "lblOutput" that exists in my test.aspx page from within a User
control, TestControl.asc x. I am stumped. Any help is appreciated.

Thanks.
The error I get when I compile is...

"The type or namespace name 'lblOutput' could not be found (are you
missing a using directive or an assembly reference?)"
[ TestControl.asc x ]
-----------------------------------
<%@ Control Language="c#" AutoEventWireup ="false"
Codebehind="Tes tControl.ascx.c s" Inherits="Test. TestControl"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>

[ TestControl.asc x.cs ]
--------------------------------------
namespace Internet
{
using System;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

public abstract class TestControl : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, System.EventArg s e)
{
lblOutput.Text = "am i here?";
}
}
}

[ Test.aspx ]
--------------------------------------

<%@ Page language="c#" Codebehind="Tes t.aspx.cs"
AutoEventWireup ="false" Inherits="Inter net.Test" %>
<%@ Register TagPrefix="uc1" TagName="TestCo ntrol"
Src="TestContro l.ascx" %>
<HTML>
<body
<form id="Test" method="post" runat="server">
<asp:Label id=lblOutput runat="server"> Label</asp:Label>
<uc1:TestContro l id=TestControl
runat="server"> </uc1:TestControl >
</form>
</body>
</HTML>
[ Test.aspx.cs ]
--------------------------------------
using System;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace Internet
{
public class Test : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l lblOutput;

private void Page_Load(objec t sender, System.EventArg s e)
{
lblOutput.Text = "";
}
}
}
Jul 21 '05 #1
0 3494

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9771
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520" AutoPostBackOnNodeMove="false" DragAndDropEnabled="true" NodeEditingEnabled="False" KeyboardEnabled="true" CssClass="TreeView" NodeCssClass="TreeNode" SelectedNodeCssClass="SelectedTreeNode" HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
1
3013
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have access to the methods and properties from the Page_Load, no problem there. But as soon as I want access to the user control from another procedure on the same page, I get the next error message: "Object reference not set to an instance of an...
9
2172
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a usercontrol and all i'm really needing to do is get the selected value when the button is clicked on the form. Can someone tell what I need to include in my page to get this working ? Moe <><
6
6118
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page then tried to access 2nd, or 3rd, etc page. The problem is it happens sometimes - sometimes when they clicked refresh button, then everything is ok. Now they told me it happens more frequently. but I have tried by myself many times and never got...
7
3187
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb -- UC/ ----- Classic/
0
283
by: dh | last post by:
As a simple example, I can't seem to be able to reference a label called "lblOutput" that exists in my test.aspx page from within a User control, TestControl.ascx. I am stumped. Any help is appreciated. Thanks. The error I get when I compile is... "The type or namespace name 'lblOutput' could not be found (are you
1
390
by: aarepasky | last post by:
I list the code below, but the line that has the error is: txtCompanyName.Enabled = false; The error is: Object reference not set to an instance of an object. Default.aspx.cs using System; using System.Data;
2
2580
by: o0JoeCool0o | last post by:
I am trying to create a User Control, that will be a message box with input options if I call okconf.visible = true in the page load of the user control it works fine, but if i then try to call it later by calling the user controls alert method i get a reference null error. heres the class code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3
2566
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
0
8360
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
8876
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
8556
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
8642
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
7387
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
6198
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.