By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,685 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,685 IT Pros & Developers. It's quick & easy.

ASP.NET suppress response HTML

P: n/a
I have an ASP.NET webpage that allows a user to upload a file from the
client browser. I want to display an animated gif and report on the
progress of the upload. The <INPUTtag used for uploading files
requires the form to be posted. Posts stop javascripts and GIF
animations from running for the duration of the upload until a
response to the post is received from the codebehind and the page is
re-rendered.

To get around this problem, I'm posting the upload through an XMLHTTP
control from a client-side javascript function instead. The XMLHTTP
control runs in parallel with the browser, so javascript and GIF
animations are able to continue to run simultaneously with the upload
as it is happening.

This works very well, and the asp.net codebehind generates its regular
response of the source code for its corresponding HTML .aspx page.
The XMLHTTP control, and not the browser, receives the codebehind's
response. As the current page the control is on is still visible in
the browser, and the XMLHTTP control doesn't re-render pages, the
returned HTML code is of little use.

It would be great if there was some way to shutdown the automatic
generation of HTML by the codebehind for its responses to the XMLHTTP
control's requests, and instead use the responses to send back
meaningful messages.

In the codebehind's Page_Load function, I've tried:
Response.SuppressContent = True
Response.Cache.SetNoStore()
Response.ClearContent()
Response.Clear()
Response.End()

But, the HTML is still being generated and returned as evidenced by
using an alert box in the clientside code on the XMLHTTP control's
received contents.

All I want is to be able to do a:
Response.Write("My message")

without the codebehind generating any other content automatically.

Does anyone know how to do this?

thanks in advance,
Andy

May 30 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
as long as buffer is on, ClearContent(), Response.End() works fine.

the only problem with using XMLHTTPResquest to upload, is the user
having to turn on full trust for your site. be sure there are no cross
scripting errors on you site, or it can be used for security exploits.

-- bruce (sqlwork.com)

Andy wrote:
I have an ASP.NET webpage that allows a user to upload a file from the
client browser. I want to display an animated gif and report on the
progress of the upload. The <INPUTtag used for uploading files
requires the form to be posted. Posts stop javascripts and GIF
animations from running for the duration of the upload until a
response to the post is received from the codebehind and the page is
re-rendered.

To get around this problem, I'm posting the upload through an XMLHTTP
control from a client-side javascript function instead. The XMLHTTP
control runs in parallel with the browser, so javascript and GIF
animations are able to continue to run simultaneously with the upload
as it is happening.

This works very well, and the asp.net codebehind generates its regular
response of the source code for its corresponding HTML .aspx page.
The XMLHTTP control, and not the browser, receives the codebehind's
response. As the current page the control is on is still visible in
the browser, and the XMLHTTP control doesn't re-render pages, the
returned HTML code is of little use.

It would be great if there was some way to shutdown the automatic
generation of HTML by the codebehind for its responses to the XMLHTTP
control's requests, and instead use the responses to send back
meaningful messages.

In the codebehind's Page_Load function, I've tried:
Response.SuppressContent = True
Response.Cache.SetNoStore()
Response.ClearContent()
Response.Clear()
Response.End()

But, the HTML is still being generated and returned as evidenced by
using an alert box in the clientside code on the XMLHTTP control's
received contents.

All I want is to be able to do a:
Response.Write("My message")

without the codebehind generating any other content automatically.

Does anyone know how to do this?

thanks in advance,
Andy
May 30 '07 #2

P: n/a
Thanks for your response...

I've got:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Buffer = True 'allows content to be cancelled

and later I have:
result = Upload(False) 'this uploads the file
and returns a status
Response.SuppressContent = True
Response.ClearContent()
Response.Clear()

Response.Write(result)

But, I still get the HTML for the page returned

What am I doing wrong?


May 31 '07 #3

P: n/a
Found the problem.

A post from the XMLHTTP control to an ASP.NET web page will always be
considered to be a first time page load and never a page postback by
the codebehind, regardless if the XMLHTTP control is posting from a
currently displayed asp.net page that has already experienced its
first load.

So, server-side code in the codebehind that is nested inside a
Page.IsPostBack if statement will never get executed.

This is because the hidden asp.net viewstate field isn't populated or
transmitted when the client-side XMLHTTP control makes its post.

The solution is to remove any Page.IsPostBack statements in the
codebehind's Page_Load function, and to control whether code that
should be executed only when a page is posted back (from the client's
perspective) through regular querystring posted values.
May 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.