ASP.NET back and forth between screens - asp.net

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.

Related

Preserve selected option with back button, using jquery mobile & asp.net & ajax

I thought this would be a trivial feature, but I have lost a fair bit of hair trying to figure it out. I have a jquery mobile web page with a select menu. Users click an item in the drop down list, then later click on a link and navigate to another page. Users then click the back button. The desired result is that the selected item remains selected. Right now, the selection is lost, and it defaults to the first element in the list again.
Things I've tried:
1) Use an asp.net dropdownlist with autopostback. This preserves the selected option, but then I get a page flicker because the entire page is posted back.
2) Wrap above asp.net dropdownlist in an updatepanel. This preserves, doesn't flicker, but it wipes out the jquery mobile styling. Also tried some suggested workarounds with firing a jquery create event, but couldn't get anything working.
3) Write cookies on the select change event in javascript, and read them in the asp page_load event. However, page_load is not called when the back button is clicked, so this had no effect.
4) Tried creating a jquery ajax request to a web page method, but the method must be static and therefore I can't get it to modify the page.
Any other ideas? Is it just me or should this indeed be a problem that's been solved a million times?
As an FYI, I am a newbie at web programming, so please spell it out if you have an answer :) (come from a c++/database background).
Thanks!
Turns out even the date scroller could not survive a back button in some cases. For example if the user navigates to another site, and then uses the back button to come back to my jquery mobile site, all my javascript dom manipulations are lost. The solution is non-trivial. I store everything I need to maintain state of a page using html 5 local storage. On the jqm show page event, I detect if all my global variables have been wiped clean, and if so, reload state from local storage. Works perfectly, but it is quite an implementation task. And of course, if local storage is not supported by underlying browser, it all falls to pieces.

Scenario - How to improve user experience using preload of pages and delayed save of web pages in ASP.NET

I have a ASP.NET website and say it has 2 pages. I am displaying these 2 pages as 2 tabs. Both pages have some input fields like check boxes, radio buttons, dropdowns.
When I move from tab-1 to tab-2, I have to perform the following operations.
I need to save the data entered on tab-1. This is currently handled in tab-1's PageLoad when user clicks tab-2 on the screen. I have made a DataSave() method, which is called in the PageLoad for IsPagePostBack equals true.
Once the DataSave is completed, I exit from tab-1 page and call the PageLoad of tab-2.
In tab-2, I created a DataLoad() method, which brings all the data for controls on tab-2.
Now when I enter all the data on tab-2 and click tab-1, the same steps 1 to step 3 are completed for tab-2 and tab-1.
This process takes a lot of time. The user is shown saving of first tab and then loading of second tab everytime.
Is there a way, that I can load the controls of second tab (or as many secondary tabs I have) in the background when the user is working on tab-1. And when the user clicks the second tab, he is displayed the second tab instantly while the tab-1 data is saved in the background.
I hope I was able to explain my problem.
My answer is contingent on the data on both pages not becoming huge because then you could hamstring one tab at the expense of the other... But what you could do to get this affect is load tab 1 and tab 2 on the same page. However, load only the data for tab 1 on page load and load the data for tab 2 async w/ ajax or something. That way, Tab 1 SHOULD load just as quickly as ever, but tab 2 would load behind the scenes, such that when the user changed tabs, the data would be there and it would feel almost instantaneous...
I get that I haven't provided a code sample... I can give you some ideas, but I would probably use jquery's ajax functions to load the data on tab 2...

Read page from cache on Back but not when clicking a link to the page

I have a set of interlinked dynamic web pages.
When the user clicks from one page to another, I don't want any caching to happen - the request must go to the server, which will return an up-to-date page.
But when user clicks Back, I do want the cache to be used - some of the pages can take some time to generate, which is fine when you're clicking through to them, but not when you're clicking Back.
Is this possible?
(Please don't suggest re-engineering everything as a single page making AJAX queries!)
(Note: this question is the opposite of the ever-popular "How do I prevent caching when the user clicks Back?" question.)
A common trick for avoiding the browser cache when dealing with dynamic pages is to add a parameter to the link url that is unique (using the time, to the millisecond is common).
When the user hits the 'back' button, they will go back to the last rendered version, and should get it from the cache.

ASP wizard browser back button

I used asp wizard with updatepanel and google map (it works great).
Wizard has 3 steps - all work's great, but when i click browser back button steps changed and i lose all previous information. When i click wizard previouse button - i can see my information.
i try this:
http://dotnetslackers.com/articles/ajax/HandlingTheBackButtonFromServerCode.aspx
but ScriptManager1.IsInAsyncPostBack always is false, and a hasn't hisotry - second problem: i want to get all information in this step
Maybe some other solutions??
It seems you want to put a square peg in a round hole.
If you want to navigate the wizard, use the wizard previous, next and finish buttons.
The browser back button is to move to another page, which is not a typical ajax application workflow and most definitely not the proper way to navigate a wizard control.

Implementing Back button functionality in asp.net

i need to implement a back button for my asp.net website.I am able to use the javascript method to acheive my requirement.But using this method sometimes I need to click on the back button multiple number times to go back to the previous page.It may be because we are using jquery tabs in our website.To focus on a particular tab,other than the 1st tab on page load I am using Page.ClientScript.RegisterStartupScript(....).So I am unable to take the user back to the previous page with just one click.
I also tried with asp.net-C# methods mentioned in the following link.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=89
I am able to go back to the previous page, but its state is being lost.Could someone please help me in acheiveing my requirement?
Details:
I have page1.aspx,page2.aspx(which contains jquery tabs view/edit).
In the page1.aspx there are 2 buttons(View,Edit).If I click on view button it takes me to page2.aspx View tab(1st tab) and if I click on the edit button it has to take me to page2.aspx with Edit tab loaded.both View/Edit tabs contain back button.
Also from the View tab I can navigate to the Edit tab,by clicking on another Edit button present in it.
Thanks.
The methods you have covered in your question are essentially what is available to you.
You can either
1. Provide a link that uses javascript to make the client go back a page.
2. Provide a link that posts back to the server that redirects you back a page.
I am not sure why the jquery in your webform as described in your question is causing you to click more that once to go back. If you know that it will always take 2 clicks to go back you could try this method:
javascript: window.history.go(-2)
When you are using the postback/redirect method you will always be using a http GET method to retrieve the page you are returning too. If you want to maintain state you will have to do this manually i.e. save the values when leaving the page somewhere, like session or a temporary database, and when returning to the page, during the page load, check to see if the user has these values saved and pre-populate them.
I've done something similar (with automatic redirections though) and I had to keep track of the number of pages to go back in my ViewState (or Session if you're jumping from page to page):
code-behind
public void Page_Load()
{
Session["pagesToGoBack"] = ((int)Session["pagesToGoBack"])++;
}
mark-up:
<input type="button" value="Back" onclick='javascript:history.go(<%= Session["pagesToGoBack"] %>);' />
Be careful to reset the session variable when needed
Made me feel a bit dirty but it worked :)

Resources