Freigeben über


Redirecting in EP user control to download a file

If you have a webpage to generate files such as word doc or pdf and you need to invoke them in a button click event of an user control used in EP and allow the user to download the file through the browser. generally you would think of calling response.redirect function. This function redirects to the download page and since it sets the mime type as the respective file, it prompts the user to save the file to the local machine or open it using the right application. Since AX usercontrols inherently uses AJAX postbacks, the postback progressbar will continue to display "Loading Information" even after the file is downloaded when response.redirect is used. This is because response.redirect supposed to replace the current page displayed in the browser, but in this case it actually streams file and does not replace the currently rendered page in the browser. For such scenarios, instead of using response.redirect, you could execute a client side javascript to push the generated file in a new browser window and avoid the above issue.

 

protected void Button1_Click(object sender, EventArgs e)

{

AxUrlMenuItem menuItem = new AxUrlMenuItem("EPDocuGet");

DataSetViewRow row = dsEPCustInvoiceJournalInfo.GetDataSet().DataSetViews[0].GetCurrent();

AxTableContext context = AxTableContext.Create(row.GetDefaultTableDataKey(row.DataSetView.Metadata.RootDataSource));

menuItem.MenuItemContext = context;

//Response.Redirect(menuItem.Url.ToString());

string downloadURL = "window.open('" + menuItem.Url.ToString() + "', '_blank', '' );";

ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", downloadURL, true);

}

Comments

  • Anonymous
    September 21, 2009
    Hi Mey, Good stuff again.  But I have a question, probably not related to redirecting, rather EPDOCUGET itself.  How (the best way) would you implement EPDOCUGET if there's "more than one" file associated with a record (i.e. ItemId)?  My plan is to show all the attached documents related to an ItemId in EPCSSItempDescription.aspx.  Thanks much in advance.  Thx. Kind regards, JL