Re: <% =expression%> not evaluated in custom control attributes



<%# %> expressions require databinding and can only be used inside of templates or inside of a full attribute value of a control. But the databinding is required as these expressions generate databinding event code.

<%= %> doesn't work inside of server control attributes as you found out because the server control parsing will interpret the expression as a string. Outside of quotes the the quotes but inside of the server expression they are not allowed at all.

As Axel points out the better way to do this is to use codebehind to set the value and while I don't agree about the 'obsolete' comment he makes, in this case that may be the only way that you can get this to work...

+++ Rick ---


"James Hawkins" <not@xxxxxxxxxxxx> wrote in message news:6i80o2935errerrbcnf98d9d96fit77rjo@xxxxxxxxxx
On Wed, 13 Dec 2006 15:38:39 GMT, James Hawkins <not@xxxxxxxxxxxx>
wrote:

The control in question is not data bound.

Is this possible? Is it perhaps possible with a different syntactical
construction; e.g. perhaps with <%# %>?

I noticed that I can use <%#S()%>, but only if I call DataBind() on
the control. As this is a custom control that I don't want to have to
explicitly DataBind(), I am currently doing a 'self-bind' by calling
DataBind() in the control's OnInit(). Is this an acceptable way of
doing things?

Thanks.

.



Relevant Pages

  • Re: Dynamically set a control property
    ... if you use runat=server, you can not use expressions, only databinding, which would require you call databind on the control. ... protected int GetMaxLength() ... Pretty sure I have seen this before but I can't seem to get it to work outside of databinding. ...
    (microsoft.public.dotnet.framework.aspnet)
  • SOLVED Re: How to programmatically access ObjectDataSource values (instead of binding to data cont
    ... Here's a very helpful article about the finer points of ASP.NET databinding: ... If you embed the output as the ImageURL of an asp:image control, ... of an image string, and show or hide visibility based on whether there's ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Idea gathering, suggestions welcome
    ... I'm not sure I follow your comments about a user control. ... suggest a usercontrol as an ascx template. ... And as for using UserControl, I think it a good approach, you can add those ... template) and then apply databinding expression on their properties. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: ItemDataBound text modification question
    ... databound control(such as datagrid, datalist, repeater..), it will loop ... hold the databinding values generated by each ... block(this behavior is for templated databound controls like ...
    (microsoft.public.dotnet.general)
  • Re: DataBinding and updating on non UI thread
    ... been using databinding in the first place is so that they don't have to write ... > control that is data bound to, ... then you need to pass a delegate to the Invoke method on the ... >> reflect the state of my datasource when I update the datasource - awesome, ...
    (microsoft.public.dotnet.languages.csharp)

Loading