473,385 Members | 1,356 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,385 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 2338
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.