Avatar of Explorer JK
Explorer JK
 asked on

Asp.net - C# - Disable button / lock screen after download is complete on the browser

Hi,

I am using xmlwriter to create XML document  from excel, I am able to create XML document and able to provide an option to the user to save the file on their computer.

However when download completes the form is still open and all button are accessible. I would ideally like to disable  the "Btn_Process " btn when the download starts or ends , I have used the option to disable to the button at all stages on click event of the button and also below in the finally statement , but the btn does not get disabled.

I would like any of the following :
1. Disable button Btn_Process on click of the btn or after the download completes
2. Lock screen when downloading is in progress then unlock
3. Redirect to the same page after download is complete

Thanks in Advance

The code is as follows:
try
                {
                    CreateXML(TableA, TableB);   //Call Create XML Method 
                }
                catch (Exception e) { //Ex catch}
                finally
                {
                    Btn_Process.Enabled = false;
                    HttpContext.Current.Response.End();
                    Server.Transfer("Excel2XML.aspx");
                    
                }

Open in new window


The above CreateXML method has the below xmlwriter For creating the XML file :
           
string name = string.Format("attachment; filename=HDCLv1_NYC_{0:yyyyMMddHHmmss}.xml", DateTime.Now);
            HttpContext.Current.Response.ContentType = "application/xml";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.BufferOutput = false; 
            HttpContext.Current.Response.AppendHeader("Content-Disposition", name);

 using (XmlWriter writer = XmlWriter.Create(HttpContext.Current.Response.OutputStream, settings)) {  

                writer.Flush();
                writer.Close();
                HttpContext.Current.Response.Flush();

Open in new window

ASP.NETC#XML

Avatar of undefined
Last Comment
Explorer JK

8/22/2022 - Mon
SOLUTION
Ess Kay

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Explorer JK

ASKER
Hi esskayb2d

Thanks for your reply, I was thinking of using client script and you gave me a good option of hiding the button, the hide button is working however out of scope I did try to disable the button but thats not working , as I am using the asp.net , I am using the following to identify the button " FeaturedContent_" is added automatically to the button name by asp.net, so manually added the ID.

<script type="text/javascript">
              $(function () {
                  $('#FeaturedContent_Button1').click(function () {
                      $(this).enabled = false;   /* tried $(this).disabled = true;  both are not working */
                  });
              });

Open in new window


Any idea why its not working?
ASKER CERTIFIED SOLUTION
Explorer JK

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Explorer JK

ASKER
The implemention suggested by esskayb2d was good but not using Asp.net functionality.

The one I found where we are using asp.net functionality.

Thanks esskayb2b.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck