sambit.albus
sambit.albus

Reputation: 250

Want repeater databinding after page load

I am using a web service API to pull json data then convert it to Dataset and show the data into REPEATER inside page load. now my question is that is there a way i can load the page first then it will show a message like loading please wait and then all the processing like pulling the data and showing in the repeater takes place. Is there any event like that in asp.net page lifecycle.

Upvotes: 0

Views: 2522

Answers (2)

Ivan Sivak
Ivan Sivak

Reputation: 7498

I recommend you to change your strategy. Instead of mixing ASP server controls and their events with AJAX use classic AJAX (jQuery) + html/css instead.

Your repeater would be a simple div

<div id="DataWrapper">
  <div id="loadingLabel" style="display:none;">Loading...</div>
  <div id="DataContainer">
  </div>
</div>

You can then use either page web method or ASMX web service (or AJAX-enabled WCF service which I personally prefer):

public static IEnumerable GetMyData(int KeyID)
  {
            DataTable sourceData = GetRepeaterData(KeyID);

            return sourceData.AsEnumerable().Select(row =>
            {
                return new
                {
                    id = row["ID"].ToString(),
                    someName = row["UserName"].ToString(),
                    someSurname = row["userSurname"].ToString()
                };
            });
        }

In JavaScript make a function that will call this service: //but before that call, show the loading.. label

$('#loadingLabel').show();
$.ajax({
                type: 'POST',
                url: '/' + 'GetMyData',
                data: {'KeyID':'8'},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                timeout: 30000,
                success: onSuccess,
                error: onError
            });

..and loop through the result in JavaScript:

function onSuccess(result)
  {
    var src = result.d;

      for (var post in src) {
        /*
         here you can create an JavaScript element and assign a CSS class to it
        */
        $("#DataContainer").append('<div class="myClass">'+ src[post].someName+'</div>');
     }
     // when loading is finished hide the loading.. label
    $('#loadingLabel').hide();
  }

..and CSS:

.myClass
{
  border: 1px single #000000;
  padding: 5px;
}

This is of course only extremely brief answer but I hope it gives you some general idea. This is very lightweight solution and you will find it much more effective than mixing ASPs repeaters and update panels etc.

To get some real numbers about the performance install the Fiddler and compare.

Also, check out this article which is very useful and contains some very helpful advices: http://encosia.com/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/

Upvotes: 2

Grant Thomas
Grant Thomas

Reputation: 45058

There is no event like that in the ASP.NET life-cycle, although you could contrive something with .NET controls (update panels, timers, etc.) but a more reasonable solution could be to simply use AJAX and WebMethods (of which here is an example).

You can generally omit the housing element of a server-side repeater then, too, and just populate native client-side-only HTML elements.

Upvotes: 1

Related Questions