Web Controls ASP.NET
Web Controls ASP.NET
Part III
Web Control Events and AutoPostBack
2
Page Processing Sequence
3
Web Control Events
4
Postback Processing Sequence
5
How Postback Events Work
6
7
Page Life Cycle
What happens when a user changes a control that has AutoPostBack
property set to True.
8
Example: Event Tracker Application
• Simple event tracker application
• Write a new entry to a list control every time one of the events it’s
monitoring occurs.
9
First Time Access
10
Text Changed Event
11
Check Changed
12
Radio Option Changed
13
Radio Option Changed
14
Check Changed
15
Text Changed
16
Interface Source Code
17
Code Behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load
End Sub
' When the Page.UnLoad event occurs it is too late to change the list.
Log("Page_PreRender")
End Sub
18
Code Behind
Protected Sub CtrlChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles chk.CheckedChanged, opt1.CheckedChanged,
opt2.CheckedChanged, txt.TextChanged
' Find the control ID of the sender.
' This requires converting the Object type into a Control class.
End Sub
' Select the last item to scroll the list so the most recent entries are visible.
lstEvents.SelectedIndex = lstEvents.Items.Count – 1
End Sub
19
Dynamic E-Card Generator
• A single page utility for creating a dynamic e-card.
20
21
22
23
Page_Load
24
cmdUpdate_Click
25
26