Preserve paging with the DevExpress MVCxGridView control? - asp.net-mvc

I'm working with the 10.2 version of the DevExpress MVC controls. I have a page hosting a MVCxGridView and I need to preserve the current page when navigating away and back to this particular page.
I can see from the old ASPxGridView documentation that there's a PageIndex property, but this seems to only be accessible from a WebForms/Code Behind/Server Control type context. I'm using MVC and can't figure out how to preserve this page setting.
I've tried the cookie settings with the control but those don't seem to persist for me.
Any pointers would be greatly appreciated.

Currently the MVC grid doesnt support SEOFriendly, or at least I cant find anything on it. You might be able to support it yourself using JQuery and perhaps a paging template which redirects the user to the same page adding a paging parameter like ?paging=2. So basically you check if the url has a paging parameter and if so you can tell the grid to GotoPage(paramValue) telling it in this case to start at page 2.

You could get the gridview's page number in the body unload event and then save that value in a cookie. Next time back at the page, in the gridview's init event read the cookie value and set the grid view's page numbe.

Related

jquery tablesorter issue with page number

I am developing an ASP.NET MVC 4 application using jquery.tablesorter.js, jquery.tablesorter.pager.js and jquery.tablesorter.widget.js. Now I get an issue with this tablesorter, that is, the page number is saved in the local storage.
I understand it is saved for some reasons. The problem is, for example, I last open the 3rd page of the table and leave the session, then re-open a session, it goes to the 3rd page automatically. If, for some reasons, there is not enough items for any item to go to the 3rd page, it simply shows an empty table and pager, and confuses the user.
Any idea is highly appreciated.
Thanks,
A. Zhang
If you don't want the pager to save the page & size, then set the savePages option to false.
If you do want the page to get saved, but you only want to use session storage, then set the storage_useSessionStorage widget option to true.
Please note: the above options only work with my fork of tablesorter.

ASP.NET MVC 4.0 Chrome Caching

I have code in place to disable caching in my MVC application. I'm using the following response headers. They seem to work in all browsers except for Chrome (currently using version 31.0.1650.48). Users are able to submit a form with model values. When they hit the back button I need the page to reload with a blank model. The headers appear to partially work since the request is hitting the action and returning the blank model. However the view isn't updating. The values from the previous post are being retained. I've tried clearing the ModelState but that doesn't work. Any suggestions? Thanks in advance!!
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(False)
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache)
filterContext.HttpContext.Response.Cache.SetNoStore()
Turning off autocomplete for the form fixed this for me. I appreciate all the input!
<form autocomplete="off"></form>
There is a way to do this in javascript for everything in one go like so...
document.getElementById("YourFormID").reset();
Just add an id to your form and all your inputs will reset on page load. Regardless if its a first time visit or a back button click with the page being cached. The biggest difference from your solution and this is that "the autocomplete attribute is new in HTML5". Which means it is not supported in older browsers, and though it does what you want it also prevents the user from autofilling fields. Meaning that for example on text types inputs users will not see a suggestion of words they may have entered on previous or other pages. You can see an example here.

Alternative way of Page.IsPostBack

I am into iPhone, Android and Blackberry web programming. I am struck into an issue in which i either need to stop refresh of page (which according to blogs is not possible) or i need to just refresh the page rather than submitting.
I have used basic HTML controls not ASP.Net server controls, so Page.IsPostBack cannot be used to differentiate between page refresh and a postback.
Alternatives that i have tried:
The root of the issue is that : Having used Request.Form Collection which are read only and are only updated on a postback. So, on a page refresh the Request.Form collection is having previous values and thus submits according to previous request.
I have tried using cookies as found in this link: http://hi.baidu.com/cxyking/blog/item/508872346135283c5ab5f53c.html
It is able to detect a page refresh only after it has already loaded. While my requirement is that i need to detect page refresh before the original page has been unloaded.
I tried to use OnBeforeUnload to display some warning message. But, this only works in desktop browsers and iOS does not seem to do anything on this event.
Is there any idea on how i can do any one of following:
Completely stop page refresh.
Display warning message to user for not leaving the page (OnBeforeUnload not working on iOS)
Somehow, update Request.Form Collection (Note that it has a Set but it is readonly, so it doesnt work)

mvc and the back button

I'm new to mvc so I don't know if there is a trick to this or not. When a user runs a search on a site I'm building and I take them to the results page, if I click the back button the search form is empty. Is there some way to keep the form fields populated as they were when going back (without resorting to session)? Thanks.
Strange.
Fields should be there by default. What browser are you using?
If you're using a regular browser, then maybe your doing something weird, like, resetting the fields via JavaScript or something. Perhaps elaborating more on your current implementation would help diagnosing your problem?
A last solution would be saving the fields as a cookie and loading them via JavaScript on the forms page inside onLoad.

