ASP.NET/DataList: client side postback by pushing list items

I have a DataList control that displays a set of items. Can anyone point me in the right direction how I can add some client-side functionality to send / perform a postback when the user clicks on an item in the list (e.g. somewhere at the root of a list item. Saw some examples adding a hidden LinkButton and plugging it in - but it didn't work out for me.

amuses,

- larsw


Thanks for the help. I went for the jQuery method. Do you know if I can call the hidden asp: LinkButton from the lambda function (for the selected item) to have a post response take place?

There was a small typo in your example code (in case anyone is reading this thread): I had to add # to the jQuery selector; ' # <% = DataList1.ClientID%> td'

- larsw

+1


source to share


1 answer


There is not such a thing as "client side feedback", it is sheets. Callback implies sending to the server (or external server).

What you are really looking for is to add some AJAX methods to your page. This can be done in several ways:

  • UpdatePanel
  • Pure MS AJAX
  • A mixture of MS AJAX and jQuery (or another JavaScript library, I suggest jQuery because of its support in VS 2008)

UpdatePanel method

This is not the best idea if you have a very heavy page. Take a look at the blog post I wrote if you want more information on what to look for - http://www.aaron-powell.com/blog.aspx?id=1195 .

Simply put, UpdatePanels can be a dangerous choice if you don't understand what the limitations are.



MS AJAX and / or jQuery

This is my recommendation on what you should do. Use jQuery to find all the elements in the DOM that you want to place client events on, for example:

$('#<%= DataList1.ClientID %> span').click(function () { alert('You want something here'); });

      

David Ward has some good posts on using jQuery with ASP.NET/ASP.NET AJAX - http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/ and http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Note. ... If you are going to use an AJAX implementation, you will not have access to the page control collection, this will all be static method interactions, so keep in mind that if you want to update multiple sections on the page, you will need to write JavaScript methods to do this.

+5


source







All Articles