473,396 Members | 2,154 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.

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.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
missing a using directive or an assembly reference?)"
[ TestControl.ascx ]
-----------------------------------
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="TestControl.ascx.cs" Inherits="Test.TestControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

[ TestControl.ascx.cs ]
--------------------------------------
namespace Internet
{
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public abstract class TestControl : System.Web.UI.UserControl
{
private void Page_Load(object sender, System.EventArgs e)
{
lblOutput.Text = "am i here?";
}
}
}

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

<%@ Page language="c#" Codebehind="Test.aspx.cs"
AutoEventWireup="false" Inherits="Internet.Test" %>
<%@ Register TagPrefix="uc1" TagName="TestControl"
Src="TestControl.ascx" %>
<HTML>
<body
<form id="Test" method="post" runat="server">
<asp:Label id=lblOutput runat="server">Label</asp:Label>
<uc1:TestControl id=TestControl
runat="server"></uc1:TestControl>
</form>
</body>
</HTML>
[ Test.aspx.cs ]
--------------------------------------
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Internet
{
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblOutput;

private void Page_Load(object sender, System.EventArgs e)
{
lblOutput.Text = "";
}
}
}
Jul 21 '05 #1
0 3472

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

Similar topics

0
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"...
1
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...
9
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...
6
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...
7
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 --...
0
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...
1
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;...
2
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...
3
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
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...

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.