delay loading of a silverlight page - c#

How would i go about delaying the total load of a SilverLight Page? I take a parameter out of the querystring on the page load of a Silverlight web page, and then send it to a web service boolean function to process. The result of the return value is used to determine whether to fully load and display the page, or direct to another page. The system works pretty much fine, however when the result from the web service returns, even if it is decided that i need to navigate away to another page, it still displays the initial page for a very short time. How can I stop this brief showing of the initial page?

Take a look at this article: http://www.codeproject.com/KB/webservices/CodeOptimizationTechnique.aspx
The point is that you must not do anything until you receive the data back from the webserice. When you receive it only when you can send the user to the right side, and remember also to consider that maybe you do not get a response from the server sometimes.

Related

ASP.Net C# Web Form: Prevent new server session while previous is processing

I have an ASP.NET 4.5 web form running C# code behind on a server. A specific form often takes some time to finish while it updates and changes various database records. However, if the user closes the tab or tries to reopen the web form, it will try to check the users status in the database and fail when those later change due to the first running process.
The need is to track this specific instance of the process and user, and if it is still running, prevent the page from loading fully or redirect. I was hoping to find and store some user and process information on a cookie and then simply check for this each time on page_load. I was not able to find these variables/properties.
Am I going about this the right way, and if so, how can I accomplish this?
Thanks!
I was not able to find the exact solution I was looking for. At the moment, I cannot see any way to find a server side identification id of the process.
Instead, I referenced How to tell if a page unload in ASP is a PostBack and made it so that the page would warn when being unloaded before the confirmation screen is shown. As long as the form opens to the same named tab, the user would be given the warning screen and given a confirmation before they could close or reload a new web form instance.

Website scraper to the next level

