Web Controls - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Web Controls

Description:

It allows one class to acquire all the properties and methods ... html xmlns='http://www.w3.org/1999/xhtml' head runat='server' title Index Page /title ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 20
Provided by: saxserv
Category:
Tags: controls | web | xhtml

less

Transcript and Presenter's Notes

Title: Web Controls


1
Web Controls
2
Outline
  • Processing Web Controls
  • For Each Loop
  • Postback

3
More on Class
  • Class is a blueprint for which objects are
    created
  • Class inheritance
  • It allows one class to acquire all the properties
    and methods of the parent class
  • Partial class
  • It allows you to split a single class into more
    than one file

4
Default.aspx
  • lt_at_ Page Language"VB" AutoEventWireup"false"
    CodeFile"Default.aspx.vb" Inherits"_Default" gt
  • lthtml xmlns"http//www.w3.org/1999/xhtml" gt
  • lthead runat"server"gt
  • lttitlegtIndex Pagelt/titlegt
  • lt/headgt
  • ltbodygt
  • ltform id"form1" runat"server"gt
  • ltdivgt
  • ltaspLabel ID"Label1" runat"server"
    Text"Enter Name"gtlt/aspLabelgt
  • ltaspTextBox ID"TextBox1" runat"server"
    gtlt/aspTextBoxgt
  • ltaspButton ID"Button1" runat"server"
    Text"Submit" /gt
  • lt/divgt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

5
Default.aspx.vb
  • Partial Class _Default Inherits
    System.Web.UI.Page
  • Protected Sub Button1_Click(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    Button1.Click
  • TextBox1.Text "Here is some sample
    text."
  • End Sub
  • End Class

6
Procedures
  • Subroutines or sub-procedures do not return
    values
  • Create a Subroutine
  • Declared using the keyword Sub
  • Exit sub statement to exit the subroutine
  • End with the keywords End Sub

7
Event Procedure
  • An event procedure is not executed until an event
    triggers the event procedure
  • An event procedure does not return a value
  • The Page_Load event procedure is triggered when
    the page is loaded into the browser

8
Page Events
  • The Page object consists of a variety of methods,
    functions, and properties that can be accessed
    within the code behind the page
  • The first time a page is requested by a client, a
    series of page events occurs
  • The first page event is the Page_Init event which
    initializes the page control hierarchy
  • The Page_Load event loads any server controls
    into memory and occurs every time the page is
    executed

9
simple.aspx
  • lt_at_ Page Language"VB" AutoEventWireup"false"
    CodeFile"simple.aspx.vb" Inherits"simple" gt
  • lthtml xmlns"http//www.w3.org/1999/xhtml" gt
  • lthead runat"server"gt
  • lttitlegtUntitled Pagelt/titlegt
  • lt/headgt
  • ltbodygt
  • ltform id"form1" runat"server"gt
  • ltdivgt
  • lt/divgt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

10
simple.aspx.vb
  • Partial Class simple Inherits System.Web.UI.Page
  • Protected Sub Page_Load(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    Me.Load
  • Response.Write("This is my first line of
    ASP.NET program. ltbrgt")
  • Response.Write("More to come next week.
    ltbrgt")
  • End Sub
  • End Class

11
Textbox
  • ltasptextbox id"txtName" runat"server " /gt
  • Code to retrieve the value of the textbox
  • Dim name as String txtName.Text

12
Drop-down List
  • ltaspdropdownlist id"list1" runat"server"gt
  • ltasplistitem Selected"True"gtMadridlt/asplisti
    temgt
  • ltasplistitemgtOslolt/asplistitemgt
  • ltasplistitemgtLisbonlt/asplistitemgt
  • lt/aspdropdownlistgt
  • Code to retrieve the value of a selected item
  • Dim city as String list1.SelectedItem.Value
  • Syntax to retrieve a property value of an object
  • objName.PropertyName

13
Radio Button
  • ltaspradiobuttonlist id"fare" runat"server"gt
  • ltasplistitem runat"server" value"First
    class" Selected"True" /gt
  • ltasplistitem runat"server" value"Coach"
    /gt
  • lt/aspradiobuttonlistgtltbr /gt
  • Code to retrieve the value of a radio button
  • Dim fareclass as String fare.SelectedItem.value

14
ListItem class
  • Property
  • Count -- the number of items
  • Selected -- Gets or sets a value indicating
    whether the item is selected
  • Text -- Gets or sets the text displayed in a list
    control for the item represented by the ListItem
  • Method
  • Add(ListItem) -- adds a list item

15
For Each Loop
  • Loop through the items in a set of data
  • Dim lstItem as ListItem
  • For Each lstItem In chklst.Items
  • Next

16
Postback
  • The process of posting data back to a form is
    known as postback
  • All web controls support postback by default
  • The values that are stored with the page remain
    with the page

17
Auto Postback
  • It means that the control will have a post back
    immediately when it detects a user action

18
Page.IsPostBack
  • Page default object
  • Belongs to web page class
  • IsPostBack
  • A property of the web page class
  • Boolean variable
  • False when the page is displayed the first time
  • True the page is being redisplayed in response
    to a control event

19
Web.config
  • Upload and store the file at your folder on the
    server
  • It can control error message display
  • The following web.config will allow error
    messages to be displayed
  • lt!-- Web.Config Configuration File --gt
  • ltconfigurationgt
  • ltsystem.webgt
  • ltcustomErrors mode"Off"/gt
  • lt/system.webgt
  • lt/configurationgt
Write a Comment
User Comments (0)
About PowerShow.com