listview itemcommand not firing after back button - asp.net

I have page that uses a multiview. Each view contains a separate user control. One of these user controls has a list view with an image button that causes the loading of a different view in the multiview. All is fine up until this point. When the user hits the back button, they are taken back to the user control that contains the list view. The user then clicks on another image button to view different data and it returns to the detail user control using the same data as before. While debugging, I have seen that the item command event does not fire after hitting the back button.
I have tried replacing the multiview and putting each user control into separate panels. This did not change the outcome at all.
I have tried setting a cookie that expires 5 seconds after page load. When the user continues to the next page, then clicks back (and it has been longer than 5 seconds), I force the form to submit again. This loads the next control again instead of reloading the page.
I have tried setting the cacheability to no cache. This causes a "page expired" message and the user has to refresh the page. This is ugly for the user and definitely takes away from the user experience.
I am looking for the cleanest way for a user to click back and have the page reloaded so that the item command event fires correctly again.

The reason is that Back doesn't affect the Page Life Cycle. It's definitely because the page is cached and cached page doesn't execute on server. You can try this code to get rid of this issue.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

It took a lot of research to find this answer, so hopefully other people stumble upon this question and find my answer. I was astonished that I was actually able to find this. Ok, enough gloating.
Because the page does not postback when the user clicks the back button, the events are not fired correctly causing problems with the next page. What has to happen is you need to be able to handle the browser's navigation buttons (i.e. back and forward). To do this you have to set EnableHistory to true within the script manager and handle the Navigate event from the script manager. You can then reload the controls using the information you save in the state object.
I used these articles from Dino Esposito on DotNetSlackers.com as a reference. Server Side History Management and Client Side History Management

Related

asp disable button for the whole session

I would like to disable a submit button on a webform like proposed in:
How to disable postback on an asp Button
But the button should stay disabled, even when the user navigates to some other webpage in the application (like admin page) and then navigates back to the original page; (in my case the button is then not disabled anymore). So is there a way that this button stays disabled (for instance until the user logs off from the application) even in such events and for the whole session until the user logs off?
Thank you for your time and effort.
Add a session variable, example Session("btnDisabled") in the event where you want this to happen and check against it every time a page with the button loads.
If session("btnDisabled")=true then btnSomething.enabled=false
then when the user is logged out, you change that variable, either kill it or set it to false.

How to have radlistview paging maintain it's index when the back button is pressed?

The scenario is that i have a list view with paging. If the user is on page 4, then clicks a link, decides that its the wrong link, then hits the back button, the listview need to be displayed with the same sorting on page 4, just like he left it. Currently, it is resetting the sort and displaying on page 1.
I tried storing the current page index in a session when the index is changed, then setting it from the session in the prerender event, but then i get "page expired" errors. Any ideas? TIA
The back button operation can only be handled in client-side javascript, as the server-side code does not run. For what you are trying to do, you'll want to check out these two resources (application history points):
http://msdn.microsoft.com/en-us/library/cc488548.aspx
http://msdn.microsoft.com/en-us/library/cc488538.aspx

UpdatePanel + Validators works! Stops async requests for sometime after validation tho

This is not the same old question about the validators and update panel compatibility.
Here's my scenario:
I have a aspx page with a script manager. This page has a ascx user control with my functionality. In this control, I have a few panels and areas which will get enabled/disabled or visible/hidden according to what the visitor selects by clicking on some of the radio buttons which will control this behaviour.
Everything is fine until this point. Validators and UpdatePanel are not fighting against each other, however, if I try to submit the page without filling the form, I get a validation message on my summary and it's all good with the validation itself.. Here's the problem, the radio buttons, which are responsible for set visibility for some areas stops working, but it starts working again after the 2nd or 3rd click. It's not delay or anything.. it just seems like the handlers are not bound to the control, then I click again, and it cleans up the summary and all error notifications and starts working again..
I don't know if it adds to the issue, but both the user control and the page have telerik controls such as combo box with load on demand, tooltips and the loading panel..
I have searched a lot about it and all I could find was the question regarding the validation controls not working inside updatepanel or updatepanel not working with validators.. in this case, it actually works, I only have problems after the validation has been performed and the page.isvalid is set to false..
To me it sounds like there is a server error in the first request ajax is sending. So here is my recommendation:
Open your web page in Firefox, then open Firebog and select "network" tab. This tab shows you every single request the browser sends to the server (including request for scripts, images, ... and also ajax async requests).
So now clear the list under "network" in firebog and trigger your ajax for the first time, see if there is any request sent to the server. if there is you can see if the response is a OK 200 response or a 500 server error and ofcourse you can see the full details of the error.
Hope this helps.

IE fails to repopulate form after file download and history.back()

I have a web page that has a button that when clicked will download a file for the user. However after the download if the user clicks on the back button the previous form is displayed but the form fields are all blank.
If the user clicks back without performing the download then the form fields are automatically repopulated by the browser as expected.
This bug happens in IE6 and 7 but seems to be OK in 8 which suggests it was a bug that has been fixed in IE8.
Anyone have any idea how I might work around this in IE6 and 7?
There is definitely nothing you can do on the server side, as the browser does not inform the server when the user presses the back button. I'm not even certain if the browser has an event that you can use JavaScript to capture, but if there is a solution, it would have to occur on the client side.
I think we are going to rewrite the page to replace the use of the browser back button with a postback to return the user to the original page. Then we can pass the original form data back and repopulate the form programatically.

Prevent a PostBack from showing up in the History

I have a page where I submit some data, and return to the original form with a "Save Successful" message. However, the user would like the ability to return to the previous page they were at (which contains search results) by clicking the browser's "Back" button. However, due to the postback, when they click the "Back" button they do not go to the previous page ,they simply go to the same page (but at its previous state). I read that enabling SmartNavigation will take care of this issue (postbacks appearing in the history) however, it has been deprecated. What's the "new" best practice?
*Edit - I added a ScriptManager control, and wrapped the buttons in an UpdatePanel, however now I'm receiving the following error:
Type 'System.Web.UI.UpdatePanel' does not have a public property named 'Button'
Am I missing a reference?
*Disregard the above edit, I simply forgot to add the < ContentTemplate > section to the UpdatePanel :P
If you put your "Save" button in an UpdatePanel, the postback will not show in the users history.
I would avoid if possible. A better solution would be to have a button that just returns them to their search results on the "Save Successful" screen.
The problem with the ajaxy saving and such is that you violate the "Back" rules that users expect. This user might want the Back button to go back to the Search page, but other users might expect that clicking Back would return them to the Add/Update page. So if another user tries to update something, clicks save, and then "woops, i forgot something on the update", they'll click back, and now they're at search results, instead of the expected Update page.

Resources