Custom http handler and AJAX

Custom http handler and AJAX

Old forum URL: forums.lhotka.net/forums/t/2528.aspx


somayajulu posted on Thursday, March 15, 2007

Hi,

I have a web application that uses a custom http handler. I have a gridview which displays data using custom paging and sorting. In grid view's pageindexchanging and sorting events, I'm redirecting the page to the custom http handler and the required paging and sorting would be done.

Now I want to provide paging and sorting with AJAX fuctionality without bypassing the custom http handler. How can I achieve this? Does ASP.Net AJAX update panel help?

Any help regarding this is appeciated.

Bayu replied on Thursday, March 15, 2007

Hi there,

Currently I am very much into AJAX as well. First I worked with the ASP.Net AJAX kit (http://ajax.asp.net), but I felt a bit too detached from the core using it. So I switched to an approach that is based on jQuery (http://jquery.com). It forced me to dive much deeper into the nasty details, but subsequently I felt much more in control.

But that's just me. ;-)

Maybe you should have a look at: http://ajax.asp.net/ajaxtoolkit/PagingBulletedList/PagingBulletedList.aspx

It is for a bulleted-list, but maybe you can redesign it to make it work for your case.


Regards,
Bayu

somayajulu replied on Thursday, March 15, 2007

Thanks Bayu,

That's a good one. However in my case, I'm considering to use the Grid itself. Is there a way to acheive the AJAX functionality with the Grid without bypassing custom http handler?

Regards,

Som.

Bayu replied on Thursday, March 15, 2007

Allright,

Which 'Grid' do you mean?
The standard Asp.Net GridView? Let's assume this is what you mean.

I had a look, what I noticed is the following:
- the GridView throws a cancellable PageIndexChanging event
- you can set the Cancel property on the EventArgs to true to prevent default paging to occur
- instead you can call your HttpHandler asynchronously (i.e. through AJAX)
- when this call returns you can set the datasource of your Grid to the newly recieved data

This might work, but I guess there will be one (potentially showstopping) problem here: the Grid might not allow you to show page numbers without having the actual data..... (ouch). I don't know if you can force page indices to appear, but it could very well be that these can only be derived from data that is actually present. You could try if subclassing gives you some more control here then is available through the properties, but I'm afraid you will get stuck here. Of course this breaks your idea of one-page-at-a-time fetching.

A possible solution:
- don't use the page indices that are provided by the GridView
- it's straightforward to create some page-index buttons of your own programmatically and show these beneath the GridView as if they are part of it
- then you can use the AJAX thingie as I described earlier and set the datasource of your GridView as is appropriate


As you notice the solution is to kind of 'work around' the standard asp control. Also the ASP.Net Ajax toolkit does not (yet) provide a ajax-enabled gridcontrol. This is one of the primary reasons why I discarded the whole asp.net-ajax thing and went for an open-source alternative.


A possible (yet perhaps too costly) alternative would be to buy a 3rd party control like those delivered by Infragistics. These are (supposed to be) fully Ajax-enabled.


Hope this helps.

Regards,
Bayu

somayajulu replied on Thursday, March 15, 2007

Hi Bayu,

Nice ideas. I would like to bring to your notice a couple of things:
a. I'm not using the default paging of the GridView.
b. I have implemented Custom Paging with the help of CslaDataSource control. I'm using CSLA.Net version 2.1.3

AJAX functionality is working fine with the GridView if I use the update panel. However, at present I'm able to do so bypassing the custom HttpHandler.

The problem is with calling the custom HttpHander asynchronously. At present, I'm using a Response.Redirect to call the custom HttpHandler. This will result in a page redirection.

Is there a workaround to this so that I call the custom HttpHandler asynchronously whenever any event is triggered?

Can this be done like the following:
a. Use the ASP.Net AJAX update panel and add the GridView in the ContentTemplate.
b. Add paging and sorting events of the GridView to the triggers list of update panel
c. Send a request through HttpWebRequest and get the response using HttpWebResponse in those events.
d. Bind the data to the CslaDataSource after getting the response back

Please let me know if I'm wrong.

Regards,
Som.

Bayu replied on Thursday, March 15, 2007

somayajulu:

Nice ideas. I would like to bring to your notice a couple of things:
a. I'm not using the default paging of the GridView.
b. I have implemented Custom Paging with the help of CslaDataSource control. I'm using CSLA.Net version 2.1.3

AJAX functionality is working fine with the GridView if I use the update panel. However, at present I'm able to do so bypassing the custom HttpHandler.


Ah, good that you have it working already!
I didn't understand that from your earlier posts. So I guess my previous post is a bit off-track. ;-)

somayajulu:

The problem is with calling the custom HttpHander asynchronously. At present, I'm using a Response.Redirect to call the custom HttpHandler. This will result in a page redirection.

Is there a workaround to this so that I call the custom HttpHandler asynchronously whenever any event is triggered?

Right, so that's the problem.

By making use of the UpdatePanel you saved yourself a whole bunch of work you would have to do otherwise, as you simply plugged-in a full block of off-the-shelf AJAX logic. All this is fine, but now that you want to modify some part of the behavior you get stuck because as far as I know there is no clean way to get behind the scenes of this UpdatePanel. This again relates to my uneasiness with this stuff from MS as I prefer to get into all the nasty details, especially with this kind of cutting-edge technology that is so sensitive to the used browser and platform.

Anyways, I am a afraid I can't offer you a solution here.This UpdatePanel is one huge black-boxed piece of AJAX logic that implements the befamed 'adaptive rendering logic', and I don't know of a straightforward way to hook into this without causing more pain than providing cure.

somayajulu:

Can this be done like the following:
a. Use the ASP.Net AJAX update panel and add the GridView in the ContentTemplate.
b. Add paging and sorting events of the GridView to the triggers list of update panel
c. Send a request through HttpWebRequest and get the response using HttpWebResponse in those events.
d. Bind the data to the CslaDataSource after getting the response back



Trial and error is the way to go I am afraid. I have don't sufficient experience with the UpdatePanel to predict how it will work. I don't know what your handler does, but another way to get some logic between your data and UI is by using an Object DataSource. If that is of any use depends on your scenario.

In my app I display lots of data in grids and most of this data is loaded dynamically and asynchronously from a HttpHandler. But as I said before, I don't use ASP.Net on the client-side, it's all built on top of jQuery (which btw is very easy to learn).

Maybe someone can be of more help?

Regards,
Bayu

Copyright (c) Marimer LLC