views:

194

answers:

3

When you are creating a Search for your Website, you Want the user experience to be as good as anytime and when you are browsing your gridview you want to be able to press the Back Button to go back to the previous viewed page.

In asp.net with asp.net ajax it's possible when using the ScriptManager + Ajax Control Toolkit where there is a History Manager.

Now, when you are using ASP.NET MVC, you Don't have the possibility to use the ScriptManager because it needs to be nested in a server-runned form.

This sample code is used for a Basic search

<% using(Ajax.BeginForm("TestSearch", 
       new AjaxOptions { UpdateTargetId = "details" })) { %>


    <%= Html.TextBox("search") %>

    <input type="submit" value="search" />

<% } %>

When you press the Submit-button on a standard page, you will be posted to a different page, however, in this case, you Wont. So there is no History saved because the whole Web Page was not reloaded.

That's just the first problem.

Problem #2

Since the history is not saved, as proven above, the Search history of a textbox is not updated. A textbox history entry is only added when the page is fully postbacked, how do you solve that with asp.net mvc + ajax?

+1  A: 

You can still use HistoryManager, but jquery has some more options.

http://stackoverflow.com/questions/1941278/which-javascript-history-back-implementation-is-the-best

Malcolm Frexner
Does that also address the second problem?
Filip Ekberg
I dont see how problem 1 and 2 are different. The problem you have seems to be that if you use ajax you will have no history entry in the browser. This problem can be solved with either ASP.NET Ajax or some jquery plugin. In both you need to add history points in JS. Have a look at the video in the link. It explains the solution pretty well.
Malcolm Frexner
Anyway here is the code if you want to use ASP.NET Ajax http://dotnetslackers.com/articles/ajax/ClientHistoryPointsInASPNET35Extensions.aspx
Malcolm Frexner
You cannot use the ScriptManager with ASP.NET MVC.
Filip Ekberg
You are right, but the ASP.NET Ajax scripts are available anyway. It doesnt change to much. This link is better for MVC http://www.asp.net/%28S%28pdfrohu0ajmwt445fanvj2r3%29%29/learn/mvc/tutorial-32-cs.aspx
Malcolm Frexner
A: 

Did you check out the MVC ScriptManager?

I know of it, but I know nothing about it ...

Martin
Well even if i Do have a script manager, i still cant access it from "code-behind" / the action. :)
Filip Ekberg
A: 

Hey,

The in-built history is available within the MS AJAX scripts in the project; you should be able to make use of it on the client side only.

Brian
Do you have an example?
Filip Ekberg
I don't know that there are many examples in MVC, but in web forms you would do it this way: http://dotnetslackers.com/articles/ajax/ClientHistoryPointsInASPNET35Extensions.aspx
Brian
The thing you may run into issue with is that the scriptmanager enabled history; there is a Sys.Application.set_enableHistory(val) method for enabling history, but it has to be before the page is initialized... don't know if that will give you any issues...
Brian