So!
For a fansite I run I also run a website scraper(/xmleader) that reads information from a secure weblocation of a game. It works perfectly as it is now but I want to make it better and mainly faster.
The 1st problem I faced was how to maintain a session where you can do a ton of requests (like 1 to 10 every 30 seconds) while maintaining logged in. Normal httprequest didn't really worked because the login was secured with a token that must be submitted together with my login information. Now the solution was made as followed: On a Form is just placed a webbrowser control and when the login page was loaded(documentCompleted event) I fill the login information inside the document and simply submit it.
Now I can access all the secure pages I want to BUT not with a HttpWebRequest I placed inside the code. BUT When I placed multiple WebBrowserControls on the same form all them could access the secure part of the site. So that is how I placed 6 of them to do -kind of- parallel requests (for xml and html) to access information in my account quickly.
This works like a charm actually, you nicely see 7 browsers browse away and analyse the domdocument but naturally this creates a lot of overhead since I don't need the images and all the flash etc to load (or the iFrames which cause very annoying multiple documentLoaded events). So I want to login once and be able to request inside the code with HttpWebRequest with the session/cookie information of the webbrowser(or login in some other way).
So how do I do this? Is this even possible or should I approach it completely differently ?
(ps I write everything in C#)
You can show the first WebBrowser, login and, after the submit, you get the cookies from it and attach them all over your HttpWebRequests.
Having only the WebBrowser shown for the first login should improve your performance a lot!
Only pay attention to browser validation / async content loading.
You can't use HttpWebRequests to share the same session with WebBrowser. You'd need to use an API based on UrlMon or WinInet, that's what WebBrowser uses behind the scene.
I listed some of the options here: https://stackoverflow.com/a/22686805/1768303.
Perhaps, the XMLHTTPRequest COM object would be the most feasible one.

ASP.NET pages never stop loading

We have a problem with many of our website written C# ASP.NET.
The problem is that often a C# page will never fully load from the server.
The page content itself load fine but Images but more annoying Scripts (Javascript) seam to hang and never come down and depending on the content it might lock up the page on Ajax Postback.
This problem is not limited to a single server as it happens on development machines as well as pre production and production servers.
The development machine are just using the inbuilt VS IIS Instance.
All pages that have this problem use ASP.NET Update Panels with varying versions of AJAX Toolkit.
Thanks
One of the possible reasons is that your postbacks are being triggered on some events which are either being fired continuously. Another possible cause is that the page life cycle is not getting completed (e.g. infinite loop). If you can post some code, you would get precise answers.
Thanks,
Vamyip
Try using asp.net trace to see which page event is taking longer. Also try using fiddler from client side to see the real traffic and error codes. If you share the fiddler logs I may be able to tell more about what's happening.
You can check the time used by all the resourced that are loaded on the page using Firefox and firebug add-on
Anyway the updatepanel doesn't work very well with heavy pages : it posts the whole page to the server and get the whole rendered HTML even if you need refresh a small portion of the page.
if you can you should replace the updatepanel with async Jquery call to the get the the response as JSON and then populate the page as you wish or try to use anothe approach similar to the update panel.
have a look at:
http://www.codeproject.com/KB/aspnet/partialRendering.aspx

Stumped. (C#, JSP)

So long story short, the company I work for, that is all about saving money, went from 1 service application, to 2 service web interfaces.
They're not secure, have no cert's, not even over SSL...yet, they have a timeout associated with each interface. Which then breaks the page you're viewing, and you have to refresh IE, and then proceed to login again, and reset your dropdowns etc...
So.
I've tried using a generic webbrowser interface in C# to have a foundation in which I can refresh the connection to the server with the page open, as to avert the timeout.
But, first attempt results in my app, going to the appropriate page, then opening a new IE window when a service ticket is opened, and there must be a lack of cached data, which results in the new IE window that opens, to revert back to the main page which prompts me to login.
The interfaces are Jsp, but I'm more familiar with c#...
Tried catching link clicks to navigate the destination in the current window, but it seems that the data you double click that prompts the new page to open, is merely a data in a table, and not technically a "link"....
I've brought this to the attention of management, but like most huge corporations, I know nothing, and they never have to deal with it, so as they say in every meeting, "silence means compliance"....
Any thoughts?
Probably not the right answer, but...
Session cookies?
Session cookies = fail..
No 'remember me' option...
I can however enter a link in each browser to "goto the home" section of each app, which each page is already at, so it keeps the connection alive, and doesn't navigate away from the current page (keeping the dropdowns etc that are set after login)
But still, the above problem exists where if I use all this in a C# browser, etc...
I told my boss first thing 'they can't tell me the timeout is for security!' heh
And I still didn't get a positive answer from 'well at 10 seconds per re-logon, per x amount of people = thousands of dollars a year spent on re-logging on...'
:D
Use ajax.
poll a server page in a small interval (a minute)
if it returns "timeouted=true" (or whatever convention you like), refresh the page with javascript.
include the ajax snippet on every page (using <jsp:include>, for example)

JavaScript alerting from a C# class

I have a 5 ASPX page wizard.
Each one contains a SaveAndExit button that executes a C# function on a common static class. After saving, the C# code redirects to another page.
Is there a way for running javascript: alert('Data Saved'); after the saving, and before new page is Loaded.
You'll have to register a startup script on postback to do the alert. Then redirect via javascript after the alert.
You can't do it exactly like you want.
The C# code (server-side) can't run until the page has already posted back and unloaded from the browser. So by the time your server-side code is running the page doesn't even exist any more as far as the browser is concerned and it's too late to run your javascript code. This is true even in the middle of a post back, and even if the result of the post back will be the same page. That is why in certain circumstances ASP.Net pages can appear to flicker during post backs.
So you can't force a javascript alert after the data is saved without doing it via some kind of ajax call back-- and that's certainly one option. Another choice is to have the page to which you redirect show some kind of "data saved" message in certain circumstances; trigger it with something simple like a session variable or the value of hidden input on load so it's not obvious to the user.
But I think probably the best thing to do is nothing at all. It sounds like if the save fails you won't redirect. You'll probably even show some kind of error. If your user doesn't have enough confidence in your app that they don't trust it even when there's no error message and it's moved on to the next step, you're in trouble.
Vik, unless this is a homework I would highly suggest you don't.
JavaScript alert is very annoying to most users and seems completely useless in this case as explained by Joel Coehoorn.
If you insist on showing a message when it is saved then think of adding maybe a session variable and on the redirected page show the "Data saved" message at the top if the session variable exist and then delete the session variable.
Again though, as Joel Coehoorn said, you should definitely show a message if there is an error but redirecting should be all the "proof" they need that their data was saved.

Categories