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