Link to home
Start Free TrialLog in
Avatar of justin_smith
justin_smithFlag for Australia

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="/wEPDwUJNzgzNDMwNTMzZGRr7t66L1bFbpKua9rQ+II9N4P8bA==" />
</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
Avatar of justin_smith
justin_smith
Flag of Australia image

ASKER

Is it due to Session or something?
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?
ASKER CERTIFIED SOLUTION
Avatar of strider_1981
strider_1981
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
I had to add Response.Flush() in the end...