1

I have some UserControls in a webpage. When I use it in the ASPX code of my 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?

Kasaku
  • 2,192
  • 16
  • 26
Cédric Boivin
  • 10,854
  • 13
  • 57
  • 98
  • Just an additional note, I think the word you want is *experience*, instead of *experiment*. – Kasaku Sep 29 '11 at 13:31
  • Can you elaborate on the code some more? A simple test of this isn't producing similar results. Are you dynamically creating these controls? When are they being added to the page? – Doozer Blake Sep 29 '11 at 14:00

1 Answers1

2

I would move to using the Literal control.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445