473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

response.write and plain/text

I have a simple export.aspx page that allows a user to fill in a form
to export some data. The postback logic writes the data to the
response stream. I have two small issues:

1) The data is tab-delimited text. If I set
Response.ContentType="plain/text", the format is fine, but an
Open/Save dialog will appear on the IE6 browser, which I don't want.
If don't set the ContentType at all, the dialog goes away, but the
browser removes the linefeeds from the output.

2) The browser history does not contain the original form display.
Hitting the back button skips over the form.

Thanks!

Mark
Nov 18 '05 #1
3 7186
Hi Mark,

As for the two questions you mentioned, here are my understandings:

1. The ContentType is used to speicfy the mime type of the response stream.
When we don't set it , its the original value (text/html) for the aspx
page. So it'll display as html and omit those "tab" even line break flag.
And as for the text file, I think the correct ContentType should be
"text/plain" rather than "plain/text", and the "plain/text" may not be
recognized by the client browser so that it open it outside the browser via
other text editors. Please try changing the contenttype to "text/plain" and
see whether it works.

2. When we hit "back" button, the browser will retrieve the previous url
stored in the history list and load it.(normally from the client cache).
And generally, when we hit a button on asp.net page, it postback and
reutrn, then the original url(before postback) is added into history list(
you can push the dropdown button beside the "back" button to view the
history list). However, as for your situation, when you post back, and
return a txt data stream rather than text/html, then the original html
document still remain( didn't reload). So it is not added into history
list, thus the "back" button won't work (not history item stored for the
previous page ).

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #2
Hey thanks Steven,

Actually, I miswrote. I was already specifying text/plain. Still the
receiving browser pulls up the save/open dialog.

Here is the simple case:

private void DisplayMessage(string msg)
{
//Clear existing stuff from response
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();

//Set response type
Response.ContentType = "text/plain";

//Write the message
Response.Write(msg);
//End the response causing it to be sent
Response.End();
}

-Mark
Nov 18 '05 #3
Hi Mark,

Thanks for your response. Really a bit surprised that since my test code is
exactly the same with yours. Anyway, I'll post my code here, you can also
have a try.

private void btnShowText_Click(object sender, System.EventArgs e)
{
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType="text/plain";
//Response.AddHeader("content-disposition","inline;filename=data.txt");
//Response.WriteFile(Server.MapPath("./text.txt"));

string txt = "Index\tName\tEmail";
txt += "\n1\tSteven\ts*****@test.com";
txt += "\n2\tMike\tm***@test.com";

Response.Write(txt);
Response.End();
}

# you can also try adding a such line
Response.AddHeader("content-disposition","inline;filename=data.txt");
in code to see whether it helps.

also, you can try using the
<a href="url of a txt file" target="_blank" > open text file</a>
hyperlink to open a txt file to see whether it can be opened in the browser
correctly.

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gary | last post by:
I am having a strange problem that I cannot solve. I have an asp page that I use for a user to login and gain access to other pages. When the user logs in I set a couple of session variables like...
2
by: RobertHillEDS | last post by:
While using the Soap generated ASP code, I would like to dump the raw contents of the request and response objects using Response.AppendToLog. I have tried using variations of the following code,...
3
by: Webgour | last post by:
How do you reproduce this vbscript in C# <% Response.ContentType = "text/plain" response.write "This is text type" %>
3
by: Fraggle | last post by:
within my reading out of data from a repeater sub ... If i put response.write(lstitem.text) it outputs the text from the listitem that is being looked at if i put
3
by: Martin Dew | last post by:
I have a page which upon opening gets information from a database, the field it returns has structured xml stored in it. private void Page_Load(object sender, System.EventArgs e) { if...
8
by: Mantorok | last post by:
Hi all I have the contents of a text file that I would like to output to the response stream, however IE thinks it is XML and comes up with and error, here is the code: Response.ContentType =...
5
by: Tim_Mac | last post by:
hi, i read that by adding the following code to by aspx pages, it would not store temporary internet files: Response.Cache.SetCacheability(HttpCacheability.NoCache); it didn't actually work...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
3
by: letuce dance | last post by:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.