Connecting Tech Pros Worldwide Help | Site Map

ASP.NET Ajax with GridView

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 4th, 2008, 06:10 PM
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Age: 33
Posts: 757
Default ASP.NET Ajax with GridView

<Edit> This thread has been split off of this thread</edit>


Quote:
Originally Posted by Frinavale View Post
I used this technique in one of my web applications as well.

Did you try the UpdatePanel?

I'd be interested in knowing if that works....
In theory, it should work relatively well... the downside is that if you've got a grid that you want to autopostback every single cell, then you've got unnecessary overhead of all the UpdatePanel instances... and if you use only a single UpdatePanel to wrap the whole grid, it doesn't fix the need to click twice on the cell you wish to select...

That won't work in the case of the OP who needs it to refresh data on the page - however, if it's just one textbox, then having the UpdatePanel around the list that needs updating and pointing the trigger to the textbox should work nicely.

Last edited by Frinavale; December 4th, 2008 at 09:25 PM. Reason: added link to old thread
Reply
  #2  
Old December 4th, 2008, 06:32 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

Quote:
Originally Posted by balabaster View Post
In theory, it should work relatively well... the downside is that if you've got a grid that you want to autopostback every single cell, then you've got unnecessary overhead of all the UpdatePanel instances... and if you use only a single UpdatePanel to wrap the whole grid, it doesn't fix the need to click twice on the cell you wish to select...
I see your point...

In the GridView case I wouldn't consider using UpdatePanels for all of my cells...because, like you've said there would be a lot of overhead. I would look into writing my own Ajax to handle this. Even though UpdatePanels are convenient to quickly add Ajax capabilities to web apps., they are not always the best way to solve the problem.

Aside from that, you have to post back to the server regardless of whether it's to update a single element or the majority of the web page.

Even though asynchronous calls update a portion of the web page when the request returns, the ASP cycle remains the same... So the same amount of sever-side processing will need to be done regardless of whether you only want to update a single element or the whole web page.

Correct me if I'm wrong here, but I'm pretty sure it's the same overhead for full page updates as it is for partial page updates.
Reply
  #3  
Old December 4th, 2008, 06:40 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

For the GridView...have you considered creating a custom object that implements both the ITemplate Interface and IScriptControl Interface....where your scripts make Ajax calls to the server to update that row?
Reply
  #4  
Old December 4th, 2008, 06:42 PM
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Age: 33
Posts: 757
Default

Quote:
Originally Posted by Frinavale View Post
Correct me if I'm wrong here, but I'm pretty sure it's the same overhead for full page updates as it is for partial page updates.
You're entirely correct. The UpdatePanel posts the whole page via an asynchronous javascript call, and the entire page life cycle is processed. The page is then rendered and sent back to the client where the javascript's callback pulls the html/script that is contained within the <ContentTemplate> tags of the received XML and replaces the data displayed on screen with it.

So as far as the server is concerned, if the postback occurs from an UpdatePanel or is an entire page postback, it's the same. It's just that the javascript handles it differently on the client side.

If you write your own javascript that contains an AJAX call however, you could have it call to a webmethod that just processes received data which could be as much or as little as needs to be posted to the server. It processes that data and passes back just the data that the AJAX call requests at which point, the javascript callback can do whatever you want. In this case, find the object in the document and replace its value, rather than replacing a whole block of html.

This way is much more efficient in terms of network and processing, but is a lot more intensive for the programmer...

Of course, wrapping every object with an UpdatePanel adds to the amount of processing the server needs to do in every case. It still needs to convert the XHTML to HTML and handle the viewstate etc etc etc...
Reply
  #5  
Old December 4th, 2008, 06:43 PM
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Age: 33
Posts: 757
Default

Quote:
Originally Posted by Frinavale View Post
For the GridView...have you considered creating a custom object that implements both the ITemplate Interface and IScriptControl Interface....where your scripts make Ajax calls to the server to update that row?
We should move these posts to another thread instead of hijacking this one...
Reply
  #6  
Old December 4th, 2008, 06:46 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

I was thinking the exact same thing.
Do you have an existing thread on this topic?
Reply
  #7  
Old December 4th, 2008, 07:46 PM
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Age: 33
Posts: 757
Default

Quote:
Originally Posted by Frinavale View Post
Do you have an existing thread on this topic?
Not yet, but I may do when I get as far as trying to fix this bug. I have more pressing issues to solve (and by pressing I mean interesting :))
Reply
  #8  
Old June 17th, 2009, 02:54 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

I've been trying a whole bunch of new (new for me at least) web technologies/techniques lately and this thread came to mind.

Apparently calling web services using JavaScript is a lot easier now :) You can create web methods that return JSON Objects and this simplifies things quite a bit in the JavaScript side of things. To get your web methods to return JSON Objects All you have to do is indicate that you want to use the Script.Services.ScriptService()

I've been starting to get away from the ASP.NET controls (like GridViews) lately and have found that it's making for a much lighter web application.

If you have time I'd recommend exploring this. Also, you should check out ASP.NET MVC (because it's absolutely awesome too!)
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.