Response.Clear() doesn't clear

Discussion in 'ASP .Net' started by David, Jan 31, 2008.

  1. David

    David Guest

    When I use Response.Clear() it doesn't seem to have an effect. The original
    aspx page code remains. I have tried creating test projects in both VS 2005 &
    2008, where I just add a new aspx page and place in the Page_Load() event
    Response.Clear(), but nothing is cleared out. I have tried various ways to
    get the page to clear, including the code below:

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.ContentType = "text/html";
    Response.Clear();
    Response.BufferOutput = true;
    Response.Write("<html><body>Testing</body></html>");
    Response.Flush();
    }

    The page will have the <html><body>Testing</body></html> at the top of the
    page's code file, but all of the original default aspx code will still be
    there also. I have tried this with both ASP .NET 2.0 & 3.5 in VS 2008. I have
    looked at a lot of examples on the Internet and have not seen anything else
    mentioned that is necessary. Is there something else that I am missing?
    David, Jan 31, 2008
    #1
    1. Advertising

  2. At this stage of the page's lifecycle internal buffer with the HTML is empty,
    it is filled in Render method. In order to make it work you'd have to call
    Response.End();

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.ContentType = "text/html";
    Response.Clear();
    Response.BufferOutput = true;
    Response.Write("<html><body>Testing</body></html>");
    Response.End();
    }

    --
    Milosz


    "David" wrote:

    > When I use Response.Clear() it doesn't seem to have an effect. The original
    > aspx page code remains. I have tried creating test projects in both VS 2005 &
    > 2008, where I just add a new aspx page and place in the Page_Load() event
    > Response.Clear(), but nothing is cleared out. I have tried various ways to
    > get the page to clear, including the code below:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Response.ContentType = "text/html";
    > Response.Clear();
    > Response.BufferOutput = true;
    > Response.Write("<html><body>Testing</body></html>");
    > Response.Flush();
    > }
    >
    > The page will have the <html><body>Testing</body></html> at the top of the
    > page's code file, but all of the original default aspx code will still be
    > there also. I have tried this with both ASP .NET 2.0 & 3.5 in VS 2008. I have
    > looked at a lot of examples on the Internet and have not seen anything else
    > mentioned that is necessary. Is there something else that I am missing?
    Milosz Skalecki [MCAD], Jan 31, 2008
    #2
    1. Advertising

  3. I also find it most useful to set the Buffer in the page directive and note
    in the codebehind. This way you don't have to worry about the timing of
    things as it's possible to set the buffer too late in the event cycle.


    --
    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression


    "David" <> wrote in message
    news:...
    > When I use Response.Clear() it doesn't seem to have an effect. The
    > original
    > aspx page code remains. I have tried creating test projects in both VS
    > 2005 &
    > 2008, where I just add a new aspx page and place in the Page_Load() event
    > Response.Clear(), but nothing is cleared out. I have tried various ways to
    > get the page to clear, including the code below:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Response.ContentType = "text/html";
    > Response.Clear();
    > Response.BufferOutput = true;
    > Response.Write("<html><body>Testing</body></html>");
    > Response.Flush();
    > }
    >
    > The page will have the <html><body>Testing</body></html> at the top of the
    > page's code file, but all of the original default aspx code will still be
    > there also. I have tried this with both ASP .NET 2.0 & 3.5 in VS 2008. I
    > have
    > looked at a lot of examples on the Internet and have not seen anything
    > else
    > mentioned that is necessary. Is there something else that I am missing?
    Mark Fitzpatrick, Jan 31, 2008
    #3
    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. Eirik Eldorsen
    Replies:
    4
    Views:
    13,613
    Eirik Eldorsen
    Aug 26, 2005
  2. Replies:
    4
    Views:
    2,371
  3. Ahmet Gunes
    Replies:
    1
    Views:
    364
    bruce barker
    Apr 14, 2008
  4. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    926
    Steven Cheng[MSFT]
    Mar 6, 2007
  5. Replies:
    1
    Views:
    174
    Evertjan.
    Nov 4, 2006
Loading...

Share This Page