getting partial response for one single call - asp.net

I am using dotnet 3.5 and AJAX and i want to get partial responses for my one single call given to server.
Its like I want to retrieve multiple profiles in one call and cannot let the system wait for all the profiles to get loaded.
Meanwhile all the profiles are loading in form of strips on the screen the user should be able to start working with the already loaded profiles.
eg
If I gave call to server and it returns 10 profiles in result then while displaying it one the screen I do not want the user to wait for all 10 profiles get loaded instead, he should be able to start working as soon as 1st profile loads and meanwhile rest 0 profiles loads on the screen.
Is it possible using Javascript, AJAX. IF yes, then how? Kindly help.
Thanks in Advance ^_^
Devshree

This is certainly possible using AJAX.
The way the page would load would be as so:
Page loads instantly with profile display area
Ajax call requests profiles
The server uses multiple HttpResonse.Write() to return profiles which gets rendered on the broswer (as they're received by the browser)
The rendering element could be acheived through an update panel or even some jQuery for more fine-tined control.

Related

Scrape dynamic rendering data with click button

I have a lot of different scrapers, but all of them are working with server rendering pages or parse responses from API endpoints.
But now I have two very specific web sites to scrape:
First.
Single page, we should click on seach button to get first 10 items. To get next 10 items - click button "Next". After 2-3 sec data in search section is rerendered. On click "Next" I get dummy unparsed data from vaadin service. So data can be parsed only from rendered HTML page.
Second.
Same single page with same principles ( click search button to get init data, click Next button to load new data). But additionally I need click on every items to get all data to scrape ( I scrape some data from rendered search result + from modal window after click on each search result item)
Question - is it possible to scrape such websites with scrapy and splash? I know about selenium, but it's quite heavy and slow, I need other solution. Never worked with splash, but if I am not mistaken it's possisble to imitate click via lua script..
I would suggest avoiding Splash and instead reproducing the underlying requests.
The main issue I see here with going the Splash route is that, if there is no URL that you can use to access a page other than the first page from a web browser, and since Splash does not support (AFAIK) resuming a previous rendering, you would need Splash to have each request to Splash run a Lua script that clicks Next, waits and repeats for N pages.
If reproducing the requests is out of the picture for some reason, using an interactive headless browser (Selenium, Puppeteer) instead of a rendering service (Splash) may be better.

ASP.NET 4.0 Ajax Progress Bar Options

I can't believe how many articles I have read and example code I've tried to understand, with no success in accomplishing what I need to do. Hopefully someone can help me out by providing some example code or pointing me to another resource.
I am working in ASP.NET 4.0, C# using VS 2012 Express. The project is a web site. I have a UI page that contains checkbox controls and dropdowns for a user to set preferences. At the bottom of the page is a checkbox for the user to agree to some terms and conditions and an image button they click to get the results based on their preferences. This all works and so does the results page.
The problem is that the results page takes as much as 90 seconds to complete. I can't just leave the user with a "Loading..." on the status bar of their browser. So what I am wanting is:
User clicks to get results
Results page loads immediately
Once results page has loaded, a call is made to server that begins the 90 second process.
User is provided a status display of the progress.
Once process completes, a link is presented for them to view their results.
I see many examples with varied approaches. Most of them require the user to click a button to begin the process. I don't want the user to have to click another button - I just want the process to begin when the results page is finished loading.
Additionally, I'm looking for an idea of how to code the client page to make calls to the server to obtain the status of the process. Preferably a percentage value and a text message for each step of the process. Ie:
25%
Compressing files...
I've seen some Web Method examples, but I don't think I've seen a single one that demonstrates beginning the process initially without having to click a button to invoke it initially. I considered putting the Javascript call in the , but it is contained in a Master.Master that is used by many other pages.
Does anyone know of any code examples that might help me accomplish this sort of thing?
I found a really nice solution from EssentialObjects.com. Their progress bar control is free, although I needed their CallBack custom control to do what I wanted - the CallBack control is not free.
Hope this helps someone else out!

Redirecting to a slow aspx page

I have a performance issue where we have a 2 page setup as part of a workflow in a bigger system. This section is dedicated to rendering reports allowing users to chose their own parameters.
Page1.aspx collects parameter information for a report. It takes the information submitted on a form and validates it. If it validates OK, it stores the selections in the DB as XML, then redirects to Page2.aspx with the run id in the query string. Simple enough, performance is great.
Page2.aspx pulls the ID out of the DB and hydrates a Crystal ReportDocument object (taking milliseconds) then we call ExportToHttpStream which then renders the report as a PDF or DOC or XLS download (output format is determined in Page1.aspx). The performance of the ExportToHttpStream method is very poor due to the way our reports are written and DB indexes on the target system. This is outwith my control at the moment but I am promised that they are being worked on.
So the problem is, that when the submit button in Page1.aspx is pressed, the user experiences a very long delay before the download starts. It is then compounded by the user pressing the submit button again thinking there is a problem.
I think what I need to do is have Page1.aspx redirect to Page2.aspx. Page2.aspx should render the master page furniture and a loading div, and the report should render asynchronously somehow in the background before the save dialogue automatically pops up, after this i'd like to change the loading div to a 'Report generated, click here to go back'.
If this is the best way to achieve this, how can I load a full page, then request the report asynchronously? I'm open to any suggestions here.
You could use ajax to load the report on Page2.aspx and show a loading message while it's processing.
Look at the jQuery.load() method. This might be the easiest way to accomplish what you are trying to do.
Page1.aspx - collect parameters
Page2.aspx - report view, calls Page2Details.aspx via ajax.
Try loading Page2.aspx inside iframe and use jQuery to display waiting indicator and hide it after Page2.aspx download
Whilst both answers gave me some ground to go out and research in the right direction. My solution included using the fileDownload plugin from John Culviner to facilitate a similar solution:
jQuery fileDownload by John Culviner
This allowed me the following page structure:
Page1.aspx, gathers and validates parameters for the report and puts them into Oracle.
Page2.aspx, whilst passed in the runid (pointer to the parameters in the db) via the query string setup 3 hidden divs. Loading, Error and Success.
The script mentioned above was employed at this point. jQuery firstly sets the loading div visible then calls the plugin. The plugin dynamically creates an iframe and downloads the binary (xls/doc/pdf) from Page3.aspx. It then fires a success callback or failure. The success callback is fired by means of a cookie set at the end of the response in Page3.aspx.
I believe the plugin mentioned downloads using a 'text/plain' AJAX call in jQuery avoiding the limitation of there not being an octet-stream equivalent in AJAX.
It works, its not the cleanest solution by any means, it doesn't degrade one bit, but provides the users on our controlled intranet with an extremely responsive and pleasing UI.

ASP.NET How can I disable re-sending of request to server on refresh?

I am developing a page whereby users can login and demo some pieces of functionality. I only want to allow the user to demo this once per day.
A small example:
I have a web page with 3 buttons (relating to 3 different scenarios). On page load, I look up the database and check if the current logged in user has run any one of the 3 scenarios available (via an audit table). Each button is enabled/disabled based on the results. If any buttons are enabled, then they have not run that demo yet. By clicking the relative button, the demo runs a record is written into the Audit Table, and the button is disabled.
This was working ok, however, I realised that when I refresh the page (and confirm I want to re-submit the information) the demo runs again.
How can I stop this from happening? I need to only allow the user to run the demo once!
Thanks.
I would suggest that you change your form submission to use the Post/Redirect/Get pattern to avoid a resubmission if they hit refresh on the demo page.
Also, it seems like you should just be able to change the code at the point where it writes the record into the audit table to check to see if the record already exists, and if so, return a different result. I'd be pretty wary about this approach though. The "refresh" functionality of the browser isn't generally something you should be trying to prevent. What happens if a user hits "refresh" in the middle of their demo?
you can check not only on the page load to enable/disable the buttons, but on the button events, you can verify if that task has already been performed

Please wait dialog & downloading files in asp.net

In my ASP.Net application I have a requirement that when a user clicks on an UI element we generate a PDF for them which they can download. This is currently implemented by doing a form post to an ashx page. This page essentially inspects the form and then executes the correct server side page which either results in HTML or a PDF document of that pages HTML.
On the client I know ahead of time if we are going to be getting a PDF or HTML, when its an HTML I open a new window and direct the form post to that window and all works well. When its a PDF I don't change the target for the form and it remains on the current page.
This works, the user is presented with a save dialog, and the current page is not changed or lost.
The problem I have is that generating the PDF takes anywhere from 1-15 seconds. What I want to do is popup a please wait dialog. Displaying the popup is going to be easy, what I am not sure of is how do I know to close the popup? The popup will be a div in the current page.
The popup can have a client side timer which polls the server for task completion. The long running server task should update the progress in a database table or a server cache object which can be accessed by the polling service.
Couple of old articles from MSDN magazine. You should be able to use the same concepts with newer libraries like asp.net Ajax.
Reporting Task Progress With ASP.NET 2.0
Simplify Task Progress with ASP.NET "Atlas"
just have some javascript on the client side and let it show some animated GIF for 1-15 seconds (your choice) and close itself after the designated time.
Gulzar's suggestion was spot on. I have a simple ajax enabled wcf service which checks a session variable. My ashx page sets the variable to false when it starts processing and then true when its done.
I think there might be a race condition if the client checks before we set the session item to false; however, there are ways around that if we modify the service to set the session item to false after a client gets an im done response.
The tricks is still going to be figuring out what the intervalon the client should be. If we set it to low the user could save the file and then see the still processing message. I'm debating myself between half a second and a second. Anything less then a half a second seems unnessecary.
You said:
When its a PDF I don't change the
target for the form and it remains on
the current page.
If that is the case then the original page will be gone when the PDF is opened. In that situation I would have a loading animated gif and open it using Javascript into a div tag overlaying the rest of the page. You would not need to close it, so no timer or polling needed. It would just be gone when the page is gone.

Resources