1 / 16

ASP.Net Form Controls

ASP.Net Form Controls. ASP.Net Form Controls Textbox, Button, Label, Literal Triggering input processing RadioButtonList DropDownList CheckBoxList Form Control Validations. ASP.Net Server-side Processing. HTTP Request. HTTP Response. Client. Microsoft Web Server. Web Page. VB.

nau
Download Presentation

ASP.Net Form Controls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.Net Form Controls • ASP.Net Form Controls • Textbox, Button, Label, Literal • Triggering input processing • RadioButtonList • DropDownList • CheckBoxList • Form Control Validations

  2. ASP.Net Server-side Processing HTTP Request HTTP Response Client Microsoft Web Server Web Page VB IIS JScript Scripting Engines Data Components Database Source: Active Server Pages, Wille & Koller, Sams Publishing

  3. ASP.Net Server-side Processing Request for Default.aspx Microsoft Web Server Client Default.aspx sent as a form Clicking Submit button sends Default.aspx page Server runs Button_Click subroutine, writes any output described by subroutine, sends Default.aspx back

  4. ASP.Net Form Controls • Textbox (to get user text input) • Button (to trigger form processing – also can be done by Autopostback when available) • Label or Literal (to display output) • RadioButtonList • DropDownList • CheckBoxList

  5. VB Language Essentials • Declaring variables Dimvariable as Type Dim d1 as Date Dim x, y as Integer Dim z as Single Dim w as Double Dim myname as String Dim misc as Object (a catchall type, to be avoided)

  6. VB Language Essentials • Operators • Mathematical: +, -, *, /, % • Assignment: = • Logical: >, <, >=, <=, <>, AND, OR, NOT • E.g., If x<100 AND x<>90 Then x = x+10 Else x = x+5 End If (If x less than 100 AND x not equal to 90 Then)

  7. VB Language Essentials • If…Else…End If If condition Then statements if condition is true Else statements if condition is false End If • If…Elseif…Else…End If If condition1 Then statements if condition1 is true Elseif condition2 Then statements if condition2 is true Else statements if condition1 & condition2 are false End If

  8. VB Language Essentials • For loops For x = initial value To final value Step value statements within the for loop Next n=20 For x = 1 To n Step 2 Response.Write “Value of X is “ & x total = total + x Next

  9. VB Language Essentials • Sub-routines Sub printtimes(n as Integer) Dim x as Integer For x = 1 To n Response.Write “Printing ” & x & “time” Next End Sub • Calling subroutines <% Dim n1 as Integer n1=10 printtimes(n1) %>

  10. VB Language Essentials • Do While loop Do While condition statements within while loop Loop Dim x,n, total as Integer x=1 n=20 total = 0 Do While x<=n Response.Write “X is ” & x x = x+1 total = total + x Loop

  11. RadioButtonList • Properties • ID, Itemlist (text, value) • Accessing RadioButtonList in VB subroutine • Assume RadioButtonList ID = Rblist1 • Rblist1.SelectedIndex (returns index of selected item, -1 if no item selected) • Rblist1.SelectedValue or Rblist1.SelectedItem.Value (returns value attribute of selected item) • Rblist1.SelectedItem.Text (returns text attribute of selected item) • Autopostback (refreshes the aspx page when selection is changed)

  12. DropDownlist • Properties • ID, Itemlist (text, value) • Accessing DropDownList in VB subroutine • Assume DropDownList ID = Dlist1 • Dlist1.SelectedIndex (returns index of selected item) • Dlist1.SelectedValue or Dlist1.SelectedItem.Value (returns value attribute of selected item) • Dlist1.SelectedItem.Text (returns text attribute of selected item) • Autopostback • Default Selected Item

  13. CheckBoxList • Properties • ID, Itemlist (text, value) • Accessing CheckBoxList in VB subroutine • Assume CheckBoxList ID = Cblist1 • Cbist1.SelectedIndex (returns index of first selected item in the list of checkboxes) • Cblist1.Items.Count (returns number of items created in the list and NOT the number of checkboxes checked) • Cblist1.Items(i) – each item is accessed by its index i • Cblist1.Items(i).Selected (returns True if Item(i) is checked, where i is an index variable created outside the CheckBoxList control) • Cblist1.Items(i).Text (returns the text attribute of Item(i)) • Cblist1.Items(i).Value (returns the value attribute of Item(i))

  14. Processing Checkboxes - Example • Inside the Button_Click Subroutine (Assume the ID for the Checkboxlist = CbList1) Dim i, count, total As Integer, s As String count = 0 total = 0 s = "" ‘For loop is to count and total only the checkboxes that are checked For i = 0 To (CbList1.Items.Count - 1) If CbList1.Items(i).Selected Then count = count + 1 total = total + CbList1.Items(i).Value s = s & CbList1.Items(i).Text & ";" End If Next Label1.Text = "The selected options are: " & s Label2.Text = "Number of options checked: " & count Label3.Text = "Total value of selected options: " & total

  15. Form Controls Validators(Client-side) • Required Field (Textbox, Radiobuttonlist) • Control to validate (required for all validators) • Error Message • Display • Regular Expression (Textbox) • Type of expression to compare with • Range • Maximum Value • Minimum Value • Data type • Compare • Compare with a static value or another control

More Related