New to Ajax? Read this...

Recently, I've run across several posts over at the AJAX.NET Google Group asking about how you can bind a DataGrid, or a Repeater using AJAX. 

The answer is, you can't.

DataGrids and Repeaters are Server Side controls.  Their life begins and ends on the server, when the page is rendered to the client.  The client is rendered to HTML, and sent to the client.  That's it.  Finito.  The End.  That's all she wrote.  From there on out, it's all the client. 

Any AJAX transactions that take place must be rendered on the client using JavaScript.  It's that simple.  Server Controls are for the server.  Asynchronous JAVASCRIPT and XML.  No mention of server controls in the name.  So, if you bring back a collection of Data from the server, you need to parse through that data with JavaScript, and create your HTML manually.  No way around it.  (Well, there is, but it can severely limit functionality).

The other issue is Page Context.  You don't get one when you're doing an AJAX call on the server.  It's an HTTP Request.  No page context.  With the AJAX.NET library, you get the session and cookies, etc, but the page doesn't exist.  No way around that.  Even if you could get the page context, it's only valid when the script is running on the server.  You can't re-bind data to an existing datagrid. 

So, Server Controls are for the Server.  Any work done with AJAX is Client Side. 

Print | posted on Saturday, March 11, 2006 1:25 AM

Feedback

# re: New to Ajax? Read this...

left by scottgu at 3/11/2006 9:03 PM Gravatar
Actually, the new Atlas server controls allow you to use the standard ASP.NET controls in an ajax way. Just wrap a <atlas:updatepanel> around a datagrid and you are good to go.

Here is a good post to read to learn more: http://weblogs.asp.net/scottgu/archive/2005/12/26/433997.aspx

Hope this helps,

Scott

# re: New to Ajax? Read this...

left by Peter Bromberg at 3/12/2006 12:04 PM Gravatar
In addition to the Atlas infrastructure, the Anthem.Net library does preserve the stateful page context like Atlas and unlike AJAX.NET library which relies on external handlers to make the remote scripting call.
You can find Anthem.NET on Sourceforge; its available for both ASP.NET 1.1 and 2.0
Peter

# re: New to Ajax? Read this...

left by Brian Foote at 3/16/2006 5:52 AM Gravatar
I'm able to do this using client callbacks. I render my DataGrid into a string with a callback function which is returned to javascript which replaces the inner html of a control (such as a td tag).

# re: New to Ajax? Read this...

left by kyle at 3/16/2006 7:56 AM Gravatar
Right.

See my post here http://groups.google.com/group/ajaxpro/browse_thread/thread/f372525e4925c9cd.

However, this has some major drawbacks such as very limited functionality, particularly in the JavaScript etc...
Title  
Name
Email (never displayed)
Url
Comments   
Please add 6 and 3 and type the answer here: