Skip to content

ASP.NET Server Controls

Introduction to ASP.NET Server Controls

🔷 What are ASP.NET Server Controls?

ASP.NET Server Controls are built-in web controls provided by the .NET framework that run on the server side and render as standard HTML in the web browser.

They are more powerful than regular HTML controls and allow event-driven programming like desktop applications.


🔷 Features of Server Controls

  • Executed on the server side
  • Automatically generate corresponding HTML for the browser
  • Support event handling (e.g., button clicks)
  • Can be data-bound
  • Managed using code-behind (C# / VB.NET) files

🔷 Syntax Example

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
  • asp: → Indicates an ASP.NET control
  • runat="server" → Makes it server-side and accessible in code-behind
  • ID → Control identifier
  • Text → Display text
  • OnClick → Event handler method

🔷 Types of Server Controls

Type Examples Description
HTML Controls <input>, <textarea> Can be used with runat="server"
Web Controls Label, TextBox, Button Most commonly used controls
Validation Controls RequiredFieldValidator Validates user input
Data Controls GridView, DataList Display and manage data
Navigation Controls Menu, TreeView Navigation menus and site maps
Login Controls Login, CreateUserWizard Built-in authentication support
Rich Controls Calendar, FileUpload Advanced functionality

🔷 Commonly Used Server Controls

Control Purpose
Label Displays text
TextBox Accepts user input
Button Triggers an action on click
DropDownList Select from a list of items
CheckBox Boolean input
RadioButton Single choice among multiple options
GridView Tabular display of data
ListBox Multi-select list
HyperLink Navigates to another URL

🔷 Event Handling

Each server control can raise events that can be handled in the code-behind.

Example:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    lblMessage.Text = "Form Submitted Successfully!";
}

🔷 Benefits of Server Controls

  • Rich set of built-in functionality
  • Event-driven model (like Windows Forms)
  • Easy integration with databases
  • Cleaner and more maintainable code
  • Enhanced productivity through Visual Studio designer

🔷 Limitations

  • Slightly higher server load than pure HTML
  • Less control over raw HTML output
  • Requires .NET-compatible hosting server (e.g., IIS)

🔷 Summary

  • ASP.NET Server Controls are web elements that run on the server-side.
  • They are used to build dynamic, data-driven web pages in ASP.NET.
  • Include a wide variety: Web controls, data controls, validation controls, login controls, etc.
  • Managed using the code-behind logic for interaction and event handling.

✅ HTML Server Controls in ASP.NET

🔷 What Are HTML Server Controls?

HTML Server Controls are standard HTML elements (like <input>, <button>, etc.) that are enhanced to run on the server-side in ASP.NET.

By adding the attribute runat="server" to a standard HTML element, ASP.NET can:

  • Treat it as a server control
  • Access and manipulate it in code-behind (C# or VB.NET)
  • Trigger events on the server

🔶 Syntax

<input type="text" id="txtName" runat="server" />

In code-behind:

txtName.Value = "John";

🔷 How Are They Different from Web Controls?

Feature HTML Server Controls Web Server Controls
Based on HTML Elements ASP.NET specific elements
Appearance Raw HTML Render to complex HTML/CSS
Event Handling Limited Rich event model (OnClick, etc.)
Customization Manual Easier through properties
ViewState Support Limited Full support

🔷 Common HTML Server Controls

HTML Tag ASP.NET Equivalent Usage
<input type="text"> HtmlInputText Single-line input
<input type="password"> HtmlInputPassword Password entry
<input type="submit"> HtmlInputSubmit Submit form
<input type="checkbox"> HtmlInputCheckBox Boolean input
<input type="radio"> HtmlInputRadioButton Option selection
<select> HtmlSelect Dropdown list
<textarea> HtmlTextArea Multi-line text
<button> HtmlButton Action button
<form> HtmlForm Defines form boundaries

🔷 Example

Design (ASPX):

<form id="form1" runat="server">
    <input type="text" id="txtName" runat="server" />
    <input type="submit" id="btnSubmit" runat="server" value="Submit" />
</form>

Code-behind (C#):

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        string name = txtName.Value;
        Response.Write("Welcome, " + name);
    }
}

