08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

38<br />

CHAPTER 3 ■ WEB FORMS WITH <strong>ASP</strong>.<strong>NET</strong><br />

<strong>Web</strong> applications are multiuser: When building an application for the <strong>Web</strong>, you have<br />

to remember that your application should be designed to be scaled out to many<br />

users, which in some cases can number in the millions. This leads to two major challenges.<br />

The first is that when the application has to scale out to huge numbers of<br />

users, it will operate in a clustered environment, meaning that it is deployed to a<br />

number of servers, <strong>and</strong> the clustering hardware manages who speaks to which<br />

server. In an environment such as this, you have to make sure that the experience<br />

each user has when using your application is consistent. Thus, a level of commonality<br />

is necessary, <strong>and</strong> this is achieved using shared pools of resources such as data,<br />

styling, <strong>and</strong> connectivity to outside applications. You have to make sure that your<br />

application cooperates with other instances of itself in accessing shared application<br />

resources. Similarly, you have to make sure that the users accessing your application<br />

are doing so concurrently, leading to potential concurrency issues. This means that<br />

you have to be careful in how you write classes that are going to be shared by user<br />

sessions. The framework helps you in this regard, but it doesn’t do everything for you.<br />

Your user classes will need to be carefully crafted <strong>and</strong> deployed.<br />

<strong>Web</strong> applications are designed to execute on a server <strong>and</strong> be viewed in a browser: Your<br />

application is used within users’ browsers on their machines, but the application<br />

actually executes (for the most part) on your server. So, if you think about the simple<br />

case where the user is filling out a form on the browser (like our stock quote application<br />

in Chapter 2), what is happening is that the user sets the state of some of the<br />

controls in the form <strong>and</strong> invokes an HTML form data submission process, which<br />

sends the data to the server. The server executes the application <strong>and</strong> then returns the<br />

results to the client. This process is called a postback. Newer application programming<br />

interfaces (APIs) <strong>and</strong> methodologies such as Ajax move some of the processing<br />

to the client, providing a richer client experience (they make more frequent asynchronous<br />

postbacks to the server to make the application appear more responsive),<br />

but your web applications still have a server element to them, <strong>and</strong> underst<strong>and</strong>ing<br />

how to h<strong>and</strong>le this is vital as you write your web applications.<br />

Typical web applications are stateless: To maintain a clean relationship between the<br />

client <strong>and</strong> the server, particularly to avoid confusion when in a clustered environment,<br />

no state of the condition of a client is stored on the server in a typical web<br />

application. This can be overridden to some degree, but the typical scenario has the<br />

server destroy all instances of web page objects residing in its memory for a particular<br />

page once the page has been sent to the client. This is great for scalability, but it<br />

can hurt the user <strong>and</strong> developer experience—for example, when information should<br />

be persisted throughout a number of sessions <strong>and</strong> a mechanism has to be grown to<br />

achieve this. <strong>ASP</strong>.<strong>NET</strong> assists you in building applications that maintain state<br />

through a process called view state, in which information about the form can be<br />

stored in hidden HTML form fields. You’ll be looking at view state a little later in this

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!