I was looking at Peter Bromberg’s post “Build a dynamic progress page” which is about creating a “Loading” page for time-taking asp.net webpages. The problem with Peter’s solution is if your destination page has more than one query string params, then it wont work. Another small problem is non-standard DOM access which wont work in non-IE browsers (it was written almost five years back so it might not a big concern at that time)

Here is the modified code to make it work with query string AND non-IE browsers.

The basic idea is having a transient ‘Loading’ page which loads the time-taking page in the background and in meantime show a nice animated progress bar. Lets name our middle page ‘loading.aspx’

loading.aspx

Header section has javascript code to show, hide progress bar while loading the destination page

    capture1

Body has nothing but visual element for progress bar. Note that we are calling Begin() on body load and End() on unload.

 

capture2 

loading.aspx.cs

In the code-behind, destinal URL is generated.

 

capture31 

Finally, to use this page to call a time-consuming page (say  longloadingpage.aspx) which takes ID1 and ID2 as query params  simply call

/loading.aspx?destPage=longloadingpage.aspx?ID1=123&ID2=345

Advertisements

One of my co-workers asked me if I know on top of my head to remove additional white spaces in a sentence using C#.   We all know that Trim() removes white spaces at front and end…. and “Replace” can be used to remove all white spaces in string   BUT  he dont want to remove all spaces …he just wants to remove extra spaces if any….

Input :  This is              a test sentence   with    some                 spaces
Desired Output :   This is a test sentence with some spaces

Using RegEx here is the way, if you need it…. 

System.Text.RegularExpressions.Regex.Replace(input, @”\s+”, ” “);

Remember that this removes all whitespace characters including tabs, newlines  etc…  which is he wants anyway!