</>
Skip to content
ASP lessons (30/40)

ASP — ASP.NET Web Forms

Web Forms Page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" %>
<html>
<body>
    <form runat="server">
        <asp:TextBox ID="txtName" runat="server" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <asp:Label ID="lblResult" runat="server" />
    </form>
</body>
</html>

Code Behind

public partial class Default : System.Web.UI.Page
{
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblResult.Text = "Hello, " + txtName.Text;
    }
}

Server Controls

ControlDescription
TextBoxText input
ButtonClick button
LabelDisplay text
DropDownListDropdown
GridViewData display
RepeaterRepeat items

ViewState

// Store in ViewState
ViewState["counter"] = 0;

// Retrieve from ViewState
int counter = (int)ViewState["counter"];

Mini Practice

  1. Create Web Forms page
  2. Add server controls
  3. Handle events
  4. Use ViewState

Up Next

Continue with ASP.NET Razor — Razor pages.

Related Topics

Frequently Asked Questions about ASP.NET Web Forms

What is ASP.NET Web Forms in ASP?

ASP.NET Web Forms is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn ASP.NET Web Forms?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ASP.NET Web Forms.

Why is ASP.NET Web Forms important in ASP?

ASP.NET Web Forms is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.