0

I have written all the code to generate excel in an ASPX page named GenerateXLS.aspx and I am calling the export to excel from javascript as

var BudgetID = document.getElementById("ctl00_ContentPlaceHolder1_CmbBudget").value;
var BudgetType = document.getElementById("ctl00_ContentPlaceHolder1_CmbBudgetType").value;
var CompanyID = document.getElementById('<% =HidCompanyID.ClientID %>').value;
var UserID = document.getElementById('<% =HidUserID.ClientID %>').value;
var BudgetName = document.getElementById("ctl00_ContentPlaceHolder1_CmbBudget").options[document.getElementById("ctl00_ContentPlaceHolder1_CmbBudget").selectedIndex].text;
var BudgetTypeName = document.getElementById("ctl00_ContentPlaceHolder1_CmbBudgetType").options[document.getElementById("ctl00_ContentPlaceHolder1_CmbBudgetType").selectedIndex].text;

document.getElementById("iFrame_Excel").src = "../Reports/GenerateXLS.aspx?Source=BudgetReport&BudgetID=" + BudgetID + "&BudgetType=" + BudgetType + "&CompanyID=" + CompanyID + "&UserID=" + UserID + "&BudgetName=" + BudgetName + "&BudgetTypeName=" + BudgetTypeName;   alert("works now");

The problem is it is generating the excel, but only if I keep the alert at the end of the javascript function. If I remove the alert from my function, the page is getting posted back but not generating the excel file. What might be the problem? Why is it generating the excel file only if I keep the alert?

6
  • this piece of code is inside a callback? i.e. behaviour of <A> click event? Commented Feb 19, 2014 at 10:48
  • try putting this in an ajax request instead of a <a>. That way the response will get captured and your page will generate the Excel too Commented Feb 19, 2014 at 10:50
  • @Alberto No. The entire coe I have provided is in a javascript function. And I am calling onclientclick of button Commented Feb 19, 2014 at 10:54
  • 1
    do you invoke a preventDefault() on event? e.preventDefault() Commented Feb 19, 2014 at 11:01
  • @Alberto : Super. It is working with e.preventDefault(). Thank Youuuuuuuuuuuuuuuuuuuuuu Commented Feb 19, 2014 at 11:04

1 Answer 1

1

Add e.preventDefault(); to avoid reload and, if you have to go to a specific URL after function execution, window.location.href = your_url;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.