🔷 Advantages

  • Simple and easy to understand for HTML developers
  • Provides access to existing HTML controls without converting them
  • Can use JavaScript and ASP.NET together

🔷 Limitations

  • Limited server-side event handling
  • Doesn’t support ViewState as fully as Web Controls
  • Less design-time support in Visual Studio

🔷 When to Use

Use HTML Server Controls when:

  • You are working with legacy HTML code
  • You want minimal server overhead
  • You need precise control over HTML output

📌 Summary Table

Feature Description
Purpose Enhance HTML tags to act as server-side controls
Requirement Add runat="server" to HTML tags
Usage Access through code-behind
Limitation Basic functionality; limited event support
Common Use Cases Simple forms, quick enhancements, HTML customization

✅ ASP.NET Web Form Controls (Web Server Controls)

🔷 What Are Web Form Controls?

Web Form Controls are special ASP.NET server-side controls that are used to design interactive and data-driven web forms. Unlike plain HTML controls, they offer:

  • Rich UI features
  • Event-driven programming
  • Full support for ViewState and postback
  • Easy data binding and validation

They must include runat="server" so they can be accessed and manipulated in the code-behind.


🔷 Syntax Example

<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

Code-behind (C#):

protected void btnSubmit_Click(object sender, EventArgs e)
{
    string name = txtName.Text;
    lblGreeting.Text = "Hello, " + name;
}

🔷 Categories of Web Form Controls

Category Controls Description
Input TextBox, CheckBox, RadioButton Accepts user input
Display Label, Literal, Image Displays text/images
Button Button, LinkButton, ImageButton Triggers server-side events
Selection DropDownList, ListBox, CheckBoxList, RadioButtonList Allows user selection
Data GridView, DetailsView, FormView, Repeater For displaying and editing data
Navigation HyperLink, Menu, SiteMapPath Page and site navigation
Validation RequiredFieldValidator, CompareValidator Used for input validation
Rich UI Calendar, FileUpload, MultiView, Wizard Enhanced interaction

🔷 Commonly Used Controls

Control Description
Label Displays text (read-only)
TextBox Accepts single/multi-line text input
Button Performs actions when clicked
DropDownList Single item selection from a list
CheckBox Boolean (true/false) option
RadioButton Single choice from a group
GridView Displays data in a table format
Calendar Displays a selectable calendar
FileUpload Allows file upload from user

🔷 Properties, Events, and Methods

Element Description
ID Unique identifier for the control
Text Text displayed or stored in the control
Enabled Enables/disables control
Visible Show/hide control
AutoPostBack Automatically posts back on change
OnClick, OnTextChanged Event handlers

🔷 Example: Form with Web Controls

ASPX:

<asp:Label ID="lblName" runat="server" Text="Enter Name:" />
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnGreet" runat="server" Text="Greet" OnClick="btnGreet_Click" />
<asp:Label ID="lblResult" runat="server" />

C#:

protected void btnGreet_Click(object sender, EventArgs e)
{
    lblResult.Text = "Welcome, " + txtName.Text;
}

🔷 Advantages of Web Form Controls

  • Easy to use with drag-and-drop in Visual Studio
  • Rich event handling (like Button_Click)
  • Built-in support for ViewState
  • Easily bind to data sources
  • Integrates with validation controls for form validation

🔷 ViewState

ASP.NET maintains the state of controls using ViewState, even after postbacks (e.g., button click or page reload).

🔹 Web controls automatically preserve their values between postbacks using ViewState.


🔷 Summary Table

Feature Description
Web Controls Server-side UI elements for ASP.NET web forms
Benefits Event-driven, data-bound, viewstate-supported
Examples TextBox, Label, Button, GridView, DropDownList
Usage With runat="server" and code-behind logic
Output Rendered as standard HTML to the browser

✅ Field Validator Controls in ASP.NET

🔷 What Are Field Validator Controls?

Field Validator Controls in ASP.NET are server-side controls used to validate user input before it's processed by the server.

These controls ensure:

  • Required fields are not empty
  • Data entered is in the correct format (e.g., number, date, email)
  • Values match expected criteria (range, pattern, comparison, etc.)

🔷 Why Use Validation Controls?

✅ To avoid incorrect or incomplete data from users ✅ To enforce business rules (e.g., age ≥ 18) ✅ To improve data accuracy and security


🔷 Common ASP.NET Validation Controls

Control Name Description
RequiredFieldValidator Ensures a field is not empty
CompareValidator Compares input to another value or field
RangeValidator Checks if input falls within a range
RegularExpressionValidator Validates input using regex
CustomValidator Allows custom validation logic using server or client-side code
ValidationSummary Displays a summary of all errors on the page

🔷 Basic Properties of Validator Controls

Property Description
ControlToValidate ID of the input control to validate
ErrorMessage Message displayed if validation fails
Text Short error symbol (like *) shown beside the field
Display How error is displayed: None, Static, Dynamic
EnableClientScript Enables client-side validation using JavaScript

🔷 Examples

✅ 1. RequiredFieldValidator

<asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator ID="reqName" runat="server" 
     ControlToValidate="txtName"
     ErrorMessage="Name is required!" 
     ForeColor="Red" />

✅ 2. CompareValidator

<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" />
<asp:TextBox ID="txtConfirm" runat="server" TextMode="Password" />
<asp:CompareValidator ID="cmpPassword" runat="server"
     ControlToValidate="txtConfirm" 
     ControlToCompare="txtPassword"
     ErrorMessage="Passwords do not match" 
     ForeColor="Red" />

✅ 3. RangeValidator

<asp:TextBox ID="txtAge" runat="server" />
<asp:RangeValidator ID="rngAge" runat="server"
     ControlToValidate="txtAge"
     MinimumValue="18" MaximumValue="60"
     Type="Integer" 
     ErrorMessage="Age must be between 18 and 60" 
     ForeColor="Red" />

✅ 4. RegularExpressionValidator

<asp:TextBox ID="txtEmail" runat="server" />
<asp:RegularExpressionValidator ID="regEmail" runat="server"
     ControlToValidate="txtEmail"
     ValidationExpression="\w+@\w+\.\w+"
     ErrorMessage="Enter a valid email address" 
     ForeColor="Red" />

✅ 5. CustomValidator

<asp:TextBox ID="txtCode" runat="server" />
<asp:CustomValidator ID="custCode" runat="server"
     ControlToValidate="txtCode"
     OnServerValidate="ValidateCode"
     ErrorMessage="Invalid Code" 
     ForeColor="Red" />

Code-behind:

protected void ValidateCode(object source, ServerValidateEventArgs args)
{
    args.IsValid = (args.Value == "1234");
}

✅ 6. ValidationSummary

<asp:ValidationSummary ID="valSummary" runat="server" 
    HeaderText="Please fix the following errors:" 
    ForeColor="Red" />

🔷 Client-side vs Server-side Validation

Type Description
Client-side Performed using JavaScript before sending data to server
Server-side Performed on the server for security and final validation

ASP.NET supports both. If JavaScript is disabled in the browser, server-side validation still works.


🔷 Grouping Validators

Use the ValidationGroup property to group controls:

<asp:Button ID="btnSubmit" runat="server" ValidationGroup="Group1" />

Apply ValidationGroup="Group1" to relevant validators and controls.


🔷 Summary Table

Control Validates
RequiredFieldValidator Field is not left blank
CompareValidator Equality between two values
RangeValidator Value within a specified numeric or date range
RegularExpressionValidator Value matches a regular expression (format)
CustomValidator Custom logic using code
ValidationSummary Shows all validation errors together

✅ Creating a Web Form in ASP.NET (Web Forms Model)

🔷 What is a Web Form?

A Web Form is a page (.aspx file) in an ASP.NET Web Application that allows users to interact with the web app through a graphical user interface (GUI).

Web Forms are designed using Web Server Controls (like TextBox, Button, etc.) and processed using C# or VB.NET in the code-behind.


🔷 Steps to Create a Web Form

🧩 1. Open Visual Studio

  • Open Visual Studio
  • Click on: FileNewProject → Select ASP.NET Web Application (.NET Framework)
  • Choose Web Forms and click Create

🧩 2. Add a New Web Form

  • Right-click on your project → AddWeb Form
  • Name it: MyForm.aspx

🔷 Example: Simple Web Form

📄 MyForm.aspx (Design View)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyForm.aspx.cs" Inherits="MyForm" %>

<!DOCTYPE html>
<html>
<head>
    <title>Simple Web Form</title>
</head>
<body>
    <form id="form1" runat="server">
        <h2>User Information</h2>
        <asp:Label ID="lblName" runat="server" Text="Name: " />
        <asp:TextBox ID="txtName" runat="server" />
        <br /><br />
        <asp:Label ID="lblAge" runat="server" Text="Age: " />
        <asp:TextBox ID="txtAge" runat="server" />
        <br /><br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <br /><br />
        <asp:Label ID="lblResult" runat="server" ForeColor="Blue" />
    </form>
</body>
</html>

📄 MyForm.aspx.cs (Code-behind)

using System;

public partial class MyForm : System.Web.UI.Page
{
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string name = txtName.Text;
        string age = txtAge.Text;
        lblResult.Text = $"Hello {name}, you are {age} years old.";
    }
}

