0

I'm using ajax in my website to call some information from a UserControl called NewsFeed.ascx which is found in the folder 'controls', my way is to make a web service page (in a folder called WebMethods) which contain a function in my case called GetRSSReader which returns a string format:

    [WebMethod]
public string GetRSSReader()
{
    Page page = new Page();
    UserControl ctl =
      (UserControl)page.LoadControl("~/Controls/NewsFeed.ascx");

    page.Controls.Add(ctl);

    StringWriter writer = new StringWriter();
    HttpContext.Current.Server.Execute(page, writer, false);

    return writer.ToString();
}

then I call this page using Jquery (which I found it too heavy) to get the returned data as a JSON like this :

<div id="Content"></div>
<script type="text/javascript" defer="defer" src="../JAVA/Default.js"></script>

>

$(document).ready(Update);

function Requests()
{
  $.ajax({
    type: "POST",
    url: "../WebMethods/Feed.asmx/GetRSSReader",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      $('#Content').html(msg.d);
    }
  });
}

the Jquery.js and this page (default.js) founded in the folder Java


my question : is there anything better than this way . besides that when I have a huge amount of data it doesn't work , and it doesn't read the grid view tool . ANY Suggestions !? 10x


Form another side is there any alternatives for web-service !? (faster)

3 Answers 3

1

While there are certainly lower-level ways to accomplish what you are doing that would reduce some overhead, it sounds like your problem is a "huge amount of data," not the overhead of a WebService.

Are you returning the entire contents of a news feed? Wouldn't you rather just return what's changed? Some logic would seem to be the answer...

Also, there's no real reason to use a webservice to do this. Just put the UserControl in a regular page (aspx) and call it with a GET query. You could also use a generic web handler (ashx) instead of a WebService which has lower overhead. But again it doesn't sound like that's really the issue here. Either way you don't need to bother with JSON. You're getting HTML, just get it, and use it directly.

Also, instead of returning fully rendered HTML (without knowing what your UserControl does, it's hard to know how to optimize this), just return the data, and use jQuery or something to produce the output. If you don't want to build your template in jQuery, then you could render a default/empty template on the server, and use this on the client to build out with the data.

This would be some work, of course, but if the amount of data is a bottleneck, it would help.

Sign up to request clarification or add additional context in comments.

2 Comments

can I understand that my way is light enough !!
Not sure what you mean... the bottom line is, where is your bottleneck? If you're just testing with a single user and it's too slow, clearly, the amount of data is the problem. You would never, ever notice the overhead of a WebService unless you had a lot of server load.
0

In general, WCF is newer, faster and better than web services.

However in your case I highly doubt you need either of those.. if I understand your requirements you can use UpdatePanel for this.. wrap the control with UpdatePanel and trigger it with client side script instead of invoking your own AJAX request.

The UpdatePanel is using its own AJAX mechanism behind the scenes and I guess it's as optimized as possible already.

1 Comment

the only problem with using the UpdatePanel is the performance. the request contains everything a conventional ASP.NET postback contains, including view state
0

You can use ASP.NET Callback API, which is very very light-weight and you can send JSON too.

Anyway, why you say your way isn't efficient? Are you sending a lot of data through this web service?

Maybe you need paging.

2 Comments

I didn't say it's not efficient but it doesn't support the GridView Tool !!! and what about thje ASP.NET Callback API !!
Where are you talking about grid views?? And I don't understand your exclamations with Callback API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.