ArticleslgStudy

computer science

ASP.NET Web Forms

ASP.NET Web Forms is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand ASP.NET Web Forms rather than just read about it. In short: ASP.NET Web Forms is a web application framework and one of several programming models supported by the Microsoft ASP.NET technology. Web Forms applications can be written in any programming language which supports the Common Language Runtime, such as C# or Visual Basic.

Key takeaways

  • ASP.NET Web Forms belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect ASP.NET Web Forms to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of ASP.NET Web Forms from memory before moving on to harder problems.

Reference excerpt

ASP.NET Web Forms is a web application framework and one of several programming models supported by the Microsoft ASP.NET technology. Web Forms applications can be written in any programming language which supports the Common Language Runtime, such as C# or Visual Basic. The main building blocks of Web Forms pages are server controls, which are reusable components responsible for rendering HTML markup and responding to events. A technique called view state is used to persist the state of server controls between normally stateless HTTP requests. Web Forms was included in the original .NET Framework 1.0 release in 2002 (see .NET Framework version history and ASP.NET version history), as the first programming model available in ASP.NET. Unlike newer ASP.NET components, Web Forms is not supported by ASP.NET Core.

Characteristics ASP.NET web pages, known officially as Web Forms, were the main building blocks for application development in ASP.NET before the introduction of MVC. There are two basic methodologies for Web Forms: a web application format and a web site format. Web applications need to be compiled before deployment, while web sites allow the user to copy the files directly to the server without prior compilation. Web forms are contained in files with a ".aspx" extension; these files typically contain static (X)HTML markup or component markup. The component markup can include server-side Web Controls and User Controls that have been defined in the framework or the web page. For example, a textbox component can be defined on a page as <asp:textbox id="myid" runat="server">, which is rendered into an html input box. Additionally, dynamic code, which runs on the server, can be placed in a page within a block <% -- dynamic code -- %>, which is similar to other Web development technologies such as PHP, JSP, and ASP. With ASP.NET Framework 2.0, Microsoft introduced a new code-behind model that lets static text remain on the .aspx page while dynamic code goes into an .aspx.vb or .aspx.cs or .aspx.fs file (depending on the programming language used).

Code-behind model Microsoft recommends dealing with dynamic program code by using the code-behind model, which places this code in a separate file or in a specially designated script tag. Code-behind files typically have names like "MyPage.aspx.cs" or "MyPage.aspx.vb" while the page file is MyPage.aspx (same filename as the page file (ASPX), but with the final extension denoting the page language). This practice is automatic in Visual Studio and other IDEs, though the user can change the code-behind page name. Also, in the web application format, the pagename.aspx.cs is a partial class that is linked to the pagename.designer.cs file. The designer file is a file that is autogenerated from the ASPX page and allows the programmer to reference components in the ASPX page from the code-behind page without having to declare them manually, as was necessary in ASP.NET versions before version 2. When using this style of programming, the developer writes code to respond to different events, such as the page being loaded, or a control being clicked, rather than a procedural walkthrough of the document. ASP.NET's code-behind model marks a departure from Classic ASP in that it encourages developers to build applications with separation of presentation and content in mind. In theory, this would allow a Web designer, for example, to focus on the design markup with less potential for disturbing the programming code that drives it. This is similar to the separation of the controller from the view in model–view–controller (MVC) frameworks.

Directives A directive is a special instruction on how ASP.NET should process the page. The most common directive is <%@ Page %>, which can specify many attributes used by the ASP.NET page parser and compiler.

User controls User controls are encapsulations of sections of page sections that are registered and used as controls in ASP.NET.

Custom controls Programmers can also build custom controls for ASP.NET applications. Unlike user controls, these controls do not have an ASCX markup file, having all their code compiled into a dynamic link library (DLL) file. Such custom controls can be used across multiple Web applications and Visual Studio 2013 projects.

Rendering technique .NET uses a "visited composites" rendering technique. During compilation, the template (.aspx) file is compiled into initialization code that builds a control tree (the composite) representing the original template. Literal text goes into instances of the Literal control class, and server controls are represented by instances of a specific control class. The initialization code is combined with user-written code (usually by the assembly of multiple partial classes) and results in a class specific for the page. The page doubles as the root of the control tree. Actual requests for the page are processed through a number of steps. First, during the initialization steps, an instance of the page class is created and the initialization code is executed. This produces the initial control tree, which is now typically manipulated by the methods of the page in the following steps. As each node in the tree is a control represented as an instance of a class, the code may change the tree structure as well as manipulate the properties/methods of the individual nodes. Finally, during the rendering step a visitor is used to visit every node in the tree, asking each node to render itself using the methods of the visitor. The resulting HTML output is sent to the client. After the request has been processed, the instance of the page class is discarded and with it the entire control tree. This is a source of confusion among novice ASP.NET programmers who rely on the class instance members that are lost with every page request/response cycle.

State management ASP.NET applications are hosted by a Web server and are accessed using the stateless HTTP protocol. As such, if an application uses stateful interaction, it has to implement state management on its own. ASP.NET provides various functions for state management. Conceptually, Microsoft treats "state" as GUI state. Problems may arise if an application must track "data state"; for example, a finite-state machine that may be in a transient state between requests (lazy evaluation) or takes a long time to initialize. State management in ASP.NET pages with authentication can make Web scraping difficult or impossible.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with ASP.NET Web Forms

Start with the simplest possible case. Write down what ASP.NET Web Forms claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to ASP.NET Web Forms before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about ASP.NET Web Forms ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of ASP.NET Web Forms

In research
ASP.NET Web Forms appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses ASP.NET Web Forms in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
ASP.NET Web Forms is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2002 software, ASP.NET, Microsoft Visual Studio, so understanding it makes those chapters shorter.
In everyday life
Look for ASP.NET Web Forms outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “ASP.NET Web Forms” →

How to study ASP.NET Web Forms in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what ASP.NET Web Forms means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain ASP.NET Web Forms out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is ASP.NET Web Forms in simple terms?

ASP.NET Web Forms is a web application framework and one of several programming models supported by the Microsoft ASP.NET technology. Web Forms applications can be written in any programming language which supports the Common Language Runtime, such as C# or Visual Basic.

Why does ASP.NET Web Forms matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study ASP.NET Web Forms?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on ASP.NET Web Forms.

Tags

  • 2002 software
  • ASP.NET
  • Microsoft Visual Studio
  • Microsoft application programming interfaces
  • Microsoft free software
  • Template engines
  • Web frameworks
  • Windows-only free software

Keep exploring