🔷 Output

When you run the form and enter your name and age, clicking the Submit button displays a message:

Hello John, you are 25 years old.


🔷 Summary of Web Form Elements

Part Description
Page Directive Top line that defines page settings
runat="server" Required for server-side processing
Web Controls Components like TextBox, Button
Code-behind Handles logic like button click

✅ Page Rendering Model in ASP.NET (Web Forms)

🔷 What Is the Page Rendering Model?

The ASP.NET Page Rendering Model describes how a Web Form (ASPX page) is processed from initial request to the final HTML output that is sent to the user's browser.

In simple terms: Client Request ➝ ASP.NET Server Processing ➝ HTML Response


🔷 Stages of the Page Rendering Lifecycle

When a user requests an .aspx page, ASP.NET executes several stages internally. Here's the detailed flow:


🔹 1. Page Request

  • The browser requests an .aspx page.
  • ASP.NET checks if the page needs to be compiled.

  • If yes, it compiles the page into a .NET class.

  • The request is handed over to the Page Handler.

🔹 2. Start

  • Initializes key page properties like:

  • Request, Response, Session, IsPostBack

  • Page begins tracking ViewState.

🔹 3. Initialization

  • All controls on the page are initialized.
  • They are given a unique ID.
  • No actual data is loaded yet.
