473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DataBou nd(object sender, DataListItemEve ntArgs e)

/.....

Label myLabel = (Label) e.Item.FindCont rol("labelFromA SCX_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 2797
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_DataBou nd(object sender, DataListItemEve ntArgs e)

/.....

Label myLabel = (Label) e.Item.FindCont rol("labelFromA SCX_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
11446
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 of this control with data and line breaks (<br>). The problem is that while working in the code behind, I don't see any properties for this control where I can set innerHTML, only text. Any good ideas?
3
3455
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
1756
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 written to the browser. ConditionalText.Eval is a method from my own library. As you can see, I have written some static text before and after the first Eval call. If I open this page, I get no content in the Label, even the static content. I...
1
9230
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 example WebForm1.aspx and WebForm1.aspx.cs code below: WebForm1.aspx =======================================================
2
1449
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 like to try some beginning coding and the developers are giving me some latitude to experiment. They said that I can use INLINE VB code. I would like to create an ASCX file that uses some labels that are on the parent page that that ascx file...
1
4060
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"> <ItemTemplate> <% if (DataBinder.Eval(Container.DataItem, "DynamicAttribute") = "No") {%>
4
6716
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 class="someclass">Text</span> When it uses a span, it doesn't seem to use all the class definitions, particularly for margins and positioning.
1
1386
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". i wanted to implement this .how to proceed can anybody tell me about this . i am using asp.net/vb.net 2.0 here i am providing the code also:-
0
1442
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 alternative for me because it doesn't produce text which can be inline and wrappable with surrounding text. Is there anyway to accomplish what I am trying to do? Thanks
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
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,...
1
10071
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
9925
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
8958
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...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.