PC Review


Reply
Thread Tools Rate Thread

ASP.NET suppress response HTML

 
 
Andy
Guest
Posts: n/a
 
      30th May 2007
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
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

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      30th May 2007
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 <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
> 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
>

 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      31st May 2007
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?




 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      31st May 2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to suppress/clear Response from within a control? Ahmet Gunes Microsoft ASP .NET 1 14th Apr 2008 04:11 PM
How to Suppress Date Footer When Printing HTML Formatted E-Mail =?Utf-8?B?TWNLZWU=?= Microsoft Outlook Discussion 2 10th Jul 2007 11:31 PM
Suppress self closing tags for html 4.01 strict compliance Nik Coughlin Microsoft ASP .NET 0 16th Jun 2006 03:27 AM
Transmit File AND HTML in Response john@haasbeek.com Microsoft ASP .NET 6 10th May 2006 10:51 PM
How do you create a response page with no HTML in ASP.Net? wptpro@gmail.com Microsoft ASP .NET 5 18th Nov 2005 06:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.