Page.Init += new EventHandler(Page_Init);

🔹 4. Load ViewState

  • The previously saved ViewState (hidden field on the page) is restored.
  • This makes controls retain their old values on postback.

🔹 5. Load PostBack Data

  • Loads form data sent by the user.
  • Updates control properties like TextBox.Text or CheckBox.Checked.

🔹 6. Load

  • Page_Load and control events are triggered.
  • You typically write your business logic here:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // Initial load
    }
}

🔹 7. PostBack Event Handling

  • Executes control-specific events.
  • Example: Button_Click, DropDownList_SelectedIndexChanged

🔹 8. Rendering

  • All controls generate their HTML output.
  • The page combines all outputs into one final HTML.
protected override void Render(HtmlTextWriter writer)
{
    // Custom HTML rendering if needed
    base.Render(writer);
}

🔹 9. Unload

  • Cleanup activities like closing DB connections.
  • This happens after the page is sent to the client.
protected void Page_Unload(object sender, EventArgs e)
{
    // Cleanup code
}

🔷 Summary of Lifecycle Methods

Stage Description
Page_Init Initialize controls
LoadViewState Restore previous state
LoadPostData Load form data sent by the user
Page_Load Main logic – runs on every request
Event Handlers Run user actions (e.g., button clicks)
Page_PreRender Last chance to modify data before rendering
Page_Unload Clean up (no UI logic here)

