Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open new window on postback

Requirements: We have a form for users to submit. On submission, form data is used for calculations and generation of reports.

On postback, a confirmation message and further options are displayed. We want to display report in a new window/tab.

Conditions: We do not want to use JavaScript on postback to open a new window onload as this will stop users who have JavaScript disabled.

Possible solutions:

  1. Open a new window on button click with a unique id (let the postback happen for code execution). The new window should request report but code waits until report is generated. On report page, show a wait message which timeouts and allows user to refresh or use page refresh in meta.
  2. Use JavaScript but detect if JS is enabled on postback (by setting a variable value using JS on form load), if JS is disabled show a link to the user for report else open a window using JS on page load after postback.

Questions:

  1. Is there any better way to do this?
  2. Any tips to improve above solutions?
  3. Which one will you prefer and why?
like image 455
Usman Akram Avatar asked Oct 14 '22 22:10

Usman Akram


2 Answers

Make a link with target=_blank which redirects to a page that generates the report and then show it.

IMO users that want to access your site WILL have javascript enabled. The web without javascript is not a web, maybe it was a few years ago, but now...

If you want to test for js, you can register a script after postback:

// normal postback
ScriptManager.RegisterStartupScript(this, GetType(), "key", "script();", true);

// postback from a updatepanel
ScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), "key", "script();", true);
like image 67
BrunoLM Avatar answered Nov 03 '22 01:11

BrunoLM


Check if js is enabled, and if js is enabled use ClientScript.RegisterStartupScript(this.GetType(), "yourScript", script, true); to execute you js and open your report page. If js id not enabled show a link to the report page.

like image 29
Vinay Pandey Avatar answered Nov 03 '22 02:11

Vinay Pandey