Apparently it is possible to write formatted output using the <%= %>
construct (render block) in ASP.NET web forms pages and views.
<%= "{0} is {1}", "Foo", 42 %>
This will render "Foo is 42". As far as I know the ASP.NET parser translates <%= %>
into a call to HttpResponse.Write(string)
. Obviously in the code above, there is no one-to-one translation, because the number of arguments don't match (assuming the ,
in the expression above separates arguments).
Now I have seen that the class TextWriter
has a Write(string, object[])
method.
I have checked the output from the parser, and indeed it calls the TextWriter
's method that accepts a params object[]
argument for formatting:
private void @__Renderform1(System.Web.UI.HtmlTextWriter @__w, System.Web.UI.Control parameterContainer) {
// ...
@__w.Write( "{0} is {1}", "Foo", 42 );
Is that behavior documented anywhere?