ASP.net
ASP.NET A revolution in the web programming world
Covers Concepts Programs
Authored by B.KANNA BABU
1
ASP.net
Acknowledgements I want to acknowledge my deep gratitude to Mr.T.S.S.sunil Kumar and Mr.G.Sudhakar who encouraged me a lot for their cooperation Iam also thankful to Mr.Ganesh, Mr.satyanarayna Mr.Thandava Krishna, Mr.Manik basava, Mr. Joji babu who has provided staunch support throughout the project and helped me to complete this book successfully Some errors may have inadvertently crept in this book. despite my best efforts to keep them out. Readers are therefore encouraged to point out these errors so that they are not repeated in the next edition.suggesitions to improve the book are also welcome.mail me at
[email protected]
2
ASP.net
About the Author
Mr.B.kanna Babu has been associated with teaching Microsoft Technologies As a corporate trainer for a couple of organizations. he worked at various colleges as professor and he has participated in many technical paper presentations
3
ASP.net
CONTENTS 1. Introduction To MS.net 1.1 1.2 1.3 1.4
Microsoft Development technology Versions Of Ms.net Features according to versions of .net MS.net Framework 1.4.1 MS.net framework 1.4.2 Microsoft Products 1.4.3 MS.net Services 1.4.4 MS.net Servers 1.4.5 MS.net Tools 1.4.6 MS.net Languages 1.4.7 MS.net Technologies
1.5 MS.net Architecture 1.5.1 Application layer 1.5.2 Base class Layer 1.5.3 Translating layer 1.6 Intermediate Language 1.6.1Metadata 1.6.2 Code 1.6.3 Resource 1.6.4 Manifest 1.7 Common Language runtime 1.7.1 IL Loader 1.7.2 Access Controller 1.7.2.1 CTS 1.7.2.2 CLS 1.7.2.3 CAS 1.7.2.4 RBS
4
ASP.net 1.7.2.5 Memory Management 1.7.2.6 Just In Time Compiler 1.7.2.6.1 Pre JIT 1.7.2.6.2 Standard JIT 1.7.2.6.3 Echno JIT
3 4
5
6
2. Hyper Text Markup Language 2.1 Features Of HTML 2.2 Tag References 2.2.1 Basic Tag 2.2.2 Link Tag 2.2.3 Text Formatting Tag 2.2.4 List Tags 2.2.5 Multimedia Tag 2.2.6 Font Tag 2.2.7 Frame Tag I. Form Tag 2.3 Button controls Scripting Languages 3.1 Different Types of Scripting languages 3.2 Features Of scripting Languages JavaScript 4.1 Variables in JavaScript 4.2 Functions in Javascript 4.3 Working with JavaScript 4.4 JavaScript Object hierarchy 4.5 Objects in JavaScript Dynamic Hypertext Markup Language 5.1 Cascading style sheets 5.1.1 Types Of CSS 5.1.1.1 Inline style sheet 5.1.1.2 Embedded style sheet 5.1.1.2.1 tag as selector 5.1.1.2.2 class as selector 5.1.1.2.3 ID as selector 5.1.1.3 External style sheet 5.1.1.4 Imported style sheet ASP.NET 6.1 Why ASP.net 6.2 Evolution of ASP.net 6.3 Features of ASP.net 6.4 Difference between ASP and ASP.net 5
ASP.net 7 Internet information service(IIS) 8 Working with ASP.net Applications 8.1 Why ASP.net 8.2 Evolution of ASP.net 8.3 Features of ASP.net 8.4 Difference between ASP and ASP.net 9 Coding Techniques in ASP.net 9.1 Code inline model 9.2 Code behind model 10 Controls in ASP.net 10.1 client side controls 10.2 silverside controls 10.2.1 HTML server controls 10.2.2 Web server controls 10.2.3 Common properties with webserver controls 10.3 Different Types of controls in ASP.net 10.3.1 Standard controls and examples 10.3.1.1 Label 10.3.1.2 TextBox with Example 10.3.1.3 CheckBox with Example 10.3.2 Redirecting The user Request 10.3.2.1 Hyperlink Button with Example 10.3.2.2 Link Button with Example 10.3.2.3 Image Button with Example 10.3.2.4 Differences b/n button controls 10.3.2.5 Response. Redirect 10.3.2.6 Server. Transfer 10.3.3 Button controls 10.3.3.1 Events with Button Controls 10.3.3.2 Click Event with Example 10.3.3.3 Command Event with Example 10.3.4 Listing Controls 10.3.4.1 ListBox 10.3.4.2 DropDownList 10.3.4.3 RadioButtonList 10.3.4.4 CheckBoxList 10.3.4.5 Panel control 11 Validation Controls 11.1 Difference b/n client side and server side validation 11.2 Different Types of validation controls 11.2.1 Required Field validator with Example 11.2.2 Range validator with Example 11.2.3 Regular Expression Validator with Example 11.2.4 Compare validator with Example 6
ASP.net 11.2.5 Validation Summary with Example 11.2.6 Custom validator with Example 12 Navigation Controls 12.1 Menu Controls with Example 12.2 Treeview Controls with Example 13 Calendar control with example 14 ADO.net 14.1 introduction to ADO.net 14.1.1 I-layered approach 14.1.2 II-layered approach 14.1.3 III-layered approach 14.2 ADO vs ADO.net 14.3 ADO.net architecture diagram 14.4 Connection oriented architecture 14.4.1 Data Providers in ADO.net 14.4.2 Objects in ADO.net 14.4.3 Steps to work with connection architecture 14.4.4 Example with Connection object 14.4.5 Command object 14.4.6 Steps to work with command object 14.4.7 Differences between Execute methods 14.4.8 Example with command object to delete . 14.4.9 Example with insert, update and delete 14.4.10 disadvantages with connection oriented. 14.5 Disconnected Architecture 14.5.1 Disconnected Data cycle 14.5.2 Dataset 14.5.2.1 Steps to work with Dataset 14.6 Data Bound Controls 14.6.1 Templates 14.6.2 Types Of Data Bound Controls 14.6.2.1 Repeater Control 14.6.2.2 Data list Control 14.6.2.3 Grid view Control 14.7 Repeater Control 14.7.1 Designing Repeater Control in Table 14.8 Data List Control 14.8.1 Events associated with Data List Control 14.8.2 Displaying Data in Datalist Control 14.8.3 Deleting with Data List Control 14.8.4 Editing with Data List Control 14.9 Grid View Controls 14.9.1 Displaying Data in GridView 14.9.2 Paging with GridView 14.9.3 Check Boxes with Grid View 14.9.4 Radio Buttons with Gridview 7
ASP.net
15 16 17 18 19
20
Ad Rotator Control CSS in ASP.net Themes and Skins Master Pages State Management in ASP.net 15.1 View state 15.2 URL encoding 15.3 Cookies 15.4 Sessions 15.5 Application 15.6 Caching 15.7 Query String 500 Frequently asked questions
MICROSOFT.NET 8
ASP.net
It is a collection of languages, technologies, frameworks, tools, libraries etc… Integrated one environment which enables to communicate device to device or application to application. It provides one environment for developing different applications rapidly and efficiently. MICROSOFT DEVELOPMENT TECHNOLOGY • OLE TECHNOLOGY: it is used for multiple application access by creating link between the application • •
COM TECHNOLOGY: it is used to create the communication between the modules MS.NET: later they upgraded these technologies in new environment called as MS.NET
VERSIONS OF .NET: MS.NET MS.NET MS.NET MS.NET MS.NET MS.NET MS.NET
1.0:-introduced 1.0:-introduced 1.1:-introduced 2.0:-introduced 2.0:-introduced 3.0 3.5
in in in in in
the the the the the
year year year year year
2000 2002 2003 2004 2005
(beta) (alpha) (alpha) (beta ) (alpha)
Note: Microsoft has given a statement that some new frameworks are Released under winfx named later renamed as Microsoft.net3.0 Features according to versions of .net: MS.net1.0 many application support Separate installation Crystal report installation Mobile application MS.net1.1 Crystal report and Mobile application are inbuilt MS.net2.0
64-bit compatibility Along SQLserver Enterprise edition Generic Classes,Generic methods, nullable types etc…
9
ASP.net
MICROSOFT.NET
.NET FRAMEWORK It is the layer between Application and OS It consists of 1. CLR 2. BCL
.NET Services .NET PRODUCTS Passport service MSVisual studio editor • • Calendar service MS Simulator • Contact Service • Alert Service • Web service Etc….
.NET Servers • MSSQL Server • BizTalk server • IIS • Mobile IIS • Exchange server • Internet Security Server Etc……..
Tools:compiler Interpreter Debugger Assembler and disassembler
1).NET FRAMEWORK: it protects the OS and enables the application execution CLR: it is the runtime environment used to execute all the .net applications. It applies security, memory management and monitors the execution of the program. Base Class Libraries: it provides some predefined functionality which can be reused for developing the application in .net environment. Nearly 4000 predefined Classes are provided for developing the applications 2) MICROSOFT PRODUCTS: MS has provided its products for faster development Of applications and testing of the applications a. MS VISUAL STUDIO EDITOR b. POCKET PC SIMULATOR
10
ASP.net
MS VISUAL STUDIO EDITOR: it is an integrated development environment for developing different types of applications i.e. execution, debugging, designing etc POCKET PC SIMULATOR: it is a special type of environment used for testing mobiles and smart pc applications 3) .NET SERVICES: a service is a back roundly running program which is used for automatic the process Ex: passport, alert, contact, address, web service, calendar etc….. 4) .NET SERVERS: MS has provided nearly 14 servers support like a). IIS :which acts as the webserver for ASP.net web application b).MOBILE IIS: which acts as a webserver for mobile application c).MS SQLSERVER:it acts as a database for storing information permanently d).ISS: Internet security server it is used for applying security for ASP.net applications e).BISTALK SERVER: it is used to store the information in XML format f).EXCHANGE SERVER: it is used for exchanging mails g).ECOMMERCE: it is used for online banking etc…. 5).NET TOOLS: it is used for compiling and executing or checking the structure of files by using built-in tools like Compilers,interpreters,debuggers,assemblers,disassemblers etc… 6).NET LANGUAGES: it supports different types of languages to group all the programmers in the world and works under one platform called MS.NET .NET1.0 supports 17 languages .NET1.1 supports 21 languages .NET2.0 supports 32 languages Ex: MICROSOFT LANGUAGES VB.NET C#.NET VISUAL C++.NET VISUALJ#.NET THIRD PARTY LANGUAGES COBOL.NET PASCAL.NET EFFIEL.NET MANAGED C++.NET JSCRIPT.NET PERL.NET PYTHON.NET etc…. 7).NET TECHNOLOGIES: a technology is the convergence of more than one language for developing different applications Ex: ASP.NET is used for web applications 11
ASP.net ADO.NET is used for database handling WEBSERVICES are used for complete distributed applications ARCHITECTURE OF MS.net
C#.net Application layer
Windows applicat
Web applicat
Data Base class layer
Vb.net Mobile web applicat
IO XML
Memory management
ARCHITECTURE OF MS.NET
Service applicat
Security Threading
CLR Security checking
Translating layer
J#.net
Monitoring The Life cycle
OS
APPLICATION LAYER: This layer is used for presenting the application by developing the front ends. This layer provides some collection of languages and application from which we can choose and develop the application BASECLASSLIBRARIES: This layer provides some predefined functionalities which are used by application layer for developing the application TRANSLATING LAYER: This layer is used to convert your application to OS understandable language by managing the memory, checking the security and monitoring the program
12
ASP.net LIFE CYCLE EXECUTION OF .NET APPLICATION .net application----compilation----IL---CLR---OS
IL (intermediate language): it is the compiled format of any .net program which is OS independent. It can be called as MSIL, CIL, and assembly IL format is of two types .dll format: it is reusable format it is not executable format .exe format: it is executable format it is not reusable ILARCHETECTURE:it consists of 4 parts and 1 wrapper to describe itself
METADATA CODE PE WRAPPER
RESOURCE MANIFEST
METADATA: it is used to describe the data of the IL file i.e. it provides the structure of the program like class names, method names etc… CODE: it provides the actual instructions of IL file RESOURCE: it provides the additional information like images, cursors, icons et MANIFEST: it provides documentary information like product name, company name, and version no, strong name etc…. PE WRAPPER: it contains some executable format which invokes the CLR. Note: if you want to view the complete IL file then ILDASM.exe
13
ASP.net
ILDASM.exe: it is a build-in tool of .net used to show the wrapper file or IL file
CLR ILLOADER ACCESS CONTROLER CTS CAS
CLS RBS
MEMORY MANAGEMENT
JIT COMPILER
• • • • •
CLR is common language runtime It is a runtime environment used to convert IL file to native OS understandable format and also provides some services like memory management, type checking, monitoring the lifecycle of the program etc… It is the heart and soul of .net frame work used to perform every operation in .net It consists of IL loader Access controllers Memory management Jit compiler
•
IL LOADER: it is used to load the complete IL file in to the clr.
• •
Access Controller: it is used to check the security privileges of IL file Different types of access controllers are
• •
•
14
ASP.net
1. CTS:common type system :it provides common data types for all .net languages and checks whether IL file is using those data types are not 2. CLS:common language specification: it provides some common rules for all .net languages and check whether IL file is following those rules are not 3. CAS:code access security: it checks whether the code is executing on the O.S and if it is invalid code it displays error message 4. RBS: role based security: it checks whether the login user is valid or invalid and it provides permissions for accessing and executing .net applications.
by
default
administrator
have
the
privileges
for
accessing .net applications •
Memory management: it look after the memory allocation and memory Deal location .it uses GIGO process for memory management. Note: Managed applications: the applications whose memory management will look after by runtime environment i.e. by CLR Without any user interface is called managed application.
JIT compiler: it is used for converting IL code in to native machine understandable format by compiling it Types of compilers: •
PreJIT: it is used to convert the complete IL code into native machine understandable format
•
Standard JIT: it is used to convert only the called method to machine understandable format use it and remove it from the memory
•
Echno JIT:
it is used to convert
the called method to
machine
understandable format use it and maintain the copy in the temporary location for the next request
HYPER TEXT MARK UP LANGUAGE (HTML)
15
ASP.net
Web applications Dev WebPages
Static webpage
Dynamic webpage
HTML PHOTOSHOP
client side DHTML
FLASH
Server side ASP ASP.NET ISP SERVELETS
• • •
Static webpage: a webpage whose output is static with diff request is called as static webpage which can be generated by using HTML,PHOTOSHOP,FLASH. Dynamic webpage: a webpage which provides different outputs for diff clients request is called dynamic webpage. Client side dynamic webpage: a webpage whose o/p changes with every request to provide new look and animated affects which can be generated by DHTML concepts
16
ASP.net •
Server side dynamic webpage: the webpage which generates diff o/p by processing every request on server machine which can be generated by some technologies like ASP, ASP.NET, JSP, SERVELETS etc….
HTML: Hyper text markup language It is used for dev static WebPages and it is one of the markup language Markup language: a language which is used for concentrating on the structure and formatting of the document to display. SML: specific markup language: a markup language which is specific for an application or OS which is not compatible with other application or OS •
Ex:RTF,HTML
•
GML:Generalised markup language: it is used to provide generalized
format which can be understand by any device or os Ex:XML
• •
Features of HTML:
•
It is free form language (case insensitive language)
•
It is space insensitive language
•
It is line insensitive language
•
It is error free language
•
It is tag oriented language
•
Tag is a command enclosed in angular braces
Syn : Tag contains two elements starting element and ending element
•
Starting element
Ending element
Every tag in HTML is predefined and optional
17
ASP.net •
Tags are of two types container tags and non container tags
•
The tag which contains both starting element and ending elements is called container tags Ex: ………………… ……………………etc….
•
Tags which provides only starting elements are called non container tags Ex :break line horizontal ruler etc………
TAG REFERENCES Different types of tag references are 1. BASIC TAG 2. TEXT FORMATING TAG 3. LINK TAG 4. LIST TAG 5. FRAME TAG 6. TABLE TAG 7. FORM TAG 8. MULTIMEDIA TAG
Basic tags: these tags will provide the structure of the document Ex: HELLO 18
ASP.net WELCOME TO HTML THIS IS HTML DOCUMENT THIS IS MY FIRST PROGRAM Link tag: it is used for linking one document with another document Or different parts of same document • Hyper link: it is used for linking two documents
link h1 F1.html • •
F2.html
Cross link: it is used for linking same document different paths Anchor tag is used for linking
Ex for hyper link
19
ASP.net HELLO WELCOME TO HTML THIS IS HTML DOCUMENT click here to show basic tag •
Text formatting tags: these tags are used to formatting the text by applying font style, size and font names etc…
Ex: BOLD ITALIC UNDERLINE SMALL FONT Big FONT LIST TAGS: It is used to display the information in bulleted format or numbered format etc…….. unordered list ordered list list item data definition data list data table
Ex for List tags
20
ASP.net
source code: MEMORY PRIMARY MEMORY RAM ROM SECONDARY MEMORY HARD DISC COMPACT DISC MULTIMEDIA TAGS: this tag is used to display the images on the text •
TAG:
•
=SCROLLING 21
ASP.net WELCOME •
IT IS USED TO PROVIDE SOME ANIMATION AFFECTS
•
PROPERTIES:
•
Ex for multi media tag:
22
ASP.net
Source code: WELCOME
Font tags: Syn :
23
ASP.net • Font tags: Syn : Arial Monotype Corsiva Times New Roman
1 least size 2 3 default size 4 5 6 7 highest size
Example with font tags
View source
24
ASP.net HI KANNABABU HTML IS MARKUP LANGUAGE HTML SUPPORTS FONT TAGS FRAME TAGS: These tags are used to divide the webpage into different webpartsFrameset tags has two optional attributes ROWS ATTRIBUTES: it is used to divide the webpage in to horizontal parts COLUMNS ATTRIBUTE: it is used to divide the webpage into vertical parts •
Each part of the webpage is known as a frame
•
Every frame should be identified using “NAME” attribute
•
To assign the name to a frame frameset tag contains a sub tag known as frame
•
It is a note after displaying webpage
•
There is no direct method to display the contents within a frame directly
•
any matter we want to display within aframe we will store in a html file and
•
attach this HTML file to the frame using src attribute
•
Frame names are case sensitive
Ex with Frame Tags
25
ASP.net
View source: where skin file is maintained Using web.config file: go to web.config file Example with THEMES AND SKINS: STEP-1: Open devenv---default.aspx--and design the following webpage
Step-2: go to website---add new item---and design default2.aspx as
Step-3: go to website-add new item--select skinfile--addyes-- automatically App_Themes\SkinFile\SkinFile.skin will be added--delete the code available in the skinfile--and write the following code Step-4: go to Default.aspx and write the following code Similarly go to Default2.aspx and write the following code Step-5: execute default.aspx and Default2.aspx and check the output the skin file is applied to every page o/p:
MASTER PAGES:
Master pages are used to provide a practical solutions for page templating .this is anewconcept introduced from ASP.net2005 .it is used to maintain the part of the webpage as constant through out the website. Example: Step-1: Start-run--devenv--create website---add new item-- Select master page template--add Step-2: cut the content place holder --go to layout--insert table--select template-select header ,footer and side template
Step-3: paste the content place holder in C
Step—4: place some image in A Step-5: drag and drop a tree view control in B
Step-6: execute the default page and execute. STATEMANAGEMENT IN ASP. Net
• • • •
• 1. 2. 3. 4. 5. 6.
It is the process of maintaining some information between multiple requests and responses It is also defined as an art of retaining values between multiple web pages As Asp .net is a stateless technology where with every request a page object is created on the server and with every response the object is destroyed on the server If we consider a website like online shopping where user can select multiple items to buy with each request the object is created then all the items details may not maintain to generate a bill.becoz of ASP. net stateless nature. in this criteria we need to maintain the information about the selected items in a temporary memory either on the client or on the server machine to perform this operation ASP .net has introduced state management state management is ASP .net contains 6 types View state URL encoding Cookies Sessions Application Caching
1. View state: it is one of the state management concept which is used for maintaining the state of a control in around trip fashion i.e. submitting the data to the server and getting the response back to the client • It maintain the information on the server under a collection class called as System.Web.UI.StateBagClass and on the client machine it is maintained in terms of a hidden field with a name – view state • The value which is maintained in view state is in a base 64 format which is easy to read a hexa decimal value • Any hacker can perform reverse engineering to the base 64 value and can get the actual value from it • To provide security for our view state data • ASP .net has provided two ways 1. Using EnableViewStateMacAttribute 2. Using Encrypting the data • Using EnableViewStateMacAttribute :This attribute generates strong check sum value which is a crypto graphical hash code •
When the page is submitted to the server this checksum is maintained on the client and is compared with the response value if both matches accept the page otherwise rejects the page • Html code window: • 10 Request.QueryString[“b"] or Request.QueryString[1] ………….>20 Request.QueryString[“uname"] or Request.QueryString[2] ………….>kanna Disadvantages of query string As query string transfers the data in plain text format and data is visible within the address bar query string cannot be used to pass the sensitive information like password, etc… Maximum limitation for address bar of any browser window is 4 kb(4096 bytes), so we cannot transfer more than 4 kb of information using query string (this 4kb uses url address also)
Ex with query string:
•
Default.aspx Enter value for a Enter value for b submit
Enter value for a Enter value for b submit
Code for Default.aspx Button1_Click { Response.Redirect("Default2.aspx?a="+ TextBox1.Text +"&b=" + TextBox2.Text); } • Code for Default2.aspx Page_Load { TextBox1.Text = Request.QueryString["a"].ToString(); TextBox2.Text = Request.QueryString[1].ToString(); } •
Default3.aspx
• Example with database •
Enter deptno submit Default4.aspx
Default3.aspx Designatio Ename Doj n
Xxx
Sal
Deptno
Xxx Xxx xxx
•
Code for default3.aspx Button1_Click { Response.Redirect("Default4.aspx?dno="+TextBox1.Text); } Code for default4.aspx •
SqlConnection con; SqlDataAdapter da; DataSet ds; protected void Page_Load(object sender, EventArgs e) { con = new SqlConnection("integrated security=yes;database=kanna;data source=localhost"); da = new SqlDataAdapter("select * from empdetails where deptno="+Request.QueryString["dno"].ToString(),con); ds = new DataSet(); da.Fill(ds, "empdetails"); GridView1.DataSource = ds; GridView1.DataMember = "empdetails";
GridView1.DataBind();} Default.aspx Enter username
pkey
Enter password label3 Empid pkey cancel Login.asmails px:
submit
SESSION: a session is some information maintained on a server machine • Session is accessible by all the WebPages of a website • A session is created separately for every user • Session supports server side state management where the complete information is maintained on the server machine • For every client which gives the request to the server is identified by the web server by creating a session for that session a session id is created which is 120 bit hexa decimal unique value. • Session id is a encrypted format and no hacker can perform reverse engineering to it • To maintain this session id asp .net supports 1. Cookies 2. Urlencoding • Cookie: when the client gives the request a session is created on the server and its session id is maintained in in-persistent cookie on the client machine by sending it along with the response for the next request and the response the session id is taken to the server and the client •
Cookie Session id
Request1 Session Response+SessionID
Session id
Asp.netsessionid ID n o i s Ses + 2 t ues q onID i e s R s e 2 +S e s n po Res
• 2.
3.
4. 5. 6.
The cookie which is maintained the session information the client machine uses ASP.net-SessionID as a name url encodeing:the session id information can also be maintained along with the url of the application where every request and the response takes the session id between client and server http://localhost/appname/(sessionid)/filename.aspx To use this type of session maintenance we should go to web.config file To create session manually asp. Net has provided a predefined object or a property called as Page.Session The session object is actually an object of System.Web.Sessionstate.Httpsessionstate the session objects provides some methods and properties methods: Apattern Add Clear Remove RemoveAll
RemoveAt 7. properties:Cookiemode Count Mode IsCookieless SessionId Keys TimeOut (specified the life span for session default life span for session is 20 minutes) • Creating a session: • Syn : Session[“name of the session”]=some value; • To get value variable=Session[“name”];
label1
button1
Page_Load(object sender, EventArgs e) { if (Session["Visit"] == null) Session["Visit"] = 1; else { int i = (int)Session["Visit"]; i++; Session["Visit"] = i; } Label1.Text = "you have visited:" + Session["Visit"] + "time"; } • To disable the session for complete web application go to web.config file • To disable the session for a webpage •
ALL THE BEST
B.KANNA BABU.