Change processing page while loading data is asp.net - asp.net

How do I show a processing page on load of a certain data display page in asp.net?

I still like the classic 2 page solution. The first page has an BODY ONLOAD call that does "window.location = 'Page2.asp';". This results in the first page being displayed and the 2 page being invoked. While the second page is doing it's work the first page remains displayed.
There are a couple of "problems" with this solution:
User clicking refreshing will not take them to the first page (they are on the second page, and clicking refresh will start the second page loading again).
This relies on the second page sending its results all at once (basically "buffered", which is the default).
You could also do this with AJAX (all on one page):
Display a waiting message
Initiate the work with an AJAX load request
Once the load is complete rebuild the page or head of to a "completed" page.
AJAX is nice, except that it may hide any server side errors that occur (i.e. if the page crashes horribly). Also it depends on how you prefer to do ajax (jQuery vs ASP.NET Ajax vs X Y Z).

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.

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 HttpHandler and frequency of hits

I was able to setup some ASP.NET Image controls to render images from a database by using an HttpHandler.
// Notice the ImageHandler.ashx
<asp:Image ID="imgSrvcGrp" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ServiceGroupID", "~/ImageHandler.ashx?id={0}") %>' />
It works great and was surprisingly easy to setup. My question follows...
I noticed that the HttpHandler (ImageHandler.ashx) gets hit at certain times when I don't expect it to. For example, I have a break point at the Page_Load event of the page that contains the Image tags consuming the HttpHandler and another break point in the handler itself, and I found that even though there is no postback (ie - the Page_Load break point is not hit) the handler sometimes gets hit (ie - the break point in the handler is hit).
Oddly, I found this occurs when I close a jQuery dialog on the page. I have a jQuery dialog popup on the page, and I found that when I close the jQuery popup (by clicking on the X) the image handler is hit for every image on the page that consumes it and yet no postback occurs.
The only other detail that I can think to add is my webpage is using Telerik's RadTabStrip, and it is possible that it is somehow having an effect upon this matter.
I realize that my explanation was rather long-winded, so to be more succinct with my question: Why does my image handler get hit so often even though there are no postbacks occurring?
Because loading a page resource and posting a form are different actions.
Don't think of it from an ASP.NET perspective with postbacks and Page_Load handlers and whatnot. Think of it from the perspective of the actual HTML in the browser. A "postback" is nothing more than a form being posted to a page. If you're not doing anything to trigger a form post, the page won't post back.
However, the page is hitting the server when it requests other resources. CSS files, JavaScript files, images, and so on. The resources referenced within the HTML which the page needs to load. So when a page is loaded, it doesn't just hit the server once. It hits the server to get the HTML document (this is where Page_Load for the page gets triggered), and while it renders that HTML it hits the server again and again for every resource referenced in the HTML document.
If the page is hiding/showing resources with dynamic style tweaks, then it shouldn't need to re-load those resources each time it shows them. However, if the page is doing something which causes it to have to re-render the loaded content (and that content isn't cached in the browser), then it will hit the server. This would be what causes that ASHX handler to get hit.
One suggestion for you would be to load up the page with some debugging tools (FireBug in Firefox continues to be my personal choice), and watch the actual traffic coming and going on the page (the "Net" tab in FireBug, possibly something similar in other tools.) This can help you determine exactly what is being requested and possibly what is requesting it. For example, if that RadTabStrip is for whatever reason removing img elements from the page and re-adding them, it'll request the image from the server each time.

Getting Lightbox to Appear over Referring Page

I am working in ASP.NET (framework 2.0) with Master Pages.
I have a page that requires registration and then the user gets kicked back to the referring page.
I need to figure out how to provide a success lightbox that appears over the referring page, not the registration page (the event is fired on form submit).
I have the inline stuff in the master page and the scripts and everything fires just fine but the form is refreshed with the new (referring) page and the DIV gets hidden again.
Is sessions the only way to go here? Is there a way of having one lightbox appearing from the master page regardless of what the sub-pages are doing?
Thanks.
There should be a successful registration event. Can you emit some javascript in that scenario that would cause a redirection to the referring page. You could pass a parameter which would indicate that a light box should show up. I don't think you can redirect directly from successful registration because I am guessing that some cookie would need to be set- which the framework should handle. I might be off, but that is where I would start. I would try and avoid Session if possible.

simultaneous page load and ajax call

I have a web application with some pages take quite a long time to load because of what they have to do in code behind. I would like to show what is going on to the user by showing the different status of the process.
I was thinking about calling recursively (by ajax) a page which ready a value in the session. This value is set by the page that take time to load.
The problem is that the page called by ajax is not executed while the other page load is finished.
Is there some way to do that?
Thanks advance
The usual pattern here is to load an initial status page that triggers an AJAX call to retrieve the final version of the page, overwriting the original with the result of your AJAX call when it completes.
Separate the part of the code that takes a long time and call it asynchronously (e.g. as a WebMethod) on page load, e.g. if using jQuery, on document.ready. You could also fake this using an UpdatePanel which is set to conditional refresh, and the code is never run by default. Then refresh it from script using __doPostBack('updatePanelUniqueID','').

Resources