justin_smith
asked on
ASP.NET Response.Write ()- only the text without HTML formatting
Hi,
I am doing the following to write to reponse
Response.Clear();
Response.Write("My String");
Response.Flush();
This writes perfectly on the web browser
But then I use another Web application to leech the response I found the text to be formatted with HTML in additiopn to \R\N (new line )
When i go and view source I find the following
My String
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="process.aspx?Input =7777" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTM zZGRr7t66L 1bFbpKua9r Q+II9N4P8b A==" />
</div>
<div>
</div>
</form>
</body>
</html>
From the content it looks like the request is return on the response too..
All i want is to send "My String" as plain text..
Any help is appreciated
I am doing the following to write to reponse
Response.Clear();
Response.Write("My String");
Response.Flush();
This writes perfectly on the web browser
But then I use another Web application to leech the response I found the text to be formatted with HTML in additiopn to \R\N (new line )
When i go and view source I find the following
My String
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="process.aspx?Input
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTM
</div>
<div>
</div>
</form>
</body>
</html>
From the content it looks like the request is return on the response too..
All i want is to send "My String" as plain text..
Any help is appreciated
ASKER
I found the reasson why those HTML tags appeared there.. It was becuase i didnt remove the HTML/ASP tage when i create webforms
But the new lines and carriage returns are stilll present
Any help?
But the new lines and carriage returns are stilll present
Any help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What you need to do is to end the response, otherwise the other code in your ASP.NET application (the code you don't see but is executed before, between and after the well-known events) will output their data.
You don't even have to remove the HTML or ASP.NET code. If, in an early event (Init or even PreInit for instance), you use the code shown by strider_1981, including the Response.End(), then other data will not be sent.
One thing to look out for: it is possible that, if you place your code in a rather late event (Page_Load, or even Page_Unload) that some data has already been flushed back to the browser. In that case, Response.Clear() will have no effect. Which is why you must place this code as early in the event chain as possible.
You don't even have to remove the HTML or ASP.NET code. If, in an early event (Init or even PreInit for instance), you use the code shown by strider_1981, including the Response.End(), then other data will not be sent.
One thing to look out for: it is possible that, if you place your code in a rather late event (Page_Load, or even Page_Unload) that some data has already been flushed back to the browser. In that case, Response.Clear() will have no effect. Which is why you must place this code as early in the event chain as possible.
ASKER
I had to add Response.Flush() in the end...
ASKER