There are several options to develop web applications in Microsoft ecosystem such as ASP.Net Web Forms, ASP.Net MVC, Single Page Applications. ASP.Net Web Forms is supported from the initial days of ASP.Net and even today enterprises build many of their web applications using Web Forms. The advantage of web forms is that enables you to build web applications rapidly.
But it hides the underlying technology (HTTP) completely. It simulates the statefulness and events driven programming like Windows Forms development which is not true. Developers can build web applications using ASP.Net Web Forms without knowing much about ‘How it works?’ and unfortunately most of the newbie ASP.Net developers build applications by this way.
In this article, I’d cover 3 basic things that every ASP.Net developer should know, especially when using ASP.Net Web Forms
- Statelessness nature of HTTP and Request-Response pattern
- Difference between client side and server side
1. Statelessness nature of HTTP and Request-Response pattern:
All web applications built using ASP.Net (or java or ‘Ruby on Rails’ or any new shiny technology) use HTTP protocol or its secured version HTTPS. You can think of HTTPS as using HHTP securely. HTTPS uses Secure Socket Layer (SSL) and encrypts your data. But, HTTPS still use HTTP.
HTTP is a stateless protocol which follows a request /response pattern i.e, user requests a resource (could be web page, text file, small piece of info etc.) and the web server responds with the requested resource.
The web server does not maintain any state of the previous requests. If the user requests the same resource again, the web server again responds with the requested resource as though the user is asking the document for the first time. There are various mechanisms to maintain the state in web application. ViewState is one such mechanism where all the form data is encoded in a hidden field and sent to the client and thus state can be maintained between requests. There are several other mechanisms available to maintain the state which would be discussed at the appropriate time on need basis in this article. As of now, you just need to keep in mind that even though HTTP is inherently stateless, there are several options to maintain the state.
HTML would provide you the layout of the web page – which content should be at what place
CSS(Cascading style sheet) would help you in applying styles to elements of the page. E.g, If you want all paragraph text to be italic and in blue color, CSS would help you to achieve it easily without much modification to the code. I am including inline styles as well in this category for clarity.
When the user access the ASP.Net web page, following are the sequence of events happen at a very high level
- User access the web page (for e.g, example.com/webpage.aspx)
- The request goes to the server where the web application is hosted. The web server forwards the request to ASP.Net as the requested resource is of aspx page. If the requested resource had been a static resource such as image, text file or static html file – the web server itself would have responded by replying with the requested resource.
- Net converts ASP.Net code to HTML,CSS and JS
- The converted document (containing HTML,CSS,JS) is sent back to the user and the user would consume the web page through browser.
Please note that there are lot of things would be happening between receiving a request and sending the response. The above discussion and the below picture is for high level understanding only.
3. Difference between client side and server side
Below picture shows HTML elements of few of the frequently used ASP.Net server controls
Thanks for reading this article. You can sign up to my mailing list below so that I can send useful articles straight to your inbox.