I am using a ListView for displaying list of items in a List page. I am also using DataPager control in my page for paging.
PROBLEM
While I am in the middle of the List let 5th page out of 10 pages and going to another page then clicking browser back button I am again comming back to my list page with page number showing 1st page out of 10.
What could be the solution.
Thanks in advance.
ASP.NET uses PostBacks to manipulate the state of the form, such as paging. What this means is that every interaction on the page - a button click, a LinkButton click - is really just submitting (posting) a form back to the same page. Hence the name, postback. An unfortunate downside of this approach is that it breaks the back button.
One possible fix is to use the Post/Redirect pattern which is becoming more common with ASP.NET MVC, but the principles still apply. However, I'd strongly discourage using widely in your application, as it would essentially double the amount of requests.
Related
I have created a page in ASP Web Pages with WebMatrix, where I use a WebGrid with paging to show the data from a query. I also have a search form on the top to search though the database. The rows are clickable, and when clicked it goes to a details page for that row, but when I go back, the WebGrid is reset. Is there any way to save the state of the webgrid, and eventually the filled search forms if they have been used, when I go back? It seems to me that when I just go back, without refresh, the page doesn't query the database again, because it is faster than refreshing. But the WebGrid is reset anyway to the first gridpage.
Can someone help?
I also noticed that WebGrid to go to its other pages. Does it retrieve all rows in the beginning or everytime in paging?
I've got a master page with a section for subnavigation links on it:
<div id="sub_nav" runat="server"></div>
I programatically populate this with Hyperlinks when my main asp:Menu data is bound depending on the address of the page I'm on.
This works fine and all my correct submenu stuff shows up on each page. The problem is that when one of these pages does a postback, I lose all the links that were in my sub_nav div.
Now, I could just populate the div with links every time regardless of whether the master page load is a postback or not, but I figured there is a better way of doing this. I was thinking enabling the viewstate on the div and links inside it might persist them through postbacks, but apparently that is not how viewstate works.
What is the correct way of doing this?
Viewstate only stores the current state of a control and not the controls by themselves. If you are dynamically adding controls make sure to add them on page init method irrespective of postback
This MSDN sample should help you.
According to the excellent article TRULY Understanding ViewState, that's not really the purpose of ViewState. Furthermore, ViewState costs additional bandwidth so in general we want to avoid it if possible. It sounds like this data should be "cheap" to obtain (cacheable or whatnot), so I'd definitely populate it on every request and disable ViewState on those controls.
To understand the main purpose of ViewState consider a page with two buttons, btnA and btnB and two labels lblA and lblB.
When the user clicks btnA , the page posts back and sets lblA to "You clicked A!".
When the user clicks btnB, the page posts back and sets lblB to "You clicked B!".
With ViewState, the page remembers that lblA.Text was set to "You clicked A!" previously and restores that value. Without ViewState, if the user clicked A and then B, the page would only display "You clicked B!" because there's nothing to store the previous value of lblA.
in my ajaxified page i have used several user control shifting from one user control to anothe r and then pressing the back button takes me to first page instead of previously filtered page
how to solve this
all this filters are linkbuttons i am also using listview these filters are actually filtering the content of this listview
You may take a look at the jquery history plugin. If you are using UpdatePanel to perform the AJAX requests you might find this article helpful as well as this video.
I selection page that has a gridview that presents the user with a list of data items that they can click on to "drill into" - redirecting them to the data maintenance page.
Because the list can get long, we have a series of check boxes and drop-down lists at the top that act as filters.
We just implemented an UpdatePanel with an UpdatePanelAnimationExtender so that when the page made long trips back to the databse, they would get a nice "Processing..." pop up.
Problem is, this seems to break the viewstate on the drop-down lists and check boxes. Now, when they go to the 'detail page' and hit the BACK button to get back to the 'selection' page - the selected values in the checkboxes and drop-downlists are back to their initial defaults. The lists are still populated, but they 'forgot' what they had when the user clicked to the data maintenance page.
I took out the .aspx code for the UpdatePanel and the animation extended and retested and everything worked perfectly. So, apparently, the UpdatePanel and/or the AnimationExtender doesn't play nice with the viewstate.
Is there a way I can stop the UpdatePanel's actions from, in effect, zeroing out the '.SelectedValue" properties?
First I would remove your "filtering" controls from the UpdatePanel. Assuming that the data for these controls are valued on Page_Load, they do not need to be refreshed every time the filter is applied to the GridView. Only the GridView is being refreshed, so it's likely that it is the only control that should be contained in the UpdatePanel.
Each of the filtering controls can be added as a trigger for updating the UpdatePanel by declaring them in the section of the UpdatePanel control. Or, if the filtering process is invoked by a "submit" like button, that would be the control to be declared in the section. This should retain the values of the filtering controls in the browser's cache.
You can also try Nikhil Kothari's UpdateHistory control (Nikhil has an excellent blog, btw) which will save the contents of the UpdatePanel as history entries in the browser's history list.
EDIT: FYI, UpdatePanel does not "kill" ViewState. The ViewState is transmitted back and forth via the UpdatePanel's update mechanism, often causing performance issues if the ViewState is excessively large. What you're seeing is the browser's history cache not storing the values that have been updated on successive callbacks. The above techniques should help.
I have a page with several gridviews. For usability, I have put these gridviews into a series of jquery tabs. Tabs works by creating anchor links that go to containers with certain ids, so after clicking on a given tab, the url might change from
host.com/page.aspx
to
host.com/page.aspx#tab2
The issue is that if any elements inside the tabs cause a postback, like trying to sort or page the grid for example, upon loading, the selected tab is lost, and reverts back to the first tab in the list. So in that case I would have sorted the right grid, but I'd have to click the correct tab again to see it.
To fix the issue, I want to track what anchor I'm at as the postback occurs, so that I can change the url I'm loading to include it. The only way I can think to do it is a Redirect, which I really don't want to incur the cost of.
Is there some better way to specify which anchor to load on postback?
On the forms onsubmit event, modify the action attribute to include the relevant anchor (which you'll need to keep track of yourself)
If the page is posting back to itself then instead of making the post back to foo.aspx you need to make it postback to foo.aspx#anchor.
You could also do this via cookies if you must but anchors is much better. Cookies are more useful for things like customizing the Yahoo page to focus on a particular tab on each visit.