I have an .aspx page in which I dynamically add web controls to a panel.
The problem is when I hit the browser's back buton, it's displayed a version of the page that no longer exists on the server-side, because the controls are dynamically added.
Let's say my aspx dynamically adds Control1. From there, I click a button that loads Control2.
At this moment, if I press the browser's back button, it will display the page with Control1, but Control1 no longer exists on the server-side, so if I interact with it, some erractic behaviour will occur. Any ideas on this?
Thank you very much.
Have you tried setting the client side to not cache pages - stick this in your page load:
Response.Cache.SetCacheability(HttpCacheing.NoCache)
(Think the syntax might be slightly off, but you should be able to figure it out)
Have you tried with removing temporary files and restarting browser. Your page might be cached in browser.
Related
I have an ASP.Net web app which has a page with various GridViews shown in Jquery tabs. This works fine in Firefox and Chrome but the page is slow to render in IE. So I thought instead of loading all the gridviews at once, i'll just load them as and when the user clicks on a tab.
So I have set up a new aspx page which accepts parameters of what to show. This all works fine in all browsers and the page is now nice and fast in IE.
However, IE has come to bite me again, because as soon as the page hits a postback it generates this exception:
The state information is invalid for this page and might be corrupted.
From what I can understand this is because the GridView control that is loaded via AJAX has to be inside a <form> tag with runat="server" and this is changing the viewstate of the overall page. So when it postbacks the original page it seems to have lost its viewstate.
I then tried to turn off the viewstate in the aspx being included. Via EnableViewState="false" but this still doesnt work.
I'm confused how Chrome and Firefox are ok, but only IE is getting the ViewState error. Is there anything else I can do to ensure the sub-page does not alter the ViewState in IE?
Perhaps if ASP.Net didnt detect the browser as being IE, it wouldnt do whatever it is doing to break the page?
Set the enableEventValidation attribute in the web.config file for the asp.net application to false.
If using IIS6, make sure IIS compression is turned off.
If is possible, add OnClientClick event to button, that cause the postback, and call a function that removing added controls via ajax.
In the end, after lots of research I don't think what I was trying to do is possible.
As a work around I opted to insert an iFrame within the jQuery tabs, and then load the gridview in that. This then doesnt upset the viewstate of the parent page.
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.
I am working in ASP.NET (framework 2.0) with Master Pages.
I have a page that requires registration and then the user gets kicked back to the referring page.
I need to figure out how to provide a success lightbox that appears over the referring page, not the registration page (the event is fired on form submit).
I have the inline stuff in the master page and the scripts and everything fires just fine but the form is refreshed with the new (referring) page and the DIV gets hidden again.
Is sessions the only way to go here? Is there a way of having one lightbox appearing from the master page regardless of what the sub-pages are doing?
Thanks.
There should be a successful registration event. Can you emit some javascript in that scenario that would cause a redirection to the referring page. You could pass a parameter which would indicate that a light box should show up. I don't think you can redirect directly from successful registration because I am guessing that some cookie would need to be set- which the framework should handle. I might be off, but that is where I would start. I would try and avoid Session if possible.
I have a page with a about 200 controls on it and Submit, Close , SavenClose and Cancel buttons. My requirement is to clear the browsing history once any of these buttons are clicked.
As of now I am redirecting the users to the Home Page once any of these buttons are clicked where the users can click on GoBack on the browser and come back to main page which I dont want to .
Can anyone help me achieving this , probably give me a start up code pls.
Thank you.
You can't
This functionality is specifically within the browser's domain, and can't be accessed via javascript. It is for this reason many banks and organisations log you out when clicking 'back'.
You can however request the browser to not cache your pages, so clicking back will result in a "Cannot find this page - you need to refresh" message, this may be a suitable solution for you and is widely used.
I'm not sure but I think it's not possible to have control over a user browser functionality like "delete history".
You could add this javascript on the top of each webpage:
window.history.forward(1);
The user's browsing history is theirs to control. The best you can do is ask to close the tab via Javascript on the page after they submit. You can do this via window.close()
I have an ASP.NET page which has an asp.net button control in it. When the user clicks on the button, the page will do some calculations and then close itself, but when I click on the button during post back, the page shows a blank screen. I want to show a loading message instead of this. I used javascript to show a div which was hidden intitially and shown when the user clicks the button, but when the post back happens, the screen becomes blank. Any idea how to show the loading messsage in this scenario?
Thanks in advance.
Do you really need to avoid ASP.NET ajax or JQuery?
If so: move the heavy processing into an invisible IFRAME. Action your form to the invisible IFRAME, or use javascript to set the location of the IFRAME.
Your 'loading' javascript will display fine. When the form inside the IFRAME completes it just needs to output some javascript to tell the 'parent' to go to location or refresh.
If you use Ajax to post back to the form asynchronously, you can use the UpdateProgress control. Here is a link to an article explaining how to implement the functionality:
How to make a Gmail-like loading indicator with ASP.NET Ajax
Basically, you can't using just postbacks. The browser draws the screen white while waiting for a response from the server. That message you set to show when the user clicks a button was the correct approach (so good work).
But the browser drew the screen white, thinking "Oh boy I'm about to get a response!" and then waited for longer than you think is appropriate.
The only thing you could try would be, in the response, make the very first thing to stream to the browser some sort of loading message that the browser can display while loading the rest (like the gmail loading screen). But personally, I think you could spend your time doing some other development.
You could try other techniques with AJAX though.