Download presentation
Presentation is loading. Please wait.
Published byDarlene Hood Modified over 8 years ago
1
Overview ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the.NET Framework, and when coding ASP.NET applications you have access to classes in the.NET Framework. ASP.NET is part of the.NET Framework, and when coding ASP.NET applications you have access to classes in the.NET Framework. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic, C#, JScript.NET, and J#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic, C#, JScript.NET, and J#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on.
2
Continued…
3
Features ASP.NET includes: A page and controls framework A page and controls framework The ASP.NET compiler The ASP.NET compiler Security infrastructure Security infrastructure State-management facilities State-management facilities Application configuration Application configuration Health monitoring and performance features Health monitoring and performance features Debugging support Debugging support An XML Web services framework An XML Web services framework Extensible hosting environment and application life cycle management Extensible hosting environment and application life cycle management An extensible designer environment An extensible designer environment
4
Stages in Web Form Processing StageDescription Page request The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page. Start In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
5
Continued… Page Initialization During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state. Load During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
6
Continued… Validation During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. Postback event handling If the request is a postback, any event handlers are called. Rendering During rendering, view state is saved to the page and then the page calls on each control to contribute its rendered output to the OutputStream of the page's Response property. Unload Unload is called when the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
7
Server Controls Controls with more built-in features than HTML server controls. Web server controls include not only form controls such as buttons and text boxes, but also special-purpose controls such as a calendar, menus, and a tree view control. Web server controls are more abstract than HTML server controls in that their object model does not necessarily reflect HTML syntax. Controls with more built-in features than HTML server controls. Web server controls include not only form controls such as buttons and text boxes, but also special-purpose controls such as a calendar, menus, and a tree view control. Web server controls are more abstract than HTML server controls in that their object model does not necessarily reflect HTML syntax. Syntax Example: Syntax Example:
8
HTML Controls HTML server controls are HTML elements (or elements in other supported markup, such as XHTML) containing attributes that make them programmable in server code. HTML server controls are HTML elements (or elements in other supported markup, such as XHTML) containing attributes that make them programmable in server code. By default, HTML elements on an ASP.NET Web page are not available to the server. Instead, they are treated as opaque text and passed through to the browser. By default, HTML elements on an ASP.NET Web page are not available to the server. Instead, they are treated as opaque text and passed through to the browser.
9
Validation Controls Controls that incorporate logic to enable you to what users enter for input controls such as the TextBox control. Validation controls enable you to check for a required field, to test against a specific value or pattern of characters, to verify that a value lies within a range, and so on. Controls that incorporate logic to enable you to what users enter for input controls such as the TextBox control. Validation controls enable you to check for a required field, to test against a specific value or pattern of characters, to verify that a value lies within a range, and so on.
10
Data Binding Controls Data-bound Web server controls are controls that can be bound to a data source control to make it easy to display and modify data in your Web application. Data-bound Web server controls are composite controls that combine other ASP.NET Web controls, such as Label and TextBox controls, into a single layout. Data-bound Web server controls are controls that can be bound to a data source control to make it easy to display and modify data in your Web application. Data-bound Web server controls are composite controls that combine other ASP.NET Web controls, such as Label and TextBox controls, into a single layout. For example, a data-bound control such as a DetailsView control can bind to a set of results such as a table of employees containing each employee's name, address, job title, and so on. Within the DetailsView control, you can bind Label controls to a single data values such as the name or address field to create the data layout in the page. For example, a data-bound control such as a DetailsView control can bind to a set of results such as a table of employees containing each employee's name, address, job title, and so on. Within the DetailsView control, you can bind Label controls to a single data values such as the name or address field to create the data layout in the page.
11
Programming with ASP.Net
12
Environment ASP pages are called as WEBFORM and have the extension.aspx ASP pages are called as WEBFORM and have the extension.aspx When an ASP page is created there are two files: When an ASP page is created there are two files: Design File : For graphically placing and adding controls on the page Code behind File : Has two extensions (eg:.aspx.vb). Second one shows source code language name.
13
HTML Controls ControlDescription Web Form Code Example Button A normal button that you can use to respond to Click events Reset Button Resets all other HTML form elements on a form to a default value
14
Continued… Submit Button Automatically POSTs the form data to the specified page listed in the Action= attribute in the FORM tag Text Field Gives the user an input area on an HTML form
15
Continued… Text Area Used for multi-line input on an HTML form File Field Places a text field and a Browse button on a form and allows the user to select a file name from their local machine when the Browse button is clicked
16
Continued… Password Field An input area on an HTML form, although any characters typed into this field are displayed as asterisks Checkbox Gives the user a check box that they can select or clear
17
Continued… Radio Button Used two or more to a form, and allows the user to choose one of the controls Table Allows you to present information in a tabular format
18
Continued… Image Displays an image on an HTML form ListBox Displays a list of items to the user. You can set the size from two or more to specify how many items you wish show. If there are more items than will fit within this limit, a scroll bar is automatically added to this control.
19
Continued… Dropdown Displays a list of items to the user, but only one item at a time will appear. The user can click a down arrow from the side of this control and a list of items will be displayed. Horizontal Rule Displays a horizontal line across the HTML page <hr>
20
Common Client Side Events ControlDescription OnBlur: Control loses focus OnChange: Contents of the control are changed OnClick: Control is clicked on OnFocus: Control receives focus OnMouseOver: Mouse moves over this control
21
Server Controls ControlDescription Commonly Used Server- Side Events Web Form Code Example Label Displays text on the HTML page None Label Label TextBox Gives the user an input area on an HTML form TextChange d Button A normal button control used to respond to click events on the server. You are allowed to pass additional information by setting the CommandName and CommandArguments properties. Click, Command LinkButt on Like a button in that it posts back to a server, but the button looks like a hyperlink Click, Command Link Button Link Button
22
Continued… Hyperlink A normal hyperlink control that responds to a click event None H yperLink H yperLink</asp:HyperLink> DropDownL ist A normal dropdown list control like the HTML control, but can be data bound to a data source SelectedIndex Changed ListBox A normal ListBox control like the HTML control, but can be data bound to a data source SelectedIndex Changed
23
Continued… DataList Allows you to create a non-tabular type of format for data. You can bind the data to template items, which are like bits of HTML put together in a specific repeating format. CancelCommand, EditCommand, DeleteCommand, ItemCommand, SelectedIndexC hanged, UpdateComman d, ItemCreated, ItemDataBound Repeater Allows you to create a non-tabular type of format for data. You can bind the data to template items, which are like bits of HTML put together in a specific repeating format. ItemCommand, ItemCreated, ItemDataBound CheckBox Very similar to the normal HTML control that displays a check box for the user to check or uncheck CheckChanged
24
Continued… ImageButton Can display a graphical image, and when clicked, posts back to the server command information such as the mouse coordinates within the image, when clicked Click DataGrid Like a on steroids. You bind a data source to this control and it displays all of the column information. You can also perform paging, sorting, and formatting very easily with this control. CancelCommand, EditCommand, DeleteCommand, ItemCommand, SelectedIndexCh anged, PageIndexChang ed, SortCommand, UpdateCommand, ItemCreated, ItemDataBound
25
Continued… CheckBoxList Displays a group of check boxes that all work together SelectedIndexChang ed RadioButton Very similar to the normal HTML control that displays a button for the user to check or uncheck CheckChanged RadioButtonList Displays a group of radio button controls that all work together SelectedIndexChang ed
26
Continued… Image Very similar to the normal HTML control that displays an image within the page None Panel Used to group other controls None Pa nel Pa nel PlaceHolder Acts as a location where you can dynamically add other server-side controls at run time None Calendar Creates an HTML version of a calendar. You can set the default date, move forward and backward through the calendar, etc. SelectionChanged, VisibleMonthChan ged, DayRender
27
Continued… AdRotator Allows you to specify a list of ads to display. Each time the user re- displays the page, the display rotates through the series of ads. AdCreated Table Very similar to the normal HTML control None Literal Like a label in that it displays a literal, but allows you to create new literals at runtime and place them into this control None
28
Validation Controls ControlDescription HTML or JavaScript Code Example RequiredFieldValidator Allows you to check a control on the form to see if it is filled in with anything. If it isn't, the ErrorMessage that you set will be displayed in this control. <asp:RequiredFieldValidato r id=RequiredFieldValidator1runat="server"ErrorMessage="RequiredFieldValidator"> CompareValidator Allows you to check the contents of one control against the contents of another control on the form to see if they match. If they don't, the ErrorMessage that you set will be displayed into this control. <asp:CompareValidatorid=CompareValidator1runat="server"ErrorMessage="CompareValidator"></asp:CompareValidato>
29
Continued… RangeValidator Allows you to check to see whether the value you entered in a control is within a specified range. If it isn't, the ErrorMessage that you set will be displayed into this control. <asp:RangeValidatorid=RangeValidator1runat="server"ErrorMessage="RangeValidator"></asp:RangeValidator> RegularExpressionValidat or Allows you to check to see if a control's contents match the input mask (regular expression) you defined. If it doesn't, the ErrorMessage that you set will be displayed into this control. <asp:RegularExpressionVal idator id=RegularExpressionValid ator1 runat="server" ErrorMessage= "RegularExpressionValidat or">
30
Continued… CustomValidator Allows you to specify either a server- side or client-side script function to validate the contents of a particular control. You must return a True or False value from these functions. If a True value is returned, processing continues; if a False value is returned, the ErrorMessage specified for this control is displayed. <asp:CustomValidatorid=CustomValidator1runat="server"ErrorMessage="CustomValidator"></asp:CustomValidator>
31
How To Use Controls Label Label 1)Text : Label1.Text=“value” Button Button 1) Text : Button1.Text=“value” LinkButton LinkButton 1) Text : LinkButton1.Text=“value” 2) PostBackUrl : LinkButton1.PostBackUrl=“webform1.aspx” 3) Event : a) Click() : //write logical code here //write logical code here
32
Continued… ImageButton ImageButton 1) AlternateText : ImageButton1.AlternateText=“value” 2) ImageUrl : ImageButton1.ImageUrl=“image” 3) PostBackUrl : ImageButton1. PostBackUrl=“webform1.aspx”
33
Continued… TextBox TextBox 1) Text : TextBox1.text=“value” 2) TextMode : TextBox1.TextMode=“SingleLine” or “MultiLine” or “PassWord” AutoPostBack : True/False AutoPostBack : True/False Automatically postback to the server after the text is modified.
34
Continued… HyperLink HyperLink 1) NavigateUrl : HyperLink1.NavigateUrl=“webform1.aspx” 2) Target : HyperLink1.Target=“_blank” or “_parent” or “_search” or “_self” or “_top” DropDownList DropDownList 1) Items Collections: It contains the items collection which internally behaves like an array. Example : DropDownList1.Items.Add(“item”)DropDownList1.Clear()DropDownList1.Items.Remove(“item”)DropDownList1.SelectValue=“value”
35
Continued… ListBox ListBox Same as DropDownList control CheckBox CheckBox 1) Text : CheckBox1.Text=“value” 2) ValidationGroup: The group that should be validated when the control causes a postback. CheckBox1.ValidationGroup=“value” Example : Protected Sub CheckBox1_CheckedChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ System.Object, ByVal e As System.EventArgs) Handles _ CheckBox1.CheckedChanged CheckBox1.CheckedChanged Label1.Text = "CheckBox1 selection is: " & _ Label1.Text = "CheckBox1 selection is: " & _ CheckBox1.Checked.ToString() CheckBox1.Checked.ToString() End Sub
36
Continued… CheckBoxList CheckBoxList 1) DataSourceID : CheckBoxList1.DataSourceID=“SqlDataSource1” 2) Items : Collection of items that internally behaves as an array. CheckBoxList1.Items.Add(“item”) CheckBoxList1.Items.Add(“item”) Example : Protected Sub CheckBox1_CheckedChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ System.Object, ByVal e As System.EventArgs) Handles _ CheckBox1.CheckedChanged CheckBox1.CheckedChanged Label1.Text = "CheckBox1 selection is: " & _ Label1.Text = "CheckBox1 selection is: " & _ CheckBox1.Checked.ToString() CheckBox1.Checked.ToString() End Sub
37
Continued… RadioButton and RadioButtonList RadioButton and RadioButtonList Same as CheckBox Example : RadioButtonList1.SelectedValue //Gets the value of the selected item in the list control
38
Continued… Image Image 1) ImageUrl : Image1.ImageUrl=“image” ImageMap ImageMap 1) ImageUrl : ImageMap1.ImageUrl=“image” 2) HotSpotMode : Specifies whether the ImageMap causes postback or navigation behaviour. ImageMap1.HotSpotMode=“Navigate” or “PostBack” or “Inactive” ImageMap1.HotSpotMode=“Navigate” or “PostBack” or “Inactive” 3) HotSpots : The hotspots collection.
39
Continued… Calendar Calendar 1) SelectedDate : The currently selected date. Calendar1.SelectedDate=“value” Calendar1.SelectedDate=“value” 1) SelectionMode : Determines whether days, weeks and months are selectable. Calendar1.SelectionMode=“Day” or “DayWeek” or “DayWeekMonth” Calendar1.SelectionMode=“Day” or “DayWeek” or “DayWeekMonth”
40
Continued… FileUpload FileUpload//code If FileUpload1.HasFile Then FileUpload1.PostedFile.SaveAs _ (Server.MapPath(“~/uploaded file/” _ & FileUpload1.FileName)) EndIf AdRotator AdRotator Add a new XML file and add the following code: <Advertisements><Ad> ~/Picture filename ~/Picture filename Address of a website Address of a website Text to be displayed on mouse hover Text to be displayed on mouse hover Set %age of Repeating Set %age of Repeating </Ad></Advertisements>
41
Continue… MultiView : Drop View control in MultiView. MultiView : Drop View control in MultiView. On Button1 Click() MultiView.ActiveIndex=0 On Button2 Click() MultiView.ActiveIndex=1 On Button3 Click() MultiView.ActiveIndex=2
42
Continue… Panel : Container control for other controls and supports static way of adding controls on a webform. Panel : Container control for other controls and supports static way of adding controls on a webform. PlaceHolder : Container control for other controls and supports dynamic way of adding controls on a webform. PlaceHolder : Container control for other controls and supports dynamic way of adding controls on a webform. PlaceHolder1.Controls.Add(new TextBox)
43
Validation Controls RequiredFieldValidator : Evaluates the value of an input control to ensure that the user enters a value. RequiredFieldValidator : Evaluates the value of an input control to ensure that the user enters a value. RangeValidator : validates that the values of another control fall within an allowable range, where the minimum and maximum are provided either directly or by reference to another control. RangeValidator : validates that the values of another control fall within an allowable range, where the minimum and maximum are provided either directly or by reference to another control. MaximumValue : Maximum Value for the control being validated. MaximumValue : Maximum Value for the control being validated. Minimum Value : Minimum Value for the control being validated. Minimum Value : Minimum Value for the control being validated. CompareValidator : Compares one control to another by using a specified comparison operator. CompareValidator : Compares one control to another by using a specified comparison operator. ControlToCompare : ID of the control to compare with. ControlToCompare : ID of the control to compare with. CustomValidator : Evaluates the value of an input control to determine whether it passes customized validation logic. CustomValidator : Evaluates the value of an input control to determine whether it passes customized validation logic. ClientValidationFunction : Client script validation function. ClientValidationFunction : Client script validation function. ValidationSummary : Displays a list of all validation errors on the Web page. ValidationSummary : Displays a list of all validation errors on the Web page. RegularExpressionValidator : To test whether the data value in a TextBox or SelectionList control matches a regular expression. RegularExpressionValidator : To test whether the data value in a TextBox or SelectionList control matches a regular expression. ValidationExpression : Regular expression to determine validity. ValidationExpression : Regular expression to determine validity.
44
Common Properties ControlToValidate : ID of the control to validate. ControlToValidate : ID of the control to validate. ErrorMessage : Message to display in a ValidationSummary when the validated control is invalid. ErrorMessage : Message to display in a ValidationSummary when the validated control is invalid.
45
Database Controls and Their Use ADO.Net Architecture ADO.Net Architecture
46
Continued… Step 1) Import Namespace as : Imports System.Data.SqlClient Step 2) Create Database in SqlServer Accessing database through VB code: - Create connection object Dim con as SqlConnection = new SqlConnection (“connection string”) Con.Open() - Create Command object Dim com as new SqlCommand = new Sqlcommand (“Select * from student”, con) - Create data reader Dim dr as SqlDataReader
47
Operations on Database Through ASP Page Select query with parameter : Select query with parameter : Dim com as SqlCommand = new SqlCommand (“Select * from stud where name=@name”, con) Com.Parameters.AddWithValue(“@name”, TextBox1.Text)
48
Continued… Insert query with parameters : Insert query with parameters : Dim com as SqlCommand = new SqlCommand (“Insert into stud values (@rno, @name, @class)”, con) Com.Parameters.AddWithValue(“@rno”, TextBox1.Text) Com.Parameters.AddWithValue(“@name”, TextBox2.Text) Com.Parameters.AddWithValue(“@class”, TextBox3.Text)
49
Continued… Update query with parameters : Update query with parameters : Dim com as SqlCommand = new SqlCommand (“Update stud set (rno=@rno, class=@class) where name=@name”, con) Com.Parameters.AddWithValue(“@rno”, TextBox1.Text) Com.Parameters.AddWithValue(“@name”, TextBox2.Text) Com.Parameters.AddWithValue(“@class”, TextBox3.Text)
50
Continued… Delete query with parameters : Delete query with parameters : Dim com as SqlCommand = new SqlCommand (“Delete stud where name=@name”, con) Com.Parameters.AddWithValue(“@name”, TextBox2.Text)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.