473,405 Members | 2,421 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,405 software developers and data experts.

asp:Label - how can I get the Text property?

I'm using VS 2003, and need to extract the text from an asp label in my
code-behind file. The label is part of a DataList's ItemTemplate.

I've noticed that in my ascx file (we're using User Controls here) I can't
set the Text property in the opening tag when writing out the
<asp:Label....</asp:Labeltags. I have to put my text between the opening
and closing tags, like you would with a regular HTML tag.

So this might be the cause of my trouble. What happens in my code-behind
file is I'm trapping the DataBound event on the label's "parent" datalist,
and doing the following:

//from DL_List_DataBound(object sender, DataListItemEventArgs e)

/.....

Label myLabel = (Label) e.Item.FindControl("labelFromASCX_page");

myLabel.Visible = true;
String myString = myLabel.Text;

//........
My problem is, the value of myLabel.Text is always equal to "" even though I
set it in the ascx file. How can I extract the label's text in my
code-behind?


Nov 3 '06 #1
1 2734
Hi,

Steve Hershoff wrote:
I'm using VS 2003, and need to extract the text from an asp label in my
code-behind file. The label is part of a DataList's ItemTemplate.

I've noticed that in my ascx file (we're using User Controls here) I can't
set the Text property in the opening tag when writing out the
<asp:Label....</asp:Labeltags. I have to put my text between the opening
and closing tags, like you would with a regular HTML tag.

So this might be the cause of my trouble. What happens in my code-behind
file is I'm trapping the DataBound event on the label's "parent" datalist,
and doing the following:

//from DL_List_DataBound(object sender, DataListItemEventArgs e)

/.....

Label myLabel = (Label) e.Item.FindControl("labelFromASCX_page");

myLabel.Visible = true;
String myString = myLabel.Text;

//........
My problem is, the value of myLabel.Text is always equal to "" even though I
set it in the ascx file. How can I extract the label's text in my
code-behind?
If you don't set the Text property of the label, but you write the
content between the closing and opening tag of the Label, I think it
doesn't set the text property, but rather it adds a literal control to
the Label. That would explain why the Text property is always empty.

Why can't you just set the Text property in the asp:Label tag?

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 6 '06 #2

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

Similar topics

1
by: moondaddy | last post by:
I want to use a asp Label control (or a <div runat=server> element) in a template column of a datagrid. In the code behind in the grid's ItemDataBound event I need to dynamically set the innerHTML...
3
by: nick | last post by:
Is possible for server side code to access the text of <asp:label> changed by client side javascript code?
2
by: Peter Rilling | last post by:
Below is some code that I do not know why it does not work. Okay, as you can see it is simple HTML with two ASP:Label controls. Each label has some code that basically gets a string that will be...
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
2
by: footballhead | last post by:
I do some design work on a website that up until to now has been limited to defining CSS and HTML elements. Excuse me if I am using incorrect terminology, I am just starting out in this. I would...
1
by: maflatoun | last post by:
Hi, I have a datagrid and based on a condition I like to display either a asp:textbox or asp:label. How would I do that? I have the following <asp:TemplateColumn HeaderText="Qty">...
4
by: pagates | last post by:
Hello All-- I have a number of <asp:Label CssClass="someclass">Text</asp:Labelcontrols on my page. I would like them to be shown as <div class="someclass">Text</div> rather than <span...
1
by: Dhananjay | last post by:
hi all i have a problem on populating a message on asp:label server control.I am able to insert records into the table.but it is not populating any message like "Records entered successfully"....
0
by: Bob | last post by:
When I use an ASP:Label with runat="server", and in JavaScript I use innerText on the ASP:Label, the Text property is not reflected in an event postback on the form. ASP:TextBox is not an...
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: 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
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
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
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...
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.