🔷 Diagram: Simplified Rendering Flow

Browser Request
     ↓
Page Initialization
     ↓
Load ViewState
     ↓
Load PostBack Data
     ↓
Page Load
     ↓
Event Handlers
     ↓
PreRender
     ↓
Render → HTML Sent to Browser
     ↓
Unload (Cleanup)

🔷 Final Output

  • All server-side controls like <asp:TextBox> and <asp:GridView> are converted to pure HTML.
  • Only HTML/JavaScript/CSS is sent to the client browser.

🔷 Key Points to Remember

  • Page_Load happens on every request.
  • ViewState helps preserve control values between postbacks.
  • Only the final HTML is visible to the browser.
  • You can override Render() to customize HTML output.

✅ Custom Rendering Controls in ASP.NET (Web Forms)

🔷 What Are Custom Rendering Controls?

Custom Rendering Controls are server controls in ASP.NET that override the default HTML output and generate custom HTML manually during the rendering phase.

They are used when the default Web Form controls (like <asp:TextBox>, <asp:Button>, etc.) do not meet UI or behavior requirements.


🔷 Why Use Custom Rendering?

Reason Explanation
🧩 Full control You want precise control over how HTML is generated
🎨 UI customization You want HTML structure different from default
📱 Lightweight controls Avoid ViewState and use minimal markup
🔄 Reusable logic You want a reusable control with custom output

🔷 Key Concepts

  • Inherit from: System.Web.UI.Control or WebControl
  • Override the method: Render(HtmlTextWriter writer)
  • Use writer object to emit HTML directly

🔷 Example: Creating a Custom Label Control

