开发者

.NET 4.0 Page.Response.Write vs <%= %>

开发者 https://www.devze.com 2023-04-09 23:56 出处:网络
I have some UserControls in a webpage. When I use it in the ASPX code of m开发者_如何学JAVAy UserControl

I have some UserControls in a webpage. When I use it in the ASPX code of m开发者_如何学JAVAy UserControl as such <div><% Page.Response.Write("<a href='http://www.microsoft.com'>test</a>") %></div>, my anchor is rendered at the start of the page:

<a href='http://www.microsoft.com'>test</a><html><head>

instead of the expected:

<html><head /><body>
<a href='http://www.microsoft.com'>test</a></body></html>

But if i use <div><%="<a href='http://www.microsoft.com'>test</a>" %></div> then the response is written inline as expected.

We used this technique of Page.Response.Write() a lot in .NET 3.5, and now migrating to .NET 4.0, we are experiencing this problem with it. Why does it happen in .NET 4.0?


I would move to using the Literal control.

0

精彩评论

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