Sign in to follow this  

[web] Asp Net - Asynchronous Web requests

Recommended Posts

I've created a site using DotNetNuke so that I can use C# .Net. This is a general ASP. Net question rather than one specific to DNN. However, If you're fluent with DNN that would be helpful.

So, I've got a page which contains a UserControl. When this page is opened, I am making use of the OnInit() method which is part of UserControl. In this method, I am retrieving data, via an external API, which makes asynchronous web-requests. As a side not, it seems I needed to launch this async call on a new thread, since for some unknown reason, I couldn't use an asynchronous call (which is synchronous under the hood).

I am blocking the flow of the OnInit(), so that I can get the data before the page loads and create UserControls dynamically, based on the returned data. To block the page load, I am using a ManualResetEvent, on which I call Set(), on the new thread I mentioned, once the data has been retrieved.

I'm fairly new to ASP Net web development, and I'm not sure if what I'm doing is the most efficient way.

Would it be better to gather data before even opening the display page? For example, if I had an intermediate page that handles the async download, and then the main page which displays the data, would that be a better method? How could i pass the data on? Is it possible?


Share this post

Link to post
Share on other sites
Let me get this straight. You are rendering a page that has a UserControl that needs data that can be found at a different site. How is the data obtained? Is it through a web service? Is it a normal HTTP request? That's the part I'm having a problem understanding.

Also, what are you trying to accomplish? Does the user submit a request that takes a while to process?

Assuming that you have to do this asynchronously:
Normally in these types of scenarios, what I do is submit the request via the client using an AJAX call to a web service, which starts the process and returns some unique key. This web service behind the scenes can submit the request to some location that another thread or process can pick up and start processing.

Back on the client side, you poll another web service method to check the status of the request every, say, 5 seconds. That method returns true/false to indicate if the data is ready. When it is, your page can then do a postback and on the postback, your page with the UserControl can then pick up the data and do what it needs.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this