Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i used to make a dynamic css by embed cs code, like so:

HTML
<div class="<%# Request.RawUrl.Contains(" personinformation.aspx=") ? " xx=" : " zh_x_z=" %>" /div>


doesn't work, but the following does:

HTML
<div class="<%= Request.RawUrl.Contains(" personinformation.aspx=") ? " xx=" : " zh_x_z=" %>" /div>



can you tell me the reason or principle of that
Posted
Updated 18-Aug-10 15:50pm
v2

1 solution

"<%# %>" is a DataBinding expression. On the other hand, <%= %> is an expression that simply executes in server as Response.Write("") and outputs something int the browser.

Suppose you use a Server control that has a DataSource property and this is Template based (GridView,DataList etc) Server control. Now if you bind the datasource of that control with some compatible data (Say, a collection), at runtime, you can bind a property of an object within that datasource to a control within the template of the control. See http://msdn.microsoft.com/en-us/library/ms178366.aspx[^] to learn more.

In your case, you want to output your class name based upon a condition. So, you should yous "<%= %>" expression and hence, this is working.
Obviously, as you are not using any Template based Server control here and you are not binding any datasource. So, the databinding expression "<%# %>" is not working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900