0

Why does calling page.RenderControl not evaulate <% Response.Write("foo") %> but it does evaluate <%= "bar" %>? Is there something else I should be calling instead?

I was under the impression that <%= %> was shorthand for Response.Write as it is in classic ASP.

... <p><%= "foo" %><% Response.Write("bar"); %></p> ...

Render Control code...

string output;

using (var mem = new StringWriter())
using (var writer = new XhtmlTextWriter(mem))
{
     page.RenderControl(writer);
     output = mem.GetStringBuilder().ToString();
}

Outputs...

Expected: "<p>foobar</p>" 
Actual: "<p>foo</p>"
Community
  • 1
  • 1
David
  • 19,389
  • 12
  • 63
  • 87

2 Answers2

3

<%= %> is the same as Response.Write in asp.net. Thats why <%= "bar" %> works.

You are missing a semicolon at the end of <% Response.Write("bar") %> . Thats why it is not working.

Ravinder Singh
  • 846
  • 1
  • 7
  • 17
  • There is a semicolon there and it is not rendering bar. That is not the reason why it's not working. – David Nov 10 '09 at 15:25
  • were you able to make it work ? I got busy with some other stuff, if it worked for you then fine, else i can fire up visual studio and see if we can generate some clue ? – Ravinder Singh Nov 10 '09 at 15:33
1

I have the same problem with yours, my solution is just use <%=...%> instead of response.write(); Personally think the reason looks like former render earlier than response.write(). Once program reach response.write() function the RenderControl object has no control over it even if in server-side tag.

Botz3000
  • 39,020
  • 8
  • 103
  • 127
Sidian
  • 11
  • 1