<%# IsEditable %> and <%= IsEditable %>

M

Max2006

Hi,

When I use this tag:

<asp:lable . Visible='<%# IsEditable %>'

I have to do DataBind so the binding takes place.

I am trying to use the following notation to do the similar thing without
forced to call DataBind method:

<asp:lable . Visible='<%= IsEditable %>'

But I receive this error:

Generation of designer file failed: Cannot create an object of type
'System.Boolean' from its string representation '<%= IsEditable %>' for the
'Visible' property.

Is there any way to use <%= IsEditable %> instead of <%# IsEditable %> to
avoid calling the DataBind?

Thank you,

Max
 
T

Teemu Keiski

<%=expression%> is executed at render-time, and is meant to output literal
stuff, not to set property values. You certainly could set it in code, but
it removes completely the point of using separate variable.
 
M

Max2006

Thank you for help.

Do you know any resource that allows me monitor - or spy into - when / how
these bindings happen?

If you know any online resource that explains the depth of the binding in
ASP.NET, that would be really helpful. I like to know binding beyond the
syntaxes.

Thank you,
Max
 
B

bruce barker

no.

<%= expression %> is translated to:

Controls.Add(new Label(expression));

where <asp:label id=lb1 Visible=<%=expression%> /> is translated to:

lb1 = new Label();
lb1.Visible = "<%=expression%>";

and when databind is called, it checks for properties with binding
expressions, evals the expression, and sets the property to the value.

-- bruce (sqlwork.com)
 
W

Walter Wang [MSFT]

Hi Max,

A tip on inspecting the generated class from a WebForm is to first
precompile the website and use Reflector
(http://www.aisto.com/roeder/dotnet/) to view the source code of the
WebForm:

aspnet_compiler -v / -p c:\projects\website1 c:\temp\website1
reflector c:\temp\website1\bin\*.dll


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Max2006

Thanks Bruce for reply.

At this point, the outcome of <asp:label id=lb1 Visible=<%=expression%> />
is the error I mentioned. It doesn't work!
 
W

Walter Wang [MSFT]

Hi Max,

lbl1.Visible = "<%= expression %>";

is not a data binding expression, that's why it doesn't work.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top