Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

ASP.NET suppress response HTML

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 <INPUT> tag 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

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

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,

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)

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


But, I still get the HTML for the page returned

What am I doing wrong?


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.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc