This is a migrated thread and some comments may be shown as answers.

Clearing grid data in Ajax postback

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TonyG
Top achievements
Rank 1
TonyG asked on 10 Aug 2012, 11:52 PM
I have the following structure:
- Main page
-- user control
--- tabstrip
---- tab (pageview)
----- user control
------ grid

The user was concerned that as they moved around the app that the grid would maintain its data. I do build a datasource and save it to state, and then on postback refresh from state in order to respond to the current request.
But if the user clicks on the tabstrip, I clear all state data, then use Response.Redirect to go back to the Main page. This forces Page_Init and all other load and render events which regenerate the grid.

What's weird is that the structure of the grid resets but not the data. I'm clearing filters, resetting sorting, resetting grouping, and yes, the DataSource is null. I am not rebinding in this event, because the grid data source is already null. If I do rebind, the larger cycle is re-initiated, so I'd rather avoid that. I can set a flag that detects a reset and initate the rebind from Page_Init or Page_Load.

I'm just wondering why the grid structure is refreshed but not the data. Do I need to set the RadAjaxManager to trigger/update some component other than the grid?

And if a change to the AjaxManager is required, what would that be given the above structure? Aside from making the nested components aware of parent components through properties, I'm not aware of how I would set the AjaxManager to update based on an event outside of the local scope.

I understand the request could be vague with no further info, and will do what I can to provide relevant info on request.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 15 Aug 2012, 11:57 AM
Hi,

By default RadGrid loads it data from the ViewState when the EnableViewState property is set to true(default) on postbacks. New data is fetched only when filter/sort/group/expand operations are performed.

If you want to force RadGrid to fetch the data again on every postback you should set the DataSource property of RadGrid to null and then call Rebind method. Thus you will force RadGrid to fire the NeedDataSource event once again and fetch the data again.

Give these suggestions a try and check whether do you get the expected behavior.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
TonyG
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or