Net Framework

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Net Framework as PDF for free.

More details

  • Words: 4,217
  • Pages: 15
.NET Framework It is a language-neutral environment for developing and building applications that can easily and securely operate within it. The components that make up the .NET platform are collectively called the .NET Framework. The .NET Framework is designed for cross language compatibility. Cross-language compatibility means, an application written in Visual Basic .NET may reference a DLL file written in C# (C-Sharp). A Visual Basic .NET class might be derived from a C# class or vice versa.

.NET Framework Advantages The .NET Framework offers a number of advantages to developers. The following paragraphs describe them in detail. Consistent Programming Model The functionality that the .NET Class Library provides is available to all .NET languages resulting in a consistent object model regardless of the programming language the developer uses. Simplified Development Efforts Let's take a look at Web applications. With classic ASP developer was required to mix the ASP code with the HTML code to get the desired result. ASP.NET and the .NET Framework simplify development by separating the application logic and presentation logic in different file. Easy Application Deployment and Maintenance The .NET Framework makes it easy to deploy applications. In the most common form, to install an application, all we need to copy the application along with the components it requires into a directory on the target computer. The .NET Framework handles the details of locating and loading the components an application needs, even if several versions of the same application exist on the target computer.

Architecture Of .Net Framework .Net framework has two tier architecture for running an application ,as follows The .NET Framework consists of two main components: Common Language Runtime (CLR) Class Libraries

Common Language Specification (CLS)

If we want the code which we write in a language to be used by programs in other languages then it should adhere to the Common Language Specification (CLS). The CLS describes a set of features that different languages have in common. The CLS defines the minimum standards that .NET language compilers must conform to, and ensures that any source code compiled by a .NET compiler can interoperate with the .NET Framework.