What is a postback?

I'm making my way into web development and have seen the word postback thrown around. Coming from a non-web based background, what does a new web developer have to know about postbacks? (i.e. what are they and when do they arise?)
Any more information you'd like to share to help a newbie in the web world be aware of postbacks would be most greatly appreciated.
The following is aimed at beginners to ASP.Net...
When does it happen?
A postback originates from the client browser. Usually one of the controls on the page will be manipulated by the user (a button clicked or dropdown changed, etc), and this control will initiate a postback. The state of this control, plus all other controls on the page,(known as the View State) is Posted Back to the web server.
What happens?
Most commonly the postback causes the web server to create an instance of the code behind class of the page that initiated the postback. This page object is then executed within the normal page lifecycle with a slight difference (see below). If you do not redirect the user specifically to another page somewhere during the page lifecycle, the final result of the postback will be the same page displayed to the user again, and then another postback could happen, and so on.
Why does it happen?
The web application is running on the web server. In order to process the user’s response, cause the application state to change, or move to a different page, you need to get some code to execute on the web server. The only way to achieve this is to collect up all the information that the user is currently working on and send it all back to the server.
Some things for a beginner to note are...
The state of the controls on the posting back page are available within the context. This will allow you to manipulate the page controls or redirect to another page based on the information there.
Controls on a web form have events, and therefore event handlers, just like any other controls. The initialisation part of the page lifecycle will execute before the event handler of the control that caused the post back. Therefore the code in the page’s Init and Load event handler will execute before the code in the event handler for the button that the user clicked.
The value of the “Page.IsPostBack” property will be set to “true” when the page is executing after a postback, and “false” otherwise.
Technologies like Ajax and MVC have changed the way postbacks work.
From wikipedia:
A Postback is an action taken by an
interactive webpage, when the entire
page and its contents are sent to the
server for processing some information
and then, the server posts the same
page back to the browser.
Expanding on the definitions given, the most important thing you need to know as a web-developer is that NO STATE IS SAVED between postbacks. There are ways to retain state, such as the Session or Viewstate collections in ASP.NET, but as a rule of thumb write your programs where you can recreate your state on every postback.
This is probably the biggest difference between desktop and web-based application programming, and took me months to learn to the point where I was instinctively writing this way.
Postback happens when a webpage posts its data back to the same script/dll/whatever that generated the page in the first place.
Example in C# (asp.net)
...
if (!IsPostback)
// generate form
else
process submitted data;
Web developement generally involves html pages that hold forms (<form> tags). Forms post to URLs. You can set a given form to post to any url you want to. A postback is when a form posts back to it's own page/url.
The term has special significance for ASP.Net WebForms developers, because it is the primary mechanism driving a lot of the behavior for a page — specifically 'event handling'. ASP.Net WebForms pages have exactly one server form which nearly always posts back to itself, and these postbacks trigger execution on the server of something called the Page Lifecycle.
The term is also used in web application development when interacting with 3rd party web-service APIs
Many APIs require both an interactive and non-interactive integration. Typically the interactive part is done using redirects (site 1 redirects a user to site 2, where they sign in, and are redirected back). The non-interactive part is done using a 'postback', or an HTTP POST from site 2's servers to site 1's servers.
When a script generates an html form and that form's action http POSTs back to the same form.
Postback is essentially when a form is submitted to the same page or script (.php .asp etc) as you are currently on to proccesses the data rather than sending you to a new page.
An example could be a page on a forum (viewpage.php), where you submit a comment and it is submitted to the same page (viewpage.php) and you would then see it with the new content added.
See: http://en.wikipedia.org/wiki/Postback
Postback refers to HTML forms. An HTML form has 2 methods: GET and POST. These methods determine how data is sent from the client via the form, to the server. A Postback is the action of POSTing back to the submitting page. In essence, it forms a complete circuit from the client, to the server, and back again.
A post back is anything that cause the page from the client's web browser to be pushed back to the server.
There's alot of info out there, search google for postbacks.
Most of the time, any ASP control will cause a post back (button/link click) but some don't unless you tell them to (checkbox/combobox)
Yet the question is answered accurately above, but just want to share my knowledge .
Postback is basically a property that we can use while doing some tasks that need us to manage the state of the page, that is either we have fired some event for e.g. a button click or if we have refreshed our page.
When our page loads for the very first time , that is if we have refreshed our page, at that time postback-property is false, and after that it becomes true.
if(!ispostback)
{
// do some task here
}
else
{
//do another task here
}
http://happycodng.blogspot.in/2013/09/concept-of-postback-in.html

Resources