473,788 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType="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 7323
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.ClearC ontent();
Response.ClearH eaders();

//Set response type
Response.Conten tType = "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_Cli ck(object sender, System.EventArg s e)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType="text/plain";
//Response.AddHea der("content-disposition","i nline;filename= data.txt");
//Response.WriteF ile(Server.MapP ath("./text.txt"));

string txt = "Index\tName\tE mail";
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.AddHea der("content-disposition","i nline;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
2826
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 Session("UserType") = "Sales". Then based on the Session("UserType") I use response.redirect to take the user to a specific page. The logic and response.redirect works fine on a Win2k server but when I move the page to a server running Win2003 the...
2
4103
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, but I may be barking up the wrong tree with this approach. Any expert help would greatly be appreciated. Dim objReader Set objReader = CreateObject("MSSOAP.SoapReader") objReader.Load Request
3
25048
by: Webgour | last post by:
How do you reproduce this vbscript in C# <% Response.ContentType = "text/plain" response.write "This is text type" %>
3
1185
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
1243
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 (!IsPostBack) { GetRecordFromServer(this.Request.QueryString.ToString());
8
2796
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 = "test/plain"; Response.OutputStream.Write(buffer, 0, buffer.Length); Response.End();
5
9151
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 that way, but i left it in anyway. little did i know it would cause a problem for a forced download routine i have. instead of downloading the .xls attachment, it tried to download the aspx file, and gave an error saying the file could not be...
4
7475
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 new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
3
13943
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, EventArgs e) { Response.ContentType = "text/plain"; Response.Write("help"); }
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10112
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.