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)
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.