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

  • Thread starter Thread starter Max2006
  • Start date Start date
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
 
<%=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.
 
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
 
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)
 
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.
 
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!
 
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.
 
Back
Top