472,368 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

Why can I not use script blocks within ASP:Label controls?

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
just get "<span id="lblScenario"
style="font-size:17px;font-weight:bold;"></span>". Now, suppose that I
remove first Eval call and open the page again, I get "<span
id="lblScenario"
style="font-size:17px;font-weight:bold;">sdfsadffdsfsda</span>", which this
time contains the static content as expected. I have even removed my
reference to Eval and just placed static content in the <% %> block and the
same thing happens. Any ideas at what the server is doing?
<form id="Form1" method="post" runat="server">
aaaaaaaa
<table>
<TR>
<TD vAlign="top">
<asp:Label id="lblScenario" Font-Size="17px" Font-Bold="True"
Runat="server">sdfsadf<%= ConditionalText.Eval("ADMIN_MARKET_HEADER")
%>fdsfsda</asp:Label>
<br>
<br>
<asp:Label id="lblScenarioExpl" Font-Bold="False" Runat="server">
<%= ConditionalText.Eval("ADMIN_MARKET_INSTRUCTION") %>
</asp:Label>
</TD>
</TR>
</table>
bbbbbbbb
</form>
Nov 19 '05 #1
2 1659
It doesn't work because ASP.NET is taking the <asp:Label x=y z=w> and creating
a method to do the instantiation and assignment of those properties on the
Label (BTW, the text inside the tags is just a Text property assignment).
This is done at creation time of the ASPX Page object. The <%%> syntax is
Rendering syntax which is done at a much later time in the page lifecycle
andn thus conflicts with the initialization code mentioned above. The idea
is that if you've gone to all the work to make this a server control, then
you'd do those sorts of assignments (dynamic or otherwide) in your code for
your page, like Page_Load. In short, the ASP.NET parser and object model
is at odds with their attempt to provide backwards classic ASP style inline
rendering syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 just get "<span id="lblScenario"
style="font-size:17px;font-weight:bold;"></span>". Now, suppose that
I remove first Eval call and open the page again, I get "<span
id="lblScenario"
style="font-size:17px;font-weight:bold;">sdfsadffdsfsda</span>", which
this time contains the static content as expected. I have even
removed my reference to Eval and just placed static content in the <%
%> block and the same thing happens. Any ideas at what the server is
doing?

<form id="Form1" method="post" runat="server">
aaaaaaaa
<table>
<TR>
<TD vAlign="top">
<asp:Label id="lblScenario" Font-Size="17px" Font-Bold="True"
Runat="server">sdfsadf<%= ConditionalText.Eval("ADMIN_MARKET_HEADER")
%>fdsfsda</asp:Label>
<br>
<br>
<asp:Label id="lblScenarioExpl" Font-Bold="False"
Runat="server">
<%= ConditionalText.Eval("ADMIN_MARKET_INSTRUCTION") %>
</asp:Label>
</TD>
</TR>
</table>
bbbbbbbb
</form>


Nov 19 '05 #2
I'm not sure to undersand what do you want to do,
but in ASP.NET sou shouldn't use <%= %> to render some dynamic content like
ASP developers used to do before ASP.NET

It is better to write the code like :
lblScenario.Text = "mystring"+ConditionalText.Eval("ADMIN_MARKET_HEAD ER")

and searching why or why not your result is strange is not the good question
I mean...

Sincerely,
Daniel
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl...
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
just get "<span id="lblScenario"
style="font-size:17px;font-weight:bold;"></span>". Now, suppose that I
remove first Eval call and open the page again, I get "<span
id="lblScenario"
style="font-size:17px;font-weight:bold;">sdfsadffdsfsda</span>", which this time contains the static content as expected. I have even removed my
reference to Eval and just placed static content in the <% %> block and the same thing happens. Any ideas at what the server is doing?
<form id="Form1" method="post" runat="server">
aaaaaaaa
<table>
<TR>
<TD vAlign="top">
<asp:Label id="lblScenario" Font-Size="17px" Font-Bold="True"
Runat="server">sdfsadf<%= ConditionalText.Eval("ADMIN_MARKET_HEADER")
%>fdsfsda</asp:Label>
<br>
<br>
<asp:Label id="lblScenarioExpl" Font-Bold="False" Runat="server">
<%= ConditionalText.Eval("ADMIN_MARKET_INSTRUCTION") %>
</asp:Label>
</TD>
</TR>
</table>
bbbbbbbb
</form>

Nov 19 '05 #3

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...
2
by: tshad | last post by:
Is there another way to put labels on a page other than asp:label? I have been building a page where I use a label to display the calculated result of some imput. I do it using Javascript. But...
2
by: Shapper | last post by:
Hello, I am creating a contact form in ASP.NET and I need to access the labels on Page_Load on my aspx.vb file. The other elements such as input box and text box don't need to be accessible....
0
by: Shapper | last post by:
Hello, I have an Asp:Label inside the HeaderTemplate of an ASP:Repeater: <asp:Repeater id="myRepeater" runat="server"> <HeaderTemplate> <asp:Label id="title" runat="server"></asp:Label> ... ...
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...
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...
4
by: Guy Noir | last post by:
So, I have a table that I only want to appear after some event has fired. Using the asp:table control and the Visible property, this is a piece of cake. The problem is that when I try and drop a...
1
by: Steve Hershoff | last post by:
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...
0
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.