469,892 Members | 2,136 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,892 developers. It's quick & easy.

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 1575
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by moondaddy | last post: by
2 posts views Thread by Shapper | last post: by
reply views Thread by Shapper | last post: by
2 posts views Thread by footballhead | last post: by
4 posts views Thread by pagates | last post: by
1 post views Thread by Steve Hershoff | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.