473,396 Members | 1,766 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.

reference USER CONTROLS label from aspx page...

Hi !
if anyone knows the answer I would appreciate it:

I have a user control for the header of the page with
one label in it..I want the label to change as the pages
are changing....

my question:

I want to reference a text property of a label in the control
from the page which holds the control...
How can I do that ?
please, in code....
Nov 18 '05 #1
1 2341
If i Understand you properly and you have a customer User control that has a Label that you wish to be able to set programmatically with the page then your label would need to be
<label runat="server" id="lblMyLabel">

If you are running VS.NET and you type the above code in your .ascx page click the "Design" button an dthen the "HTML" button and the next line of code will be added for you.
in your UserControl's CodeBehind you would have to make sure you had a defenition that went something like
protected System.Web.UI.HTML.HtmlGenericControl lblMyLabel;

Now the smartest thing to do would be to set a property accessor for it so in the UserControl's code behind also hadd
public string MyLabelText
{
get { return lblMyLabel.InnerText; }
set { lblMyLabel.InnerText = value; }
}

Then on your Page where you have something that looks like
<cc1:MyUserControl runat="server" id="uscMyUserControl">

On your Page's Code Behind you Must create a definition for it
protected MyUserControl uscMyUserControl; // Note this assumes MyUserControl is the class name and uscMyUserControl is the ID specified in your .aspx page

now in your PageLoad you should be able to go
uscMyUserControl.MyLabelText = "Hello";

And if you followed all of the instructions through properly when you run wherever your UserControl is a "hello" should appear on your page.

Hope this helps.
Nov 18 '05 #2

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

Similar topics

6
by: Tom Rowton | last post by:
This one has me a bit confused and I'm not finding what I need in the MSDN or by searching these forums, so here goes... I have a rather large, complex code-in-page WebForm (don't ask) and a...
0
by: Zi | last post by:
I have a user control within a data grid. I am binding the user control to one of the values from the data grid. The data grid implements paging. It is all working ok for the first page but once i...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
2
by: Scott | last post by:
I'm using a master page (mp_TableMaint.aspx) with one Content area (ID: Content1). Content1 contains several usercontrols, which are hidden. The goal is to show the correct control based on the...
5
by: Seok Bee | last post by:
Hi All, I have a webform with a button to add record into the database. When the button is being clicked, the program will assign initial value controls in a detailsview control. When the first...
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...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
4
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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.