0% found this document useful (0 votes)
5 views

Web Controls ASP.NET

The document outlines the processing sequence of web control events and the AutoPostBack feature in ASP.NET. It details the steps involved in page life cycle when a control with AutoPostBack is changed, including event firing and state management. Additionally, it provides examples of event handling in a simple application and discusses the implementation of a dynamic e-card generator.

Uploaded by

REHMAN ASHRAF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Web Controls ASP.NET

The document outlines the processing sequence of web control events and the AutoPostBack feature in ASP.NET. It details the steps involved in page life cycle when a control with AutoPostBack is changed, including event firing and state management. Additionally, it provides examples of event handling in a simple application and discusses the implementation of a dynamic e-card generator.

Uploaded by

REHMAN ASHRAF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Web Controls

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.

1. On the client side, the JavaScript _doPostBack function is invoked,


and the page is resubmitted to the server.
2. ASP.NET recreates the Page object using the .aspx file.
3. ASP.NET retrieves state information from the hidden view state field
and updates the controls accordingly.
4. The Page.Load event is fired.
5. The appropriate change event is fired for the control.
6. The Page.Unload event fires, and the page is rendered
(transformed from a set of objects to an Html page).
7. The new page is sent to the client.

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.

• It represents the order in which events are triggered.

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

Log("<< Page_Load >>")

End Sub

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As


EventArgs) Handles MyBase.PreRender

' 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.

Dim ctrlName As String = CType(sender, Control).ID


Log(ctrlName & " Changed")

End Sub

Private Sub Log(ByVal entry As String)


lstEvents.Items.Add(entry)

' 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.

• Can be extended in the following manner


– Store e-cards in a database
– Email notifications to card recipients

20
21
22
23
Page_Load

24
cmdUpdate_Click

25
26

You might also like