Do you think it's possible to refresh an update panel and immediately after redirecting the response (for instance a download) ?
I tried this:
an invisible button -> as an asyncpostbacktrigger
a download button -> when it is clicked the onclientclick clicks the invisible button
However for some reason when the invisible button is clicked by the download button client script, it doesn't refresh the update panel..
Do you have an idea why it doesn't work? Or do you have other and cleaner techniques?
Here's how the elements are declared:
<asp:Button runat="server" ID="ButtonInvisible" Text="" Click="RefreshDisplay" />
<asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="clickInvisible(this.id)" Click="Download" /><Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonInvisible" /></Triggers>
//the javascript
<script type="text/javascript" language="javascript">
function clickInvisible(idButton) {
document.getElementById('ButtonInvisible').click();
}</script>
'
//the methods
Download(object source, EventArgs e){Response.Redirect("test.txt")}
RefreshDisplay(object source, EventArgs e){ ButtonCancel.Enabled = false;}
I have had a similar problem and solved it by using the hidden IFRAME trick . No invisible button required. In fact, my version does not even require JavaScript:
protected void Button1_Click(object sender, EventArgs e)
{
// update some controls in the UpdatePanel
...
// add an iframe which will start the download at the bottom of the UpdatePanel
var iframe = new HtmlGenericControl("iframe");
iframe.Style["display"] = "none";
iframe.Attributes["src"] = "http://...download url...";
iframe.EnableViewState = false // we only need the iframe for this one postback
myUpdatePanel.ContentTemplateContainer.Controls.Add(iframe)
}
Is the RefleshDisplay
only going to disable the ButtonCancel button? Then you can do it in plain JavaScript without using any trigger:
<asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="disableCancelButton()" Click="Download" />
<script type="text/javascript" language="javascript">
function disableCancelButton() {
document.getElementById('<%= ButtonCancel.ClientID %>').disabled = true;
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.