开发者

After disabling a Submit button with JS, re-enable after file download

I'm working on an ASP.NET application. Currently when the user clicks "Save" on an item, we disable the Save button, change its text to "Saving..." and so on. This works fine, because the button causes a postback which results in a new page being loaded, on which the Save button is no longer disabled.

We now want to apply this to other actions: Publish (not much different from Save), Import (again, much like Save, but based on data the user has uploaded in a previous step), Export (downloads an XML file to the user) etc.

Export is causing me problems - the button stays disabled. I think this is because the server sends back an XML file rather than a new web page, and so the browser just displays the same page.

The server-side code is along the lines of

Response.Clear();
Response.BufferOutput = true;
Response.ContentType = "text/xml";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + whatever);
[push file contents into Response.OutputStream]
Response.End();

[No idea if this is good code or not - it's not mine - but it does the job :)]

Basically, I'd like to know either:

  • a way of making the server send a fresh page back in the response as well as the XML, thus re-enablnig the button in the same manner that the other pages开发者_运维技巧 do, or
  • a way of getting the browser/JS to re-enable the button once the file has been sent.


Looks like this should do it: essentially, set a cookie with the file response, and have the browser waiting for that cookie in order to unblock the page.


The problem probably is that you do not load a new page at all.

Since content disposittion is attachement, the browser will not reload the page but only save the return from the server to disk.

You need to reload the page some how but I have no really good idéa on how to do that after a file fetch.


There is a dirty hack. You can use setTimeOut method to enable and change back button caption/image.

So you can write a server side code similar to

btn.Attributes.Add("onclick", "this.disabled='true'; this.value='Processing...';_doPostback(this,null);setTimeout(function() { enable button logic....set the text /img of the button}, );");

The server side download attachment event will not be synch perfectly, but you can set timeout as 2-5 seconds depending on your server configuration.

Thank you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