views:

661

answers:

2

Hi All,

I need to populate 4 GridViews on an aspx page, but I only bind a datatable to one of them on page load. I need to pupulate the other 3 after page load.

does anyone know the best way to do this using ajax ?

Currently I'm using javascript to __doPostBack on a button that pupulates the 3 GridViews but unfortunately this forces a full page load even when using an update panel. I need the page to load, and then populate the GridViews as the datatables are returned.

any suggestions would be much apreciated.

A: 

If I understand the question properly, you want the data to load after the page is in the browser. If this is the case, then you can fire an event with JavaScript when the page loads on the client.

One method I've used is to put a hidden (with CSS, not any property) button on the page and 'clicking' it with javascript. The event of the button click event will need to be wired in the page's code. Also the button would have to be in an update panel that either contains the grids you want to be bound or has the appropriate triggers to cause them to reload.

You might look at JQuery to get manage when this code gets fired. The $(document).ready(function(){ /* Your code here... */ }); method will fire after the entire DOM is available, which is faster than waiting on the entire page to load (images and so forth).

Greg Ogle
+2  A: 

The way you are doing it should work ok, although using jquery to populate a div via the $("#targetDiv").load("contentUrl"); function may be a cleaner way to do it. Anyway, in order to get your current implementation working, there could be a few things you want to look at:

  1. I assume EnablePartialRendering is true on your ScriptManager (always worth checking!).
  2. Make sure the eventTarget for the __dopostback call is set up as an async trigger for your update panels or that it is inside the UpdatePanel if you are only using one UpdatePanel. (See here for details)
  3. Try returning false from the javascript code that executes in the onclick event handler if you have attached this to a button, to make sure the form is not being submitted normally by your browser when you click the button.
Steve Willcock
Thanks so much ! All I had to do was set EnablePartialRendering to true ad it worked.
That's great, glad you got it working :)
Steve Willcock
Awwww It all works fine on my test page, but as soon as I use a master page it goes back to refreshing the the whole page. EnablePartialRendering = true,__dopostback call is an async trigger, and the __doPostBack function returns false.
Ah, are you using a ScriptManager on the master page or on the content page?
Steve Willcock
I've tried it on both with the same result.