You must Sign In to post a response.
  • Category: JavaScript

    Java script method is not firing when I am opening excel file through c# code

    Hi,

    I have java script method to display a pop message. it is working proper in normal code.
    In one scenario after displaying this pop up message I need to open an excel with c# code.
    In this scenario my pop up (java script method not firing) is not coming.

    I am using below code

    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.End();

    Please help me on this.

    thanks
  • #764451
    Hi sarayu,

    The code you had given above is the code for downloading a file in ASP.Net Web/Windows application. Whenever you execute this code, web browser will automatically opens a pop up wizard for save/open a file.
    At server side if you had written your javascript pop up message code after the above code then it will not execute it because your focus will be on web browsers pop up wizard.
    For this you have to register the script properly at server side or just write the pop up message code in javascript.

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764454
    Hi sarayu,

    After run the Response.End(); method then it's stops to run the application. May be because of that reason after open your excel it won't perform popup action.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764493
    The following code clears your response and create new response as file.

    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.End();

    The above response is coming as file. We can not run the java script in the file response.
    You can handle the about code in the ashx handler and call it separately. Once you can that you can run your javascript in your aspx page.

    By Nathan
    Direction is important than speed


Sign In to post your comments