WebForm - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

WebForm

Description:

As each time the page is reloaded all data is lost. ... As webpages are stateless, on every page reload, the textbox values should disappear. ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 18
Provided by: mche6
Category:
Tags: webform | reloaded

less

Transcript and Presenter's Notes

Title: WebForm


1
WebForm
  • Objective
  • Web aspx flow sequence
  • Common Control color alignment
  • Response.write/ redirect, server transfer
  • Page object
  • Session variable
  • View State.
  • ArrayList HashTable

2
Executing .ASPX
3
WebServer Controlvs HTML Control
  • Webserver controls run on the server.
  • E.g. you can program a server button as before.
    (double click to get the button_click event.)
  • But you cannot program a HTML button.
  • Also, the HTML table cannot be access in VB. i.e.
    you cant get me.table1 (Alignment must be done
    using HTML)

4
DropDownList
  • ComboBox replaced by DropdownList.
  • To get the selected value use
  • Dropdownlist1.selecteditem.text (different from
    combobox).
  • use the AutoPostBack property
  • to choose how to handle
  • selectedindexchange
  • Post page to server
  • Ignore indexchange..

5
RadioButtonList
  • To show a list of radiobuttons
  • Use the items collection to add buttons and text.
  • Use the
  • SelectedIndexChanged
  • sub to get selected item
  • ResponseWrite(Me.RadioButtonList1.SelectedItem.Te
    xt)

6
Use of Panel and PlaceHolder
  • Use of panel and placeholder to hold other
    controls.
  • Place buttons and textboxes in panel and make
    them visible or otherwise.
  • Me.panel1.visible true / false.
  • Home work investigate PlaceHolder.

7
Response.Write/Redirect
  • Response.Write writes a message to the client
    browser. E.g. response.write(Hello)
  • E.g. response.write ( ltigt Crazy crazy lt/igt)
    sends an italic Crazy crazy to the browser.
  • Response.redirect redirect to another page.
  • E.g. jump to another page with
  • reponse.redirect(webform2.aspx)

8
Page.IsPostBack
  • An .aspx is repeatly called by the brower.
  • Th form_load event in windowapplications, only
    run once when the form is loaded.
  • The page_load sub is run everytime the .aspx is
    called
  • To tell whether the page is called the first time
    or subsequent times Use the page.Ispostback
  • page.Ispostback means 2nd,3rd,4th .. Times.
  • If not page.Ispostback then checks 1st time.

9
PageLoad Initialization
  • Perform initialization work once in page load.
    For example initialize listbox fill dataset.
  • Sub Page_load (..
  • If not page.IsPostBack then
  • RadioButtonList1.Items.Add("aa")
  • RadioButtonList1.Items.Add("bb")
  • me.dbProd.Fill(dsProd1)
  • session(dsProduct) dsProd1
  • End if
  • End sub

10
Keeping state with session var.
  • As each time the page is reloaded all data is
    lost.
  • When transferring to another page, you need to
    keep track of info such as login id or datasets.
  • Use the session variables to keep data while the
    session is running.

11
Session Variables
  • To create a session variable, in webform1
  • session(loginID) S001
  • To retrieve the session variable in webform2
    user session(loginID)

webform2
webform1
session(loginID) S001
Dim user as string User session(loginID)
12
Session variable (Counting)
  • Dim ing a global variable to Count will NOT
    work in webform.
  • count is redim to 0 everytime
  • the page is reloaded.
  • Label will always show
  • 1, no matter how many
  • times the button is
  • clicked.
  • Soln Use session(count) 1.

Dim count as integer Sub button1_click(.
count count 1 label1.text count End Sub
button2_click(. session(count) 1
label1.text count end
13
Session Var. and Redirect
  • Session variable is used to keep variables alive
    between page loads and page jumps.
  • BUT it does NOT always work with
    response.redirect.
  • Instead use Server.transfer
  • e.g. Server.Transfer(webform2.aspx)

14
Keeping value with ViewState
  • As webpages are stateless, on every page reload,
    the textbox values should disappear. The values
    in textboxes are kept using the viewstate
    EnableViewState True.

15
ArrayList
  • ArrayList functions similarly to Listbox.
  • Dim pass as New Arraylist
  • pass.Add("111")
  • pass.Add("222")
  • pass.Add("333")
  • ArrayList has properties
  • Sort, reverse, count,
  • Contain, insert, .

16
HashTables
  • Store passwords in Hashtable
  • Dim hash as new Hashtable
  • hash.Add("S001", "111")
  • hash.Add("S002", "222")
  • hash.Add("S003", "333")
  • hash.Add("S004", "444")
  • hash.Add("S005", "555")
  • To get password for S003 use hash(S003)

17
Moving Applications
  • After you move a webapplication folder.
  • Right-click on the folder and select sharing
  • Choose web-sharing tab.
  • Start IIS.
  • Turn off the proxy using -- IE5 ?Tools ?
    InternetOptions ? Connections ? LanSettings
  • Click on the project to run.
Write a Comment
User Comments (0)
About PowerShow.com