How can i update hidden field value on one page from the code behind of another page?

Jimmy Genslinger

I have a page, behaviorAnalysis.aspx, that is calling a javascript that does two things: 1) Display a modal dialog with a please wait message; and 2) creating an iFrame and calling a second page, behaviorAnalysisDownload.aspx via jQuery:

function isMultiPageExport(exportMedia) {
    waitingDialog.show("Building File<br/>...this could take a minute", { dialogSize: "sm", progressType: "warning" });

    var downloadFrame = document.createElement("IFRAME");

    if (downloadFrame != null) {
        downloadFrame.setAttribute("src", 'behaviorExport.aspx?exportType=html&exportMedia=' + exportMedia);
        downloadFrame.style.width = "0px";
        downloadFrame.style.height = "0px";
        document.body.appendChild(downloadFrame);
    }
}

The second page is downloading an Excel file using the following code snippet:

//*****************************************
//* Workbook Download & Cleanup
//*****************************************
MemoryStream stream = new MemoryStream();
wb.Write(stream);
stream.Dispose();

var xlsBytes = stream.ToArray();
string filename = "Behavior Stats YTD.xlsx";

MemoryStream newStream = new MemoryStream(xlsBytes);

if (Page.PreviousPage != null)
{
    HiddenField exp = (HiddenField)Page.PreviousPage.FindControl("hidDownloadStatus");
    exp.Value = "Complete";
}

HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename);
HttpContext.Current.Response.BinaryWrite(xlsBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

As you can see, I was hoping to update a hidden field on the calling page before pushing the download through; however, PreviousPage is null. Is there another approach I can use, to update the hidden field value from the calling page, behaviorAnalysis.aspx?

zfrank

I would first recommend this jQuery library, which does exactly what you want with the background download and modal, but it's been tested cross-browser and has a lot of neato features already available: http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/

If you don't like that, you can take a similar approach to what that plugin does. Instead of trying to set the value of a HiddenField on the parent, just add a cookie:

Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });

After your first page appends the iFrame, just use setInterval() to check to see if that cookie exists with something like:

if (document.cookie.indexOf('fileDownload') > -1) {
    document.cookie = 'fileDownload=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' // remove cookie
    // it was a success, so do something here
}

Of course, you'll want to put some sort of a timeout or logic to handle errors, but that should cover the basics of it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How is a hidden field declared in ascx page so that it takes value from hidden field in aspx?

From Dev

Can I fake the originating hyperlink of one remote page to say that it came from another page?

From Dev

How to pass a value from one jsp to another jsp page?

From Dev

How do I lead client to another page and modify an uploaded file in the code-behind in .NET?

From Dev

How to carry session value from one page to another in php?

From Dev

How to enableviewstate from code behind for the whole page

From Dev

How can I track visitors’ paths from one page to another with full URLs?

From Dev

How can I pass the url of a selected image which is included in a listview from one aspx page to another?

From Dev

Angularjs pass value from one page to another

From Dev

How can i pass multiple value another page in URL

From Dev

How can I send data from one page to another using Laravel?

From Dev

Transfer value from code behind in xaml page to change expander foreground

From Dev

how to pass the value from one page to another page in angular?

From Dev

How can i get all control in another page of site in code behind

From Dev

How can I pass ItemTemplate value to another page?

From Dev

How can I display all the array value in another php page

From Dev

ASP .net get hidden value from code behind in page_load function

From Dev

How to update config file from code behind page in C#

From Dev

how to pass the value from one page to another page in html

From Dev

In mvc how can i achieve loading animation while page is transforming from one to another

From Dev

How can i refresh a asp page from code behind? C#

From Dev

How can i jump one cshtml page to another cshtml?

From Dev

How can i update the value of my rails model from the show page?

From Dev

How to transfer value from one page to another? Octobercms

From Dev

how can i get single value at next page from multiple values in another page using php

From Dev

How can I add a code-behind file to an aspx page?

From Dev

How to copy the hidden field value and pass it on another page using jquery in CodeIgniter?

From Dev

Update Xamarin Page label from code-behind (another class)

From Dev

How Can I route From One page to another when its route are in different file

Related Related

  1. 1

    How is a hidden field declared in ascx page so that it takes value from hidden field in aspx?

  2. 2

    Can I fake the originating hyperlink of one remote page to say that it came from another page?

  3. 3

    How to pass a value from one jsp to another jsp page?

  4. 4

    How do I lead client to another page and modify an uploaded file in the code-behind in .NET?

  5. 5

    How to carry session value from one page to another in php?

  6. 6

    How to enableviewstate from code behind for the whole page

  7. 7

    How can I track visitors’ paths from one page to another with full URLs?

  8. 8

    How can I pass the url of a selected image which is included in a listview from one aspx page to another?

  9. 9

    Angularjs pass value from one page to another

  10. 10

    How can i pass multiple value another page in URL

  11. 11

    How can I send data from one page to another using Laravel?

  12. 12

    Transfer value from code behind in xaml page to change expander foreground

  13. 13

    how to pass the value from one page to another page in angular?

  14. 14

    How can i get all control in another page of site in code behind

  15. 15

    How can I pass ItemTemplate value to another page?

  16. 16

    How can I display all the array value in another php page

  17. 17

    ASP .net get hidden value from code behind in page_load function

  18. 18

    How to update config file from code behind page in C#

  19. 19

    how to pass the value from one page to another page in html

  20. 20

    In mvc how can i achieve loading animation while page is transforming from one to another

  21. 21

    How can i refresh a asp page from code behind? C#

  22. 22

    How can i jump one cshtml page to another cshtml?

  23. 23

    How can i update the value of my rails model from the show page?

  24. 24

    How to transfer value from one page to another? Octobercms

  25. 25

    how can i get single value at next page from multiple values in another page using php

  26. 26

    How can I add a code-behind file to an aspx page?

  27. 27

    How to copy the hidden field value and pass it on another page using jquery in CodeIgniter?

  28. 28

    Update Xamarin Page label from code-behind (another class)

  29. 29

    How Can I route From One page to another when its route are in different file

HotTag

Archive