Namespaces A namespace is a collection of different classes. All .Net applications are developed using classes from the .NET System namespace. The namespace with all the built-in VB functionality is the System namespace. All other namespaces are based on this System namespace. ` Some Namespaces and their use: System: Includes essential classes and base classes for commonly used data types, events, exceptions and so on System.Collections: Includes classes and interfaces that define various collection of objects such as list, queues, hash tables, arrays, etc System.Data: Includes classes which lets us handle data from data sources System.Data.OleDb: Includes classes that support the OLEDB .NET provider System.Data.SqlClient: Includes classes that support the SQL Server .NET provider System.Diagnostics: Includes classes that allow to debug our application and to step through our code System.Drawing: Provides access to drawing methods System.Globalization: Includes classes that specify culture-related information System.IO: Includes classes for data access with Files System.Net: Provides interface to protocols used on the internet System.Reflection: Includes classes and interfaces that return information about types, methods and fields System.Security: Includes classes to support the structure of common language runtime security system System.Threading

: Includes classes and interfaces to support multithreaded applications System.Web: Includes classes and interfaces that support browser-server communication System.Web.Services: Includes classes that let us build and use Web Services System.Windows.Forms: Includes classes for creating Windows based forms System.XML: Includes classes for XML support

ASP.NET ASP.NET, the next version of ASP, is a programming framework used to create Web Applications. These applications are accessible over a network(internet). The advantages ASP.NET offers more than just the next version of ASP.

Why ASP.NET? Since 1995, Microsoft shift it's focus from Windows-based platforms to the Internet. As a result, Microsoft introduced ASP (Active Server Pages) in November 1996. But ASP Script was an interpreted script and contain unstructured code and was difficult to debug and maintain. As the web consists of many different technologies, software integration for Web development was complicated and required to understand many different technologies. Also, as applications grew bigger in size and became more complex, the number of lines of source code in ASP applications increased dramatically and was hard to maintain. Therefore, an architecture was needed that would allow development of Web applications in a structured and consistent way. The .NET Framework was introduced with a vision to create globally distributed software with Internet functionality and interoperability. The .NET Framework consists of many class libraries, includes multiple language support and a common execution platform. It's a very flexible foundation on which many different types of top class applications can be developed that do different things. Developing Internet applications with the .NET Framework is very easy. ASP.NET is built into this framework, we can create ASP.NET applications using any of the built-in languages. Unlike ASP, ASP.NET uses the Common Language Runtime (CLR) provided by the .NET Framework. This CLR manages execution of the code we write. ASP.NET code is a compiled CLR code instead of interpreted code (ASP). CLR also allows objects written in different languages to interact with each other. The CLR makes developement of Web applications simple.

Advantages Using ASP.NET ○ ASP.NET drastically reduces the amount of code required to build large applications ○ ASP.NET makes development simpler and easier to maintain with an event-driven, server-side programming model ○ ASP.NET pages are easy to write and maintain because the programming code and HTML are separated in different files.

○ The programming code is executed on the server. The pages have lots of power and flexibility by this approach ○ The programming code is compiled the first time the page is requested. Execution is fast as the web server compiles the page the first time it is requested. The server saves the compiled version of the page for use next time the page is requested ○ The HTML produced by the ASP.NET page is sent back to the browser. The application programming code you write is not sent and is not easily stolen ○ ASP.NET makes for easy deployment. There is no need to register components because the configuration information is built-in ○ ASP.NET validates information (validation controls) entered by the user without writing a single line of code ○ ASP.NET easily works with ADO .NET using data binding and page formatting features ○ ASP.NET applications run fsater and counters large volumes of users without performance problems

Web Server Web pages must be stored and organized in a central computer.Computer which store web pages in form of directories and files and provide these files to be read, are called “Server”. They act like a service providers that service the need for information. The server computer must runs special software called Web Server software that allow Web site Management. (1) Accept a client request for information. (2) Respond to client’s request by providing the page with the required information. Some of the most popular software which server run to allow them to respond to client request for information , are Internet Information Server, Apache Web Server , Netscape Server, Microsoft Personal Web Server.

IIS To develop a Web Application you need IIS (Internet Information Server) on your machine. IIS comes with Operating Systems like Windows 2000, XP and 2003. You need to configure IIS to run ASP.NET Web applications. You should configure IIS prior to the installation of Visual Studio .NET software on your machine to avoid errors. In most cases configuring IIS after the installation of VS .NET will result in many errors and unexpected behaviour by the application. By default, IIS creates a folder on the server's hard disk with the name Inetpub. The Inetpub folder contains a subfolder called wwwroot. The wwwroot folder is the root for the web site. All the ASP.NET applications you develop using VS .NET are saved in this wwwroot folder. ASP .Net Web controls are divided into five different groups. a. Basic Web Controls - Button, Checkboxes, CheckBoxList, DropDownList etc. b. Validation Web Controls - CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, Validation Summary

c. Data Controls - DataGrid , DataList, Repeater, d. Rich Web Controls e. Mobile Controls Benefits of Asp.Net Controls:

The folllowing are the benefits of Asp.net control.

1. An Intuitive Object Model 2. View State : The Difference b/w the simple HTML control and Asp.Net Control is that the Asp.Net control retains the values that are put into it after the post to the server.

HTML Server Controls HTML server controls are HTML tags understood by the server. HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time. Note: All HTML server controls must be within a
tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts. (2) Client/HTML Control : HTML control donot run on the server bydefault; they only do so if we right click the control and select the Run As A Server Control menu item. By default they handeled in the browser there is a advantage to operating this way if we handle an event in the client (browser) instead of web server , the whole page does not have to make the round trip to the server, which saves a lot of time. Net refers to control handeled this way as a html client control. Because they run in the browser , we have to program them with a language the browser understand such as javascript. All the html form controls are the standard control in the ASP.net for example:

Web Forms Working with Web Forms is similar to working with Windows Forms. But the difference is that web form will be accessible by a Web browser. Web Forms are Web pages that serve as the user interface for a Web application. A Web Forms page presents information to the user in any browser or client device and implements application logic using server-side code. Web Forms are based on the System.Web.Ui Page class.

Components of Web Forms In Web Forms pages, the programming is divided into two parts: the visual component (design page) and the logic (code behind page). The Web Forms page visual component works as a container for the static text and the controls we want to display. Using the Visual Studio Web Forms Designer and ASP.NET server controls, we can design the form just like in any Visual Studio application.

The logic for the Web Forms page consists of code that we create to interact with the form. The programming logic is in a separate file from the user interface file. This file is the "code-behind" file and has an ".aspx.vb" (VB) or ".aspx.cs" (C-Sharp) extension. The logic we write in the code-behind file can be written in Visual Basic or Visual C#. The code-behind class files for all Web Forms pages in a project are compiled into the project dynamic-link library (.dll) file. The .aspx page file is also compiled, but differently. The first time a user loads the aspx page, ASP.NET automatically generates a .NET class file that represents the page, and compiles it to a second .dll file. The generated class for the aspx page inherits from the code-behind class that was compiled into the project .dll file. When the user requests the Web page URL, the .dll files run on the server and dynamically produces the HTML output for your page. When you open a new ASP.NET Web Application in Visual Studio .NET the form that is loaded (WebForm1.aspx) looks like the image below.

The form opens in design mode and we can switch to source view by clicking on the source tab. default.aspx file in the image above is standard HTML with ASP elements embedded in it. The file looks like the image below.

Stages in Web Forms Processing Page Initialization:--- The page's Page_Init event is raised, and the page and control view state are restored. During this event, the ASP.NET page framework restores the control properties and postback data User Code Initialization:--- The page's Page_Load event is raised. Read and restore values stored previously, Using the Page.IsPostBack property, check whether this is the first time the page is being processed. If this is the first time the page is being processed then perform initial data binding. Otherwise, restore control values. Read and update control properties. Validation:-- The Validate method of any validator Web server controls is invoked to perform the control's specified validation. Test the outcome of validation in an event handler Event Handling:-- If the page was called in response to a form event, the corresponding event handler in the page is called during this stage. Perform application-specific processing and handle the specific event raised. Cleanup:-- The Page_Unload event is called because the page has finished rendering and is ready to be discarded. Perform final cleanup work. Close files, closing database connections and discard objects.

Label The Label web server control is used to label other parts of the application. They are used to display text which the user can't change. To display text on a label we use the text property. A label control with Border Style property as solid and Border Color property as blue is shown below. I am Label

Properties

ID---Programmatic name of the control. Accesskey----Keyboard shrot cut used by the control. BackColor----Set the backgrouhnd color of the control. BorderColor----Set the color of the border around control. BorderStyle-----Set the style of the border around control. BorderWidth-------Set the width of the border around control Enabled------------Enabled The state of the control. Enable Theming----Indicate whether control can be themed. EnableViewState-----Whether the control automatically saves its state for use in round trip. Font-----Font used for text within control. ForeColor-------Color of text within control Height-----The height of control TabIndex----The tab order of the control. Text-----The text to be show for the label. ToolTip--------The tooltip is displayed when the mouse is over the control. Visible---Indicate whether the control is visible or rendered. Width----The Width of the control. Name Description DataBinding Occurs when the server control binds to a data source. (Inherited from Control.) Disposed

Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested. (Inherited from Control.)

Init

Occurs when the server control is initialized, which is the first step in its lifecycle. (Inherited from Control.)

Load

Occurs when the server control is loaded into the Page object. (Inherited from Control.)

PreRender

Occurs after the Control object is loaded but prior to rendering. (Inherited from Control.)

Unload

Occurs when the server control is unloaded from memory. (Inherited from Control

TextBox The TextBox Web Server Control used to accept input from the user. They appear like a box and allows the user to enter some text, like, username, password, etc. Below is a ReadOnly TextBox with BackColor property set to Silver, BorderColor property set to Brown and BorderStyle property set to solid. I am a TextBo

Properties ID---Programmatic name of the control.

Accesskey----Keyboard shrot cut used by the control. BackColor----Set the backgrouhnd color of the control. BorderColor----Set the color of the border around control. BorderStyle-----Set the style of the border around control. BorderWidth-------Set the width of the border around control Enabled------------Enabled The state of the control. Enable Theming----Indicate whether control can be themed. EnableViewState-----Whether the control automatically saves its state for use in round trip. Font-----Font used for text within control. ForeColor-------Color of text within control Height-----The height of control TabIndex----The tab order of the control. Text-----The text to be show for the label. ToolTip--------The tooltip is displayed when the mouse is over the control. Visible---Indicate whether the control is visible or rendered. Width----The Width of the control. AutoPostBack :--- Gets/Sets whether events will be automatically posted to the server Column : ---Gets/Sets the textbox's width in columns MaxLenght :--Gets/Sets the maximum number of characters that can be displayed in the textbox ReadOnly :--ether the textbox is readonly Rows:---s a multiline textbox's display height Text :---the text in a textbox TextMode :---ther a textbox should be single line, multiline or a password control Wrap :--s whether text wraps in a textbox

Events TextChanged:--

Occurs when the user changes the text of a TextBox.

Code Examples Sample 1 Drag a TextBox and a Button control onto the WebForm. When you click the button some text is displayed in a TextBox. The code for that looks like this: Protected Sub Button1_Click(ByVal sender As System.Object,_ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "Welcome to TextBoxes" End Sub Sample2 Multiline TextBox Drag a TextBox, Button and a Label control onto the form. We will make this TextBox a Multiline textbox and display the text entered in this multiline textbox on a label. Before

you proceed, select the textbox, open it's properties window and set it's Textmode property to Multiline. The code to achieve the desired functionality looks like this: Protected Sub Button2_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles Button2.Click Label2.Text = TextBox2.Text End Sub Sample3 Password Character Drag a Textbox, Button and a Label control onto the form. Select the textbox, open it's properties window and set the TextMode property to Password. When you set TextMode property to password, the text you enter in the textbox is masked with asteriks (*). The following code displays the text you entered in the textbox as text for the label. Protected Sub Button3_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles Button3.Click Label3.Text = TextBox3.Text End Sub

Buttons A Button Web Sever control is a control which we click and release to perform some action. Button Event The default event of the Button is the Click event which looks like this in code: Protected Sub Button1_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles Button1.Click 'Implementation Omitted

End Sub Command:--Occurs when the Button control is clicked.

Properties ID---Programmatic name of the control. Accesskey----Keyboard shrot cut used by the control. BackColor----Set the backgrouhnd color of the control. BorderColor----Set the color of the border around control. BorderStyle-----Set the style of the border around control. BorderWidth-------Set the width of the border around control Enabled------------Enabled The state of the control. Enable Theming----Indicate whether control can be themed. EnableViewState-----Whether the control automatically saves its state for use in round trip.

Font-----Font used for text within control. ForeColor-------Color of text within control Height-----The height of control TabIndex----The tab order of the control. Text-----The text to be show for the label. ToolTip--------The tooltip is displayed when the mouse is over the control. Visible---Indicate whether the control is visible or rendered. Width----The Width of the control. Text : Gets/Sets the text in a textbox Cause Validation: Gets/Sets the button that causes validation CommandArgument :--Gets/Sets the command argument which is passed to the command event handler CommandName: Gets/Sets the command name which is passed to the command event handler Sample Code1 Drag a Button onto the form from the toolbox and set it's text as ClickMe. When you click the button it changes it's text from ClickMe to "You clicked Me". The code for that looks like this: Protected Sub Button1_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles Button1.Click Button1.Text = "You clicked me" End Sub

Command Button To create a command button we need to add a command name to the button. We add a command name to the button with the CommandName property and a command argument with the CommandArgument property. Both these properties can hold text which can be recovered in code. Sample code to create a Command Button Drag two TextBoxes and Buttons from the toolbox. Select Button one and in it's properties window set the CommandName property to Command1 and CommandArgument property to I am Command one. Repeat the same for Button two. When you click Button1, the CommandName of Button1 will be displayed in TextBox1 and CommandArgument of Button2 in TextBox2. To get those values we need to use the command event for the button and not the click event. The code for that looks like this: Private Sub Button1_Command(ByVal sender As System.Object,_ ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles Button1.Command TextBox1.Text = e.CommandName End Sub Private Sub Button2_Command(ByVal sender As System.Object,_ ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles Button2.Command TextBox2.Text = e.CommandArgument

End Sub

List Control The toolbox contains a number of control that present themselves as lists in the browser. These control include ListBox , DropDownList,CheckBoxList, RadioButtonList, and BulletedList. To add items to the list , we define elements between the opening and closing tags of the control , as shown in the following example. C# Visual Basic CSS
To see currently active and selected item of a list control programmatically , we can look at its selectedvalue , seleteditem or selectedindex properties. Selectedvalue property return the string that contains the value for the selected item , like C# or visual Basic in the example. SelectedIndex return the zero based index of the item in the list.With example above if the user has choosen CSS the index would be 2. The BulletedList control does not allow a user to make selections , and as such does not support these properties. For control that support multiple selection (like CheckBoxList , and ListBox) , we can loop through the Items collection and see what items are seleted. In this case , seletedItem returns only the first seleted item in the list ; not all of them.

Properties ID---Programmatic name of the control. Accesskey----Keyboard shrot cut used by the control. BackColor----Set the backgrouhnd color of the control. BorderColor----Set the color of the border around control. BorderStyle-----Set the style of the border around control. BorderWidth-------Set the width of the border around control Enabled------------Enabled The state of the control. Enable Theming----Indicate whether control can be themed. EnableViewState-----Whether the control automatically saves its state for use in round trip. Font-----Font used for text within control. ForeColor-------Color of text within control Height-----The height of control TabIndex----The tab order of the control. Text-----The text to be show for the label. ToolTip--------The tooltip is displayed when the mouse is over the control. Visible---Indicate whether the control is visible or rendered. Width----The Width of the control. Text : Gets/Sets the text in a textbox

Events SelectedIndexChanged Occurs when the selection from the list control changes between posts to the server. (Inherited from ListControl.) TextChanged

Occurs when the Text and SelectedValue properties change. (Inherited from ListControl.)

Program 1:----- To get The Selected Item In the ListBox And Display them in label. Method 1.1 Dim item As ListItem For Each item In ListBox1.Items If item.Selected = True Then Label1.Text = Label1.Text & item.Value End If Next Method 1.2 Dim i As Integer For i = 0 To listbox1.items.count - 1 If listbox1.items(i).selected = True Then

label1.text = label1.text & listbox1.items(i) End If Next Program 2:--------- Program To Transffer All Item Of A List Box In Other ListBox Dim i As Integer For i = 0 To ListBox1.Items.Count - 1 ListBox2.Items.Add(ListBox1.Items(i)) Next Program 3:-------Program to Transffer Only selected item of a listbox to other Listbox Dim item As ListItem For Each item In ListBox1.Items If item.Selected = True Then ListBox2.Items.Add(item.Value) End If Next

RadioButton The control is a method for user input that presents clickable choices. A RadioButton control creates a single radio button. Multiple buttons can be grouped together for a mutually exclusive choice from the group. A typical group of radio buttons is shown below. Clicking the "Select" button reports the choice made. Choose a button: Button 1 Button 2 Button 3

The RadioButton web server control is similar to CheckBox but RadioButtons are displayed as rounded instead of box.

Radiobutton Event The default event of the RadioButton is the CheckedChanged event which looks like this in code: Protected Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

'Implementation Omitted End Sub

Properties Notable property of the RadioButton control is the Group Name property which sets the radio button's group. The radio button will act in concert with the other members of the group. ID---Programmatic name of the control. Accesskey----Keyboard shrot cut used by the control. AutoPostBack-----Automatically post back to the server when the control is clicked. BackColor----Set the backgrouhnd color of the control. BorderColor----Set the color of the border around control. BorderStyle-----Set the style of the border around control. BorderWidth-------Set the width of the border around control Checked------- A Boolean value that specifies whether the radio button is checked or not Enabled------------Enabled The state of the control. Enable Theming----Indicate whether control can be themed. EnableViewState-----Whether the control automatically saves its state for use in round trip. Font-----Font used for text within control. ForeColor-------Color of text within control Height-----The height of control TabIndex----The tab order of the control. Text-----The text to be show for the label. ToolTip--------The tooltip is displayed when the mouse is over the control. TextAlign-------The alignment of the textlabel with respect to each item Visible---Indicate whether the control is visible or rendered. Width----The Width of the control. Text: Gets/Sets the text in a textbox

Related Documents

Net Framework
December 2019 46
Net Framework
May 2020 15
Net Framework
June 2020 17
Dot Net Framework
April 2020 11
Dot Net Framework
August 2019 29