473,473 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Response.Write or <%= in a Label Control

PK9
I'm having some issues with using a Response.Write or the shortcut ( <%= ...)
from within a label control. I cannot do this in the code behind, I need to
do it here at runtime. I have a public function (GetMsgs) in my code behind
page that returns a string back to the caller. I want to call this function
from the ASPX page and return the value to a Label control.

I have tried the following options but cannot get it to work:
1)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<%= GetMsgs() %>' />

2)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<% Response.Write(GetMsgs()) %>' />

3)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor">
<%= GetMsgs() %>
</asp:Label>
--
PK9
Nov 19 '05 #1
3 6610
<%= ... %> constructs are evaluated when Page is rendered, so it doesn't
actually make sense to have them like that because you'd be assigning text
to Text property of a Label which should happen before rendering.

What you can do is put it like this:

Text='<%# GetMsgs() %>' />

(databinding-expression) and call Page.DataBind() or
lblSelectedMessages.DataBind() somewhere (you definately can do that in
inline code as well, you just need to have the server-sidescript block then
but is that a good option...)

You can output text on page with <%= %> if you don't have server control
"around it".

--
Teemu Keiski
ASP.NET MVP, Finland
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
I'm having some issues with using a Response.Write or the shortcut ( <%=
...)
from within a label control. I cannot do this in the code behind, I need
to
do it here at runtime. I have a public function (GetMsgs) in my code
behind
page that returns a string back to the caller. I want to call this
function
from the ASPX page and return the value to a Label control.

I have tried the following options but cannot get it to work:
1)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<%= GetMsgs() %>' />

2)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<% Response.Write(GetMsgs())
%>' />

3)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor">
<%= GetMsgs() %>
</asp:Label>
--
PK9

Nov 19 '05 #2

Teemu Keiski wrote:
<%= ... %> constructs are evaluated when Page is rendered, so it doesn't actually make sense to have them like that because you'd be assigning text to Text property of a Label which should happen before rendering.

What you can do is put it like this:

Text='<%# GetMsgs() %>' />
<%# is new to me. what does Microsoft call "<%=" and "<%#"? I dont
know how to search for the concept at MSDN.

(databinding-expression) and call Page.DataBind() or
lblSelectedMessages.DataBind() somewhere (you definately can do that in inline code as well, you just need to have the server-sidescript block then but is that a good option...)

You can output text on page with <%= %> if you don't have server control "around it".
Which I dont understand at all. Does .NET discriminate against server
controls! :)

thanks,

-Steve

--
Teemu Keiski
ASP.NET MVP, Finland
"PK9" <PK*@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
I'm having some issues with using a Response.Write or the shortcut ( <%= ...)
from within a label control. I cannot do this in the code behind, I need to
do it here at runtime. I have a public function (GetMsgs) in my code behind
page that returns a string back to the caller. I want to call this function
from the ASPX page and return the value to a Label control.

I have tried the following options but cannot get it to work:
1)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<%= GetMsgs() %>' />

2)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor" Text='<% Response.Write(GetMsgs()) %>' />

3)
<asp:Label Runat="server" ID="lblSelectedMessages"
CssClass="span_normal_bold_altcolor">
<%= GetMsgs() %>
</asp:Label>
--
PK9


Nov 19 '05 #3
Really in the code behind you just want to call (on the PageLoad)
lblSelectedMessage.Text = GetMsgs()

this way the logic of setting the label is seperated form the page
layout

Nov 19 '05 #4

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

Similar topics

6
by: Pete Mahoney | last post by:
I am trying to 'POST' values from a form in a ASP file that has anonymous access permissions. I can retrieve the form values when I redirect to this page from another page which has also has...
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
3
by: clintonG | last post by:
Briefly stated, my problem is accessing and 'setting' properties of a label control declared in the template of another control noting that the other control is an instance of the beta 2...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
3
by: Yiu | last post by:
Here is my code: private static ArrayList info=new ArrayList(); private Label label; private void Page_Load(object sender, System.EventArgs e) { label=new Label; Response.Write("<table...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
10
by: Ron | last post by:
Hi, I currently am generating a report by to my end user by retrieving data from my back end DB and concatenating strings together and place this string concatenation within a Label control. I...
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
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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.