Design pattern for Page A waiting for Page B - asp.net

I have no idea what this design call.
I have a page A, with a Link in it.
Click on the link, will open page B in NEW WINDOW/NEW TAB.
Page A now shows a 'Waiting for Page B' message.
input data in page B, click save, and close page B.
page A will notice that page B is closed, and display the input from page B.
I think there is some trigger in page B's unload event, but how does page A notice page B is closed?
Any idea anyone?

To make a long story short, you basically need to rely on some server-side operation to manage the "state" between these two pages.
There are a lot of approaches to be taken here, but ultimately, they are going to rely on some form of client-side polling, as an asynchronous event fired from Page B (like your 'Save' operation) won't inherently have the ability to modify the state of Page A upon returning.
Implement a timer in JavaScript to check a server value every few seconds from Page A, and make sure the 'Save' operation from Page B sets that particular condition on the server when it executes. Page A will detect it and can transition state.

Try window.postMessage.

Related

Can I cancel the loading of a asp.net control inside an iframe

I have an iframe on my page. Basically, the iframe hosts a user-defined control (let's call the control C). At Page_Load, this control C queries a database and displays the results in an ASP:DataGrid control
As of now, while the control C is loading its data and I try to navigate away from the page, the browser won't navigate to the new page until the data for the control C are loaded.
I wonder if there's a way to programmatically stop the the control C from finishing its loading process (something like the stop button on a browser)? I can stop the iframe from loading (i.e. trigger the iframe onload event before the control C finishin loading), but the brower still doesn't navigate away until the control C finishes loading its data.
I wonder if there's a way to programmatically stop the the control C
from finishing its loading process (something like the stop button on
a browser)?
From the moment you ask for an other page, the control that make a long loop can only understand if the client is close his connection and must stop what he is doing by detecting that, and here is a code snippet for that.
if (!Response.IsClientConnected){
HttpContext.Current.Response.End();
return;
}
Now the only reason that your page is wait to finish what the previous action do, is the session lock that asp.net have by default and lock each request by the same user to keep a good synhronization. If you use the code to check if the use is still connected, I believe that you have what you ask.

How to return control to function after page transfer

I'm working on my first web forms application and I'm running into an interesting problem. I have two pages in my application- one is the main page where the user can manipulate information on the page, and the other is an information retrieval page that lets the user select which information he/she would like to see on the main page. I have a function attached to a button on the main page that immediately uses Server.Transfer to send the browser to my selection page. After the user selects some data, they press another button that uses Server.Transfer to send them back to the main page. I had thought that the flow of the program would return to just below the first transfer call, but it looks like the browser is just reloading the main page in its original state.
The question is as such: how do I make it so that the program flow will return to the place that it left in my function so that I can retrieve information from the previous form and do something with it? Thanks in advance!

ASP.NET back and forth between screens

I am working on an application, where a user can start filling a (multipage)form and press back button to navigate to previous screen and continue button to navigate to next screen.
Currently, the page was implemented using the browser's back capability. This causes circular reference
The Scenario is
Navigate from page 2 to page 3 click back button on page 3
User is now in page 2 and clickint back button pn page 2 will take it to page 3 (because of browser's history has page 3.)
This has to be achieved by using session? How can this be implemented correctly? What options does asp.net provide?
Have a look at the Wizard control - it's designed for your sort of scenario where you have multiple pages and you want to go back and forth between them. And you can combine it with AJAX to avoid postbacks :-) ScottGu has a piece on it here.
You can save all steps in session variable, for example of type Queue. When you need return two steps back, simple, two times dequeue and go to uri.

ASP.Net save after hyperlink is clicked

I have a requirement to call a save method, that persists a model/object in the session, when the user leaves the page.
The page has various links that do not raise a postback but just perform a redirect. Are there any ASP.Net page life cycle methods I can hook into to perform the save without requiring a postback?
One solution could be to perform an asynchronous POST request (without waiting for a response) when the window is being unloaded:
An example using jQuery:
$(window).unload(function() {
$.post(location.href, $(document.forms[0]).serialize());
});
Although you will probably need to use a slightly different method for Chrome (found on jQuery forums):
It looks like the only way to get the
Ajax request to go through in Chrome
is to use the non-standard event
onbeforeunload. Chrome evidently
doesn't wait long enough to send the
Ajax request using onunload. It does
however wait for alerts...
Well that depends.
If you need to save values when the person leaves the page, then thats kinda hard.
What you can do, is to wrap all your links in some jquery, that says like:
Issue a Ajax Call, to AjaxSave.aspx, then it is completed, then window.location to the links href attribute.
BUT, that will only work if the person clicks on your links, not if the person just closes the browser or something.
You can also take the route to just save the stuff offen, so every time the person issues a post back, you just put the stuff in session. But that will mean that values changed from the last postback to the navigating away from the page is lost - don't know if that is an issue.
The last thing is to do like StackOverflow is doing. If you are editing stuff, it will show a warning when you leave the page, and then you have to click okay, to navigate away from the site.

how to intercept processing when Session.IsNewSession is true

I have a small 4-page application for my customers to work through. They fill out information. If they let it sit too long, and the Session timeout out, I want to pop up a javascript alert that their session has expired, and that they need to start over. At that point, then redirected to the beginning page of the application.
I'm getting some strange behavior. I'm stepping through code, forcing my Sessioni.IsNewSession to be true. At this point, I write out a call to Javascript to a Literal Control placed at the bottom of the . The javascript is called, and the redirection occurs.
However, what is happening is.. I am pressing a button which is more or less a "Next Page" button and triggering this code. The next page is being displayed, and then the Alert and redirection occurs. The result I was expecting was to stay on the same page I received the "Timeout", with the alert to pop-up over it, then redirection.
I'm checking for Session.IsNewSession in a BaseClass for these pages, overriding the OnInit event.
Any ideas why I am getting this behavior?
Thanks!
There multiple ways u can do this. Have hava Script timer as per u session timeout (Default is 20 min). After 19 min just rasise a alert on client and submit the page to the same page to refresh. This may not good option given user would have entered lot of stuff already
Or other way is don't session time out this page. U can do this on back ground just refresh the page after 19 min (U can do this by placing one div and iframe or image request on the server.). This might be good experiance for the user the reason is he don't have to enter the content again. Talking to u client giving this kind of option is worth sometimes.

Resources