简体   繁体   中英

Render .aspx page without html, body tags

I have a test page Test.aspx , below is the code i have it in Page_Load function.

Response.Write("test");

When i execute this page, i can see the html out put "test" along with html, body tags in it.

What should i do so that the output only has the text "test", and no body,html tags?

Please suggest.

You can try with this code - based on ContentType = "text/plain";

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Only text is printed");
Response.End(); 

Try this

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Test");
Response.End();

When you have a case that you wont an empty page that you can write just some words, or something else, is better to use a handler .ashx

The handler is not add anything by default, like an .aspx page do, no need to clear anything and you do not spend time to render, then clear as you do with an aspx page.

So the correct way, is to create a handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM