Using <% =%> or <% #%> with the runat = server in ASP.NET

I have a web control that looks like this

public class Foo: WebControl
{
  [Bindable (true)]
  [Category ("Default")]
  [DefaultValue ("")]
  [Localizable (true)]
  public string Bar {get; set; }

  protected override void Render (HtmlTextWriter output)
  {
    output.WriteLine (Bar);
  }
}

I want to place this webcontrol on my aspx page as follows:

<cc1: Foo Bar = "<% = Fa.La.La%> / otherstuff" runat = "server" />

(obviously, this code is simplified to show the problem)

In my Render method, the variable Fa.La.La is not evaluated. It is included as the source text "<% = Fa.La.La%>" How to evaluate it?

, . , <% #...% > , . , , , Render().

, , <% =...% > - , .

href <% = xx% > runat = server, , .

+5
2

<%# expr %>.

<cc1:Foo Bar='<%# String.Concat(Fa.La.La,"/otherstuff")%>' runat="server" /> 

DataBind() .

public void page_load()
{
  DataBind();
}
+3

, , . , .

  • <%=
  • <%# DataBind() , DataBind() .
  • <%# . <%= .

MSDN

+6

All Articles