开发者

RenderControl does not evaluate Response.Writes but evaluates <%= %>?

开发者 https://www.devze.com 2022-12-10 20:39 出处:网络
Why does calling page.RenderControl not evaulate <% Response.Write(\"foo\") %> but it does evaluate <%= \"bar\" %>? Is there something else I should be calling instead?

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" %&g开发者_如何学Got;<% 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>"


<%= %> 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号