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

T

Tim_Mac

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));
}
}
}
 
K

Kevin Yu [MSFT]

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."
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| 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: <[email protected]>
| 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: (e-mail address removed)
| 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: (e-mail address removed)
| 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));
| }
| }
| }
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top