ASP.NET suppress response HTML

Discussion in 'ASP .Net' started by Andy, May 30, 2007.

  1. Andy

    Andy Guest

    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
    Andy, May 30, 2007
    #1
    1. Advertising

  2. Andy

    bruce barker Guest

    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
    >
    bruce barker, May 30, 2007
    #2
    1. Advertising

  3. Andy

    Andy Guest

    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?
    Andy, May 31, 2007
    #3
  4. Andy

    Andy Guest

    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.
    Andy, May 31, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nik Coughlin
    Replies:
    0
    Views:
    416
    Nik Coughlin
    Jun 16, 2006
  2. Replies:
    1
    Views:
    829
  3. Ahmet Gunes
    Replies:
    1
    Views:
    372
    bruce barker
    Apr 14, 2008
  4. Ahmet Gunes

    How to suppress Response from within a control?

    Ahmet Gunes, Apr 14, 2008, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    758
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    May 10, 2008
  5. Ahmet Gunes

    How to suppress all Response content from within a control?

    Ahmet Gunes, Apr 14, 2008, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    170
    AhmetG
    Apr 14, 2008
Loading...

Share This Page