views:

156

answers:

1

hi

i have a page filling a gridview which is all working fine.

the grid is basically the result of a search .. the filters for which are a number of dropdowns and a couple of textboxes the data from the grid and dropdowns are saved in the session and the whole page lives inside an updatepanel

when i navigate away from the page (as it happens by clicking a link inside the grid) and then back button to it, all the droppers are back to their unselected values and the grid is nowhere to be seen..

i understand that this is because of the scriptmanager doesnt do 'standard' postbacks so the browser doesnt realise what has happened.

however i have set the EnableHistory to true in the scriptmanager

is there an easy way to get this to remember without dropping the updatepanel/scriptmanager?

also to complicate things further the scriptmanger /updatepanel is actually in a master page. so not really sure how i can get the navigate bits to work in the scriptmanager.. clearly i am a bit confuised and any help that someone could provide would be happily received

thanks nat

+1  A: 

Setting EnableHistory only tells the ScriptManager to be ready for you to use the server-side support. It is still up to you to tell the ScriptManager how to actually work with it. It doesn't matter that the UpdatePanel is on a MasterPage. Same goes with the ScriptManager. As long as you can get the references you need via a public property / FindControl, you'll be fine. I've done this several times with the ScriptManager in the MasterPage and handling the event

Here is a blog post I wrote about 2 years ago. It is a bit out of date as you don't need the Extensions Preview, but the rest should be relevant enough. When you are in an async postback and binding the gridview, you have to add state to a history point, and let the ScriptManager store it. This is where you would freeze the state of the filters. Then, you also need to have an event handler for the Navigate event. This is where you pull the state out, use it to set controls to what they should be, and bind your grid.

The code samples are in vb.net, but please let me know and I can convert to c#.

rchern
hi thanks very much for the replycould you clarify how to handle the events in the master page.as i have a number of pages using this master page, only one of them needs to save the state in this way. where do i put the Scriptmanager_navigate and addhsitory entry function? does that go in teh master page and then if it can find the particular controls, then save the states for the appropriate ones?thanksnat
nat
The aspx page is the one that knows what state needs to be saved and then on the other side, how to use it, right? Does the master page know what the state means? No. So put it in the aspx. You'd be doing a lot of extra work/coding if you put it in the MasterPage.
rchern
so this.Master.scriptManager1.onnavigate += foo ?in the onload or findcontrol("scriptmanager1").. whatever..thanks for your help, much appreciated
nat
ended up writing a addhistory method called whenever something is done on the form worth saving.. so running the search, paging/sorting the grid. also added this is the aspx page_load (this.Master.FindControl("scriptmanager1") as scriptmanager).Navigate += myscriptnavigatefunction;that function grabs the bits from the NameValueCollection which was added as a history state in the other function, then sets the selected items in the droppers, and rebinds the gridthanks for your pointers
nat