View Single Post
  #2 (permalink)  
Old July 18th, 2009, 11:06 PM
chroniclemaster1 chroniclemaster1 is offline
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts

Originally Posted by carewithl View Post
1) I assume only reason why “SearchByEmail” and “SearchText” attributes need to be stored in ViewState ( and thus persisted across postbacks ) is for cases when administrator deletes a user and we want GridView to display same users (say those whose email name includes letter L ) as it displayed before page issued a posted back due to clicking a delete button?

2) lblTotUsers and lblOnlineUsers display a total number of registered users and a number of users currently online, respectively. The values assigned to these two labels are calculated only on first postback ( value for lblTotUsers is also calculated when user gets deleted ).

But shouldn’t values for lblTotUsers and lblOnlineUsers be calculated on each postback since new users could be created or logged in between the two concurrent postbacks?
I believe both of these cases are for application performance. If I can take #2 first, if you hit the server to check for those values again then... you have to wait for it to do so. Since those values are unlikely to change significantly while you're working on one web page, why bother? How many new people are going to register while you're working on that page, probably none, and while some users may log in or log off, you've still got a decent idea of how many people are online even if it's a couple minutes old. If not, you just hit refresh.

#1, and I'm a little fuzzier on this part but I think....

When you do a search you are hitting a data store, not having the book I'll just guess database and beg forgiveness if I'm wrong. In any case, returning information from any data store is usually one of the slowest operations you can do for a web page. While storing lots of information in the ViewState is not great for application performance either, it beats waiting for a whole new search to be returned by the database (which is especially annoying since you'd be waiting all that time for the EXACT SAME information you just retrieved 60 seconds before).

So you save the results of the search to ViewState. Otherwise the page that's posted back would have no access to that information; you would effectively lose search results everytime you posted back.

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of
A Growing History of our Planet, by our Planet, for our Planet.
The Following User Says Thank You to chroniclemaster1 For This Useful Post:
carewithl (July 20th, 2009)