how can write to the page after Response.End()

Discussion in 'ASP .Net' started by Tim_Mac, Sep 2, 2005.

  1. Tim_Mac

    Tim_Mac Guest

    hi,
    i'm guessing you just can't write to the page after Response.End(), but
    i would be interested to hear if anyone has a work around for my
    situation.

    i have designed a 'SmartButton' control that disables itself (client
    side) when it's clicked, and re-enables itself (client side) after it
    is clicked.
    the problem is when the button_click event does something like download
    a file with binarywrite, this ends the Response. when this happens, my
    client side code obviously doesn't get written out, and the button
    stays in a disabled state with "Please wait..." as the text. i would
    like the button to return to normal, so the user can click it again if
    necessary.

    the code for the control is below.
    thanks for any tips
    tim.

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;

    namespace Whatever
    {
    /// <summary>
    /// A button control that disables itself when clicked, and changes
    the text to "Please wait..."
    /// This is to prevent duplicate clicks by impatient or novice users.
    /// </summary>
    [DefaultProperty("Text"), ToolboxData("<{0}:SmartButton
    runat=server></{0}:SmartButton>")]
    public class SmartButton : Button
    {

    protected override void Render(HtmlTextWriter output)
    {
    string onClick = "this.form.__EVENTTARGET.value='" + this.UniqueID +
    "'; this.disabled = true; this.value = 'Please wait...';
    this.form.submit(); ";
    this.Attributes.Add("onclick", onClick);
    base.Render(output);
    }

    protected override void OnClick(EventArgs e)
    {
    base.OnClick (e);

    // reset enabled state and text to the original values
    HttpContext.Current.Response.Write(String.Format(@"
    <script>
    if(document.getElementById('{0}') != null)
    {{
    document.getElementById('{0}').disabled = false;
    document.getElementById('{0}').value = '{1}';
    }}
    </script>
    ", this.UniqueID, this.Text));
    }
    }
    }
     
    Tim_Mac, Sep 2, 2005
    #1
    1. Advertising

  2. Hi Tim,

    We have reviewed this issue and are currently researching on it. We will
    update you ASAP. Thanks for your patience!

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."
     
    Kevin Yu [MSFT], Sep 3, 2005
    #2
    1. Advertising

  3. Hi Tim,

    Welcome to ASPNET newsgroup.
    Regarding on the problem you mentioed, here are some of my understanding
    and suggestions:

    first, for the ASP.NET's response stream, after we call Response.End
    method, the connection between server and client has been closed, so we
    won't be able to write data to client any more. Also, even if possible, we
    still can't do this since when we perform file downloading, we need to make
    sure only the binary data of the file could be contained in the response
    stream, no mixed content should be embeded in it.

    Also, since the download action is performed by the clientside user(open or
    save....), so there hasn't direct means for us to inform the clientside
    when all the file steam data has been writen to client. Currently, if you
    do need to do this, you can write a certain variable (session state value)
    at serverside when you start and finish write all the data to client, then
    at clientside, you use clientscript (with iframe) to contantly post back to
    server to qurey the value so as to determine whether it's ok to reenable
    the button. However, I don't think this is a good means and will cause
    performance concerns.

    IMO, I'd rather suggest you consider use clientside script to set a
    certain Timeout after which you reenable the button again.

    Thanks,

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)


    --------------------
    | From: "Tim_Mac" <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Subject: how can write to the page after Response.End()
    | Date: 2 Sep 2005 05:18:15 -0700
    | Organization: http://groups.google.com
    | Lines: 64
    | Message-ID: <>
    | NNTP-Posting-Host: 83.141.121.205
    | Mime-Version: 1.0
    | Content-Type: text/plain; charset="iso-8859-1"
    | X-Trace: posting.google.com 1125663500 22613 127.0.0.1 (2 Sep 2005
    12:18:20 GMT)
    | X-Complaints-To:
    | NNTP-Posting-Date: Fri, 2 Sep 2005 12:18:20 +0000 (UTC)
    | User-Agent: G2/0.2
    | X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
    rv:1.7.10) Gecko/20050716 Firefox/1.0.6,gzip(gfe),gzip(gfe)
    | Complaints-To:
    | Injection-Info: f14g2000cwb.googlegroups.com; posting-host=83.141.121.205;
    | posting-account=UaxKfw0AAAA4oMLJHydK195yIv1avAma
    | Path:
    TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
    ne.de!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.gigan
    ews.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:121985
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | hi,
    | i'm guessing you just can't write to the page after Response.End(), but
    | i would be interested to hear if anyone has a work around for my
    | situation.
    |
    | i have designed a 'SmartButton' control that disables itself (client
    | side) when it's clicked, and re-enables itself (client side) after it
    | is clicked.
    | the problem is when the button_click event does something like download
    | a file with binarywrite, this ends the Response. when this happens, my
    | client side code obviously doesn't get written out, and the button
    | stays in a disabled state with "Please wait..." as the text. i would
    | like the button to return to normal, so the user can click it again if
    | necessary.
    |
    | the code for the control is below.
    | thanks for any tips
    | tim.
    |
    | using System;
    | using System.Web;
    | using System.Web.UI;
    | using System.Web.UI.WebControls;
    | using System.ComponentModel;
    |
    | namespace Whatever
    | {
    | /// <summary>
    | /// A button control that disables itself when clicked, and changes
    | the text to "Please wait..."
    | /// This is to prevent duplicate clicks by impatient or novice users.
    | /// </summary>
    | [DefaultProperty("Text"), ToolboxData("<{0}:SmartButton
    | runat=server></{0}:SmartButton>")]
    | public class SmartButton : Button
    | {
    |
    | protected override void Render(HtmlTextWriter output)
    | {
    | string onClick = "this.form.__EVENTTARGET.value='" + this.UniqueID +
    | "'; this.disabled = true; this.value = 'Please wait...';
    | this.form.submit(); ";
    | this.Attributes.Add("onclick", onClick);
    | base.Render(output);
    | }
    |
    | protected override void OnClick(EventArgs e)
    | {
    | base.OnClick (e);
    |
    | // reset enabled state and text to the original values
    | HttpContext.Current.Response.Write(String.Format(@"
    | <script>
    | if(document.getElementById('{0}') != null)
    | {{
    | document.getElementById('{0}').disabled = false;
    | document.getElementById('{0}').value = '{1}';
    | }}
    | </script>
    | ", this.UniqueID, this.Text));
    | }
    | }
    | }
    |
    |
     
    Steven Cheng[MSFT], Sep 5, 2005
    #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. =?Utf-8?B?RGFu?=

    Response.Write/Flush/End

    =?Utf-8?B?RGFu?=, Jan 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,217
    Patrice Scribe
    Jan 30, 2004
  2. csgraham74

    Response.Redirect at a response.end

    csgraham74, Jun 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    911
    Karl Seguin
    Jun 16, 2005
  3. Replies:
    9
    Views:
    4,787
  4. =?Utf-8?B?RmlsaXAgRGUgQmFja2Vy?=

    page layout changes after response.write

    =?Utf-8?B?RmlsaXAgRGUgQmFja2Vy?=, May 8, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    4,694
    inibhreaslain
    Sep 20, 2007
  5. dotnettester

    Setting object = nothing after Response.end

    dotnettester, Sep 12, 2005, in forum: ASP General
    Replies:
    6
    Views:
    158
    Dave Anderson
    Sep 13, 2005
Loading...

Share This Page