在code座的Response.Write输出外出现的HTMLResponse、code、HTML、Write

2023-09-03 07:14:48 作者:敢不敢以心换心

暂且不论是否应该甚至使用的Response.Write在.aspx的HTML部分,在一个项目中我的工作变量从code后面被显示在使用响应前端的任何辩论。写。它曾经工作正常,但一些项目最近改变(另一个开发团队的工作就可以了,所以我不知道到底发生了什么),但现在所有的Response.Write code块在的顶端显示页。唯一的线索我有什么可能改变的是,近期一些AJAX功能被添加到项目中。

Putting aside any debate about whether you should even use Response.Write in the HTML portion of an .aspx, in a project I am working on variables from the code behind are being displayed on the front-end using Response.Write. It used to work fine but something in the project changed recently (another development team was working on it, so I don't know exactly what happened) but now all the Response.Write code blocks are displaying at the top of the page. The only clue I have to what might have changed is that some recent AJAX functionality was added to the project.

推荐答案

的Response.Write 写入响应流。您的数据被添加的响应流的开始的原因只能是,你的陈述引发的事件的在的任何的Response.Write

Response.Write writes to the response stream. The reason that your data is added on the beginning of the response stream can only be that the event where your statements are triggered is before any of the Response.Write of ASP.NET start.

您通常应该重写渲染 RenderChildren将或 RenderControl 把你的Response.Writes中,并确保调用正确的父方法,否则只有您的语句是可见的。另外,把你的Response.Write内部服务器标记< 或使用函数naveed的建议(其中顺便说一句内部转化为响应; %%&GT。写反正,但更清晰,更容易编写)。

You should typically override Render, RenderChildren or RenderControl to put your Response.Writes in, and make sure to call the proper parent methods, otherwise only your statements are visible. Alternatively, put your Response.Write inside server tags <% %> or use the suggestion of Naveed (which btw translates internally into a Response.Write anyway, but is much clearer and easier to write).

下面的扩展聊天编辑总结:原因被发现在的Telerik RadAjax.Net2控制。在去除,这个问题就走了。由Andreas自己解决了。

EDIT summary of the extended chat below: the cause was found in the Telerik RadAjax.Net2 control. On removing that, the issue went away. Solved by Andreas himself.