Response.Write output in code block is appearing outside html

只谈情不闲聊 提交于 2019-12-31 04:53:06

问题


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.


回答1:


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.

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).

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.



来源:https://stackoverflow.com/questions/6931436/response-write-output-in-code-block-is-appearing-outside-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!