1. Code Behind (C#)

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public class CustomLabel : WebControl
{
    public string Text { get; set; }

    protected override void Render(HtmlTextWriter writer)
    {
        writer.AddStyleAttribute("color", "blue");
        writer.RenderBeginTag(HtmlTextWriterTag.Span); // <span>
        writer.Write(Text);                            // write content
        writer.RenderEndTag();                         // </span>
    }
}

2. Register and Use in ASPX Page

<%@ Register TagPrefix="custom" Namespace="YourNamespace" Assembly="YourAssembly" %>

<custom:CustomLabel ID="lbl1" runat="server" Text="Welcome to ASP.NET!" />

🔷 How It Works

  • ASP.NET calls the control’s Render() method during the Render phase.
  • The control emits pure HTML using the HtmlTextWriter.
  • The browser receives custom-styled output, not the default WebControl HTML.

🔷 HtmlTextWriter Methods

Method Description
RenderBeginTag() Writes an opening HTML tag
RenderEndTag() Writes a closing HTML tag
AddAttribute() Adds attributes like class, id, etc.
AddStyleAttribute() Adds inline CSS styles
Write() Writes raw text or content

🔷 Example 2: Render Custom Button

public class CustomButton : WebControl
{
    public string Label { get; set; }

    protected override void Render(HtmlTextWriter writer)
    {
        writer.AddAttribute("type", "button");
        writer.AddAttribute("onclick", "alert('Hello!')");
        writer.RenderBeginTag(HtmlTextWriterTag.Input);
        writer.Write(Label);
        writer.RenderEndTag();
    }
}

🔷 Benefits of Custom Rendering

✅ Optimized HTML output ✅ Avoid ViewState (better performance) ✅ Complete control over structure and styling ✅ Can generate responsive UI elements


🔷 When to Use

  • When built-in controls cannot meet design needs
  • When working with JavaScript-heavy or mobile-friendly apps
  • When building reusable UI components

🔷 Difference: Custom Control vs User Control

Aspect Custom Control User Control
Code Type Class (.cs file) ASPX-like file (.ascx)
Flexibility Full control over rendering Limited to layout-based control
Reusability Highly reusable across apps Mostly reusable within the same app

🔷 Summary

  • Custom rendering is done using Render(HtmlTextWriter writer)
  • You control the output HTML using code
  • Best suited for advanced UI needs or high-performance web controls

✅ Developing Composite Control in ASP.NET

🔷 What Is a Composite Control?

A Composite Control in ASP.NET is a custom server control that combines multiple child controls (like TextBox, Button, Label, etc.) into a single reusable control.

Think of it as building a mini form or custom UI widget using existing ASP.NET controls, packaged as one control.


🔷 Why Use Composite Controls?

Benefit Description
🎯 Reusability One control, used in multiple pages
🔄 Encapsulation Combines logic and UI into one place
💡 Maintainability Easy to manage and modify
📦 Custom Functionality Can have events, validation, and custom layout

🔷 How to Create a Composite Control

✅ Step-by-Step:

  1. Inherit from CompositeControl (or WebControl)
  2. Create child controls (like TextBox, Button)
  3. Override CreateChildControls()
  4. Add logic and properties
  5. Register and use in ASPX page

🔷 🧪 Example: Login Composite Control

1. C# Code: LoginBox.cs

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public class LoginBox : CompositeControl
{
    private TextBox txtUsername;
    private TextBox txtPassword;
    private Button btnLogin;
    private Label lblMessage;

    protected override void CreateChildControls()
    {
        // Username
        txtUsername = new TextBox { ID = "txtUsername", Placeholder = "Username" };
        Controls.Add(txtUsername);

        // Password
        txtPassword = new TextBox { ID = "txtPassword", TextMode = TextBoxMode.Password, Placeholder = "Password" };
        Controls.Add(txtPassword);

        // Button
        btnLogin = new Button { ID = "btnLogin", Text = "Login" };
        btnLogin.Click += BtnLogin_Click;
        Controls.Add(btnLogin);

        // Message
        lblMessage = new Label { ID = "lblMessage", ForeColor = System.Drawing.Color.Red };
        Controls.Add(lblMessage);
    }

    private void BtnLogin_Click(object sender, EventArgs e)
    {
        if (txtUsername.Text == "admin" && txtPassword.Text == "123")
        {
            lblMessage.Text = "Login successful!";
            lblMessage.ForeColor = System.Drawing.Color.Green;
        }
        else
        {
            lblMessage.Text = "Invalid credentials!";
        }
    }
}

🔷 2. Registering in ASPX

Assume this control is in a compiled DLL or App_Code:

<%@ Register TagPrefix="custom" Namespace="YourNamespace" Assembly="YourAssembly" %>

<custom:LoginBox ID="loginBox1" runat="server" />

🔷 3. Output (What User Sees)

[ Username     ]   ← TextBox  
[ Password     ]   ← Password TextBox  
[ Login ]          ← Button  
Login successful!  ← Label (after correct input)

🔷 Important Methods/Events

Method Purpose
CreateChildControls() Used to create and initialize child controls
EnsureChildControls() Ensures controls are created before access
OnPreRender() For final logic or visual setup
Render() Used to customize output HTML

🔷 Differences: User Control vs Composite Control

Feature User Control (.ascx) Composite Control (C# Class)
Design View Visual Designer available Written entirely in code
Reusability Mostly within same project Highly reusable, even across projects
Flexibility Limited customization Full control over structure & behavior

🔷 Summary

  • Composite Controls are custom C# classes that bundle multiple child controls.
  • Override CreateChildControls() to define your control layout and logic.
  • Helps to reuse complex UI elements and improve code maintainability.

✅ Control Potpourri in ASP.NET (Web Forms)

🔷 What is "Control Potpourri"?

Control Potpourri” refers to a collection of various useful ASP.NET server controls that are commonly used in web applications, beyond the standard TextBox, Button, and Label.

Think of it like a grab bag of diverse controls with unique purposes — improving user interaction, layout, data display, and input handling.


🔷 Commonly Included Controls in Potpourri

Below are some important controls that typically fall under the "control potpourri" category:


🔹 1. Calendar Control

  • Displays a full calendar to pick dates.
  • Useful for date selection in forms.
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>

🧠 Events: SelectionChanged — Triggered when a user picks a date.


🔹 2. AdRotator

  • Displays rotating banner ads or images.
  • Pulls data from an XML file or data source.
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ads.xml" />

🧠 Needs an XML file like:

<Advertisements>
  <Ad ImageUrl="banner1.jpg" NavigateUrl="http://example.com" />
</Advertisements>

🔹 3. FileUpload Control

  • Allows users to upload files to the server.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />

🧠 In code-behind:

if (FileUpload1.HasFile)
{
    FileUpload1.SaveAs(Server.MapPath("~/uploads/" + FileUpload1.FileName));
}

🔹 4. MultiView and View Controls

  • MultiView contains multiple View panels.
  • Only one View is visible at a time — like a wizard or multi-step form.
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    <asp:View ID="View1" runat="server">Step 1</asp:View>
    <asp:View ID="View2" runat="server">Step 2</asp:View>
</asp:MultiView>

🧠 Switch views:

MultiView1.ActiveViewIndex = 1;

🔹 5. Wizard Control

  • A specialized control for multi-step processes.
  • Includes navigation (Next, Previous, Finish).
<asp:Wizard ID="Wizard1" runat="server">
    <WizardSteps>
        <asp:WizardStep Title="Step 1">Enter Details</asp:WizardStep>
        <asp:WizardStep Title="Step 2">Confirm</asp:WizardStep>
    </WizardSteps>
</asp:Wizard>

🔹 6. Panel Control

  • A container for grouping other controls.
  • Can be shown/hidden dynamically.
<asp:Panel ID="Panel1" runat="server" Visible="false">
    <asp:Label ID="Label1" runat="server" Text="Inside Panel" />
</asp:Panel>

🔹 7. Image and ImageButton

  • Image is for displaying images.
  • ImageButton is an image that behaves like a button.
<asp:Image ID="Image1" runat="server" ImageUrl="~/logo.png" />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/submit.png" OnClick="ImageButton1_Click" />

🔹 8. Literal and PlaceHolder

  • Literal: Displays plain text or HTML.
  • PlaceHolder: Holds dynamic controls — doesn't render anything unless populated.
<asp:Literal ID="Literal1" runat="server" Text="Welcome!" />
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />

🧠 Add controls at runtime:

PlaceHolder1.Controls.Add(new TextBox());

🔹 9. BulletedList

  • Displays a list of items with bullets or numbering.
<asp:BulletedList ID="BulletedList1" runat="server" BulletStyle="Numbered">
    <asp:ListItem>Item 1</asp:ListItem>
    <asp:ListItem>Item 2</asp:ListItem>
</asp:BulletedList>

🔹 10. Table Control

  • Allows server-side generation of HTML tables.
Table table = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = "Cell Content";
row.Cells.Add(cell);
table.Rows.Add(row);
PlaceHolder1.Controls.Add(table);

🔷 Summary Table

Control Purpose
Calendar Date selection UI
AdRotator Display rotating images/ads
FileUpload Upload files to the server
MultiView Multi-step view container
Wizard Step-by-step process flow
Panel Group controls, show/hide block
Literal Render plain HTML/text
PlaceHolder Add controls dynamically
BulletedList Display bullet/numbered list
ImageButton Image with button action

✅ Summary

  • Control Potpourri refers to a variety of useful ASP.NET controls.
  • These controls enhance interactivity, layout, and user experience.
  • Many of them allow server-side logic and dynamic rendering.