Vb.Net Web Forms

6,940 views

Published on

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
  • Sir, very fine mrng 2 U !
    Would u pls send me this Lucky Chance to DwnLoad dis Classy File.... Sir with all ur Lovely blessings...
    I got a Job in ITI (INDIAN TECHNICAL TRAINING)
    SO WHY DON'T YOU SEND ME THIS ppt without delay..
    it really had made me captivated....
    Hopin a positive reply frm ur Side........
    with Warm Regards
    RACHIT GAUR
    I T I LAHURABEER, VNS(UP- INDIA).. thanks!!!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
6,940
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
0
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide
  • Vb.Net Web Forms

    1. 1. Copyright ©2004 and Distribution Rights Held by DotNetTechnology, LLC. This material is exclusively used by DotNetTechnology, LLC Consultants as a teaching aid. Any unauthorized usage including teaching, copying, and redistribution is strictly prohibited. .NET Programming with VB.NET Dutch Dasanaike November 2004 VB.Net Dutch Dasanaike © 2004 DotNetTechnology.com . All rights reserved. ASP.NET Web Forms
    2. 2. A Simple ASP.NET Web Form <ul><li><%@ Page Language=“VB”%> </li></ul><ul><li><script runat=“server”> </li></ul><ul><li>Public Sub Page_Load(Src as Object, E as EventArgs) </li></ul><ul><li>lblOutput.Text = “This is Label Text.” </li></ul><ul><li>End Sub </li></ul><ul><li></script> </li></ul><ul><li><html> </li></ul><ul><li><body bgcolor=“#ffffff”> </li></ul><ul><li><form id=“frmHW” runat=“server”> </li></ul><ul><li><asp:Label id=“lblOutput” runat=“server” /> </li></ul><ul><li></form> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>ASP.NET code HTML code
    3. 3. Web Forms and Code Behind Pages <ul><li>Programming code (VB.NET, C#, etc.) for Web Forms can be placed into one file along with the HTML or stored separately in a code behind file. </li></ul><HTML> form.aspx Code <HTML> form.aspx Code form.aspx.vb Single file Separate files (Code behind)
    4. 4. Code Behind Directives <ul><li>An ASP.NET code behind page can be referred to by using the following directives: </li></ul><ul><li><%@ Page Language=“VB” Src=“form.aspx.vb” </li></ul><ul><li>Inherits=“MyNamespace.MyClassName” %> </li></ul><ul><li>If using Visual Studio.NET you can also use the Codebehind directive: </li></ul><ul><li><%@ Page Language=“VB” Codebehind=“form.aspx.vb” </li></ul><ul><li>AutoEventWireup=“false” Inherits=“MyNamespace.MyClassName” %> </li></ul>Only used by VS.NET “ Src” directive causes code behind page to automatically compile when the Web Form is first hit.
    5. 5. Introduction to ASP.NET Server Controls <ul><li>Server controls are software components that can be used in Web Forms to collect, display, and validate data. </li></ul><ul><li>Server controls have properties, methods, and events that can be programmed against in Web Forms. </li></ul><ul><li>Four basic types of server controls exist: </li></ul><ul><ul><li>Web server controls : Strongly-typed programmable objects </li></ul></ul><ul><ul><li>HTML server controls : Similar to regular HTML elements, but you control them on the server side </li></ul></ul><ul><ul><li>Validation controls : Used to validate Web Form submissions </li></ul></ul><ul><ul><li>User controls : Custom-built controls (Example: login screen, header, etc.) </li></ul></ul>
    6. 6. Web Server Controls <ul><li>Web server controls simplify the processes of collecting user input, displaying data, and showing calendars, as well as other functions. </li></ul><ul><li>Benefits of Web server controls: </li></ul><ul><ul><li>Reduce complex code in Web Forms </li></ul></ul><ul><ul><li>Object-oriented (support for events) </li></ul></ul><ul><ul><li>Extensible and customizable </li></ul></ul><ul><ul><li>Support for data binding </li></ul></ul><ul><ul><li>Simply to use and configure </li></ul></ul><ul><ul><li>Custom controls can be created </li></ul></ul><ul><ul><li>Strongly-typed (lblMsg.Text=“Hi There!”) </li></ul></ul><ul><ul><li>Target multiple browser types </li></ul></ul>
    7. 7. Web Server Controls Hierarchy
    8. 8. Using Web Server Controls <ul><li>ASP.NET Web server controls are used in a Web Form by prefixing the control name with an asp namespace prefix: </li></ul><ul><ul><li><asp:Label id=“lblHello” Text=“Hello” runat=“server” /> </li></ul></ul><ul><li>asp:Textbox web server control examples: </li></ul><ul><ul><li>Regular textbox: </li></ul></ul><ul><ul><li><asp:Textbox id=“txtFirstName” runat=“server” /> </li></ul></ul><ul><ul><li>Password textbox: </li></ul></ul><ul><ul><li><asp:Textbox id=“txtFirstName” TextMode=“Password” runat=“server” /> </li></ul></ul><ul><ul><li>TextArea textbox (multiline): </li></ul></ul><ul><ul><li><asp:Textbox id=“txtFirstName” TextMode=“MultiLine” Rows=“5” Columns=“50” runat=“server” /> </li></ul></ul>
    9. 9. Web Server Controls Example <ul><li><%@ Page Language=&quot;VB&quot;%> </li></ul><ul><li><script runat=&quot;server&quot;> </li></ul><ul><li>Public Sub Page_Load(Src as Object, E as EventArgs) </li></ul><ul><li>If (Page.IsPostBack) Then </li></ul><ul><li> lblMessage.Text = txtFirstName.Text & &quot; &quot; & txtLastName.Text </li></ul><ul><li>End If </li></ul><ul><li>End Sub </li></ul><ul><li></script> </li></ul><ul><li><html> </li></ul><ul><li><body bgcolor=&quot;#ffffff&quot;> </li></ul><ul><li><form id=&quot;frmName&quot; runat=&quot;server&quot;> </li></ul><ul><li><b>Please complete the following:</b><p /> </li></ul><ul><li>Your Name: <asp:Label ID=&quot;lblMessage&quot; Runat=&quot;server&quot; /> <p /> </li></ul><ul><li> First Name: <asp:TextBox ID=&quot;txtFirstName&quot; Runat=&quot;server&quot; /> <br /> </li></ul><ul><li> Last Name: <asp:TextBox ID=&quot;txtLastName&quot; Runat=&quot;server&quot; /> <p /> </li></ul><ul><li> <asp:Button ID=&quot;btnSubmit&quot; Text=&quot;Submit!&quot; Runat=&quot;server&quot; /> </li></ul><ul><li></form> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>Called each time a page is loaded
    10. 10. Event Handling in ASP.NET <ul><li>ASP.NET controls expose different events that can be wired up to event handlers. </li></ul>1 2 3 Browser (ShopCart.aspx) Shopping Cart Server (Parse post information) Call appropriate event-handling method btnAddToCart_Click(obj,event) Prod1=Thing:Prod2=Item; Prod3=Gizmo Submit=btnAddToCart3 Add Add Add Thing Item Gizmo
    11. 11. Hooking Up Web Control Events <ul><li>Web server controls expose different events that can be handled in Web Forms. </li></ul><ul><li>The onClick attribute can be added to hook a control’s Click event to an event handler: </li></ul><ul><ul><li><script runat=“server” language=“VB”> </li></ul></ul><ul><ul><li>Public Sub btnSubmit_OnClick(sender as Object, e as EventArgs) </li></ul></ul><ul><ul><li> Response.Write(“You clicked a button!”) </li></ul></ul><ul><ul><li>End Sub </li></ul></ul><ul><ul><li></script> </li></ul></ul><ul><ul><li><asp:Button id=“btnSubmit” onClick=“btnSubmit_OnClick” </li></ul></ul><ul><ul><li> runat=“server” Text=“Click here” /> </li></ul></ul>
    12. 12. Hooking Up Web Control Events: Example 1 <ul><li><%@ Page Language=“VB” %> </li></ul><ul><li><script runat=&quot;server&quot;> </li></ul><ul><li>Public Sub btnSubmit_OnClick(sender as Object, e as EventArgs) </li></ul><ul><li> lblMessage.Text = txtFirstName.Text + &quot; &quot; + txtLastName.Text </li></ul><ul><li>End Sub </li></ul><ul><li></script> </li></ul><ul><li><html> </li></ul><ul><li><body bgcolor=&quot;#ffffff&quot;> </li></ul><ul><li><form id=&quot;frmName&quot; runat=&quot;server&quot;> </li></ul><ul><li><b>Please complete the following:</b><p /> </li></ul><ul><li><b>Your Name:</b> <asp:Label ID=&quot;lblMessage&quot; Runat=&quot;server&quot; /><p /> </li></ul><ul><li> First Name: <asp:TextBox ID=&quot;txtFirstName&quot; Runat=&quot;server&quot; /><br /> </li></ul><ul><li> Last Name: <asp:TextBox ID=&quot;txtLastName&quot; Runat=&quot;server&quot; /><p /> </li></ul><ul><li> <asp:Button ID=&quot;btnSubmit&quot; Text=&quot;Submit!&quot; Runat=&quot;server&quot; </li></ul><ul><li> onClick=&quot;btnSubmit_OnClick&quot; /> </li></ul><ul><li></form> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
    13. 13. <ul><li><%@ Page Language=&quot;VB&quot;%> </li></ul><ul><li><script runat=&quot;server&quot;> </li></ul><ul><li>Public Sub ddStates_IndexChanged(sender as Object,e as EventArgs) </li></ul><ul><li>lblMessage.Text = &quot;You selected &quot; & ddStates.SelectedItem.Text & _ </li></ul><ul><li> &quot; which has a state code of &quot; & ddStates.SelectedItem.Value </li></ul><ul><li>End Sub </li></ul><ul><li></script><html> </li></ul><ul><li><body bgcolor=&quot;#ffffff&quot;> </li></ul><ul><li><form id=&quot;frmName&quot; runat=&quot;server&quot;> </li></ul><ul><li> <b>Select a Western State:</b> </li></ul><ul><li> <asp:DropDownList ID=&quot;ddStates&quot; Runat=&quot;server&quot; </li></ul><ul><li> OnSelectedIndexChanged=&quot;ddStates_IndexChanged“ AutoPostBack=&quot;True&quot; > </li></ul><ul><li><asp:ListItem Value=&quot;&quot; Text=&quot;Select One:&quot; /> </li></ul><ul><li><asp:ListItem Value=&quot;AZ&quot; Text=&quot;Arizona&quot; /> </li></ul><ul><li><asp:ListItem Value=&quot;CA&quot; Text=&quot;California&quot; /> </li></ul><ul><li><asp:ListItem Value=&quot;UT&quot; Text=&quot;Utah&quot; /> </li></ul><ul><li><asp:ListItem Value=&quot;WA&quot; Text=&quot;Washington&quot; /> </li></ul><ul><li> </asp:DropDownList><p /> </li></ul><ul><li><b>Selection:</b> <asp:Label ID=&quot;lblMessage&quot; Runat=&quot;server&quot; /> </li></ul><ul><li></form> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>Hooking Up Web Control Events: Example 2
    14. 14. Introduction to ASP.NET Validation Controls <ul><li>Validation controls allow input submitted through Web Forms to be validated easily. </li></ul><ul><li>When possible, validation will occur on the client side. For older browsers (and even new browsers). validation occurs on the server side. </li></ul><ul><li>Types of validation include: </li></ul><ul><ul><li>Required entry </li></ul></ul><ul><ul><li>Validating specific criteria (value range, etc.) </li></ul></ul><ul><ul><li>Comparing control values (does text1 = text2 ?) </li></ul></ul><ul><ul><li>Range checking </li></ul></ul><ul><ul><li>Pattern matching </li></ul></ul><ul><ul><li>Custom validation </li></ul></ul>
    15. 15. Validation Controls in ASP.NET <ul><li>Validation controls that can be used in ASP.NET Web Forms include: </li></ul><ul><ul><li><asp:RequiredFieldValidator> </li></ul></ul><ul><ul><li><asp:RangeValidator> </li></ul></ul><ul><ul><li><asp:CompareValidator> </li></ul></ul><ul><ul><li><asp:RegularExpressionValidator> </li></ul></ul><ul><ul><li><asp:CustomValidator> </li></ul></ul><ul><ul><li><asp:ValidationSummary> </li></ul></ul>
    16. 16. Validation Controls Example <ul><li><form id=&quot;frmName&quot; runat=&quot;server&quot;> </li></ul><ul><li><b>Please complete the following:</b><p /> </li></ul><ul><li><b>Valid Check:</b> <asp:Label ID=&quot;lblMessage&quot; Runat=&quot;server&quot; /><p /> </li></ul><ul><li> Password: <asp:TextBox ID=&quot;txtPassword&quot; TextMode=&quot;Password&quot; Runat=&quot;server&quot; /> </li></ul><ul><li> <asp:RequiredFieldValidator ID=&quot;vTxtPassword&quot; runat=&quot;server&quot; </li></ul><ul><li>ControlToValidate=&quot;txtPassword&quot; </li></ul><ul><li>ErrorMessage=&quot;Enter your password!&quot; />< br /> </li></ul><ul><li> Re-Type Password: <asp:TextBox ID=&quot;txtPassword2&quot; TextMode=&quot;Password&quot; Runat=&quot;server&quot; /> </li></ul><ul><li> <asp:RequiredFieldValidator ID=&quot;vTxtPassword2&quot; runat=&quot;server&quot; </li></ul><ul><li>ControlToValidate=&quot;txtPassword2&quot; </li></ul><ul><li>ErrorMessage=&quot;Re-Enter your password!&quot; /> </li></ul><ul><li> <asp:CompareValidator ID=&quot;user_pwd_compare_validate&quot; </li></ul><ul><li>Runat=&quot;server&quot; ControlToCompare=&quot;txtPassword&quot; </li></ul><ul><li>ControlToValidate=&quot;txtPassword2&quot; Type=&quot;String&quot; </li></ul><ul><li> ErrorMessage=&quot;Passwords do not match!&quot; /> </li></ul><ul><li> <p /> </li></ul><ul><li> <asp:Button ID=&quot;btnSubmit&quot; Text=&quot;Submit!&quot; Runat=&quot;server&quot; /> </li></ul><ul><li></form> </li></ul>

    ×