Download as pdf or txt
Download as pdf or txt
You are on page 1of 65

What is .NET?

• Microsoft .NET is a set of Microsoft software


technologies for connecting information, people,
systems, and devices.
• It is a device and platform independent distributed
computing model based on Web Services (which are in
turn based on open XML communication technology),
and consists of a software platform for building .
• .NET experiences a programming model and tools to
build and integrate XML Web services
• .NET is all about creation, consumption and delivery of
Web Services
What are the Components of .NET?
.NET Architecture
.NET Framework
ASP.NET Windows Forms

Web Services Web Forms Controls Drawing

ASP.NET Application Services Windows Application Services

Framework Class Library

ADO.NET XML Threading IO

Network Security Diagnostics Etc.

Common Language Runtime

Memory Management Common Type System Lifecycle Monitoring


.NET Component Model
• It offers developers an component model directly
based on OO.
• Removes distinction between a program element and a
software component. Thus it provides significant
benefits over technologies like CORBA and COM.
• .NET gets rid of the IDL - we can use a .NET assembly
directly as a component.
• Uses interface documentation already present in the
source code. Compliers for .NET supported languages
retain this information as metadata - self documented
components.
• Metadata is also available in XML format, any
application whether it is a part of .NET or not can
obtain information about components.
Visual Basics

Introduction:
The DOT NET is a software framework. It is developed by Microsoft. It
includes a large library and also provides language inter-operability across some
programming languages. Language inter-operability refers the capability of two
different languages to interact and operate on the same kind of data structures.
Design Features of DOT NET Framework
• Interoperability
• Common Language Runtime engine (CLR)
• Language independence
• Base Class Library
• Simplified deployment
• Security
• Portability
Operators:

An operator is a symbol that tells the compiler to


perform specific mathematical or logical manipulations.
VB.Net is rich in built-in operators and provides following
types of commonly used operators
• Arithmetic Operators
• Comparison Operators
• Logical/Bitwise Operators
• Assignment Operators
• Concatenation Operator
• Miscellaneous Operators
Object Oriented Programming
Visual Basic provides full support for object-oriented
programming including encapsulation, inheritance, and
polymorphism. Encapsulation means that a group of related
properties, methods, and other members are treated as a single
unit or object.
• Abstraction and Encapsulation.
• Polymorphism, Inheritance and Properties.
• Methods and Declaration Options.
• Object Instantiation and Early and Late Binding.
• Components and Adding Abstraction.
• Adding Encapsulation.
Error And Exception Handling
An exception is a problem that arises during the execution of a program.
An exception is a response to an exceptional circumstance that arises while a
program is running, such as an attempt to divide by zero.
• Exceptions provide a way to transfer control from one part of a program to
another. VB.Net exception handling is built upon four keywords - Try,
Catch, Finally and Throw.
• Try − A Try block identifies a block of code for which particular exceptions
will be activated. It's followed by one or more Catch blocks.
• Catch − A program catches an exception with an exception handler at the
place in a program where you want to handle the problem. The Catch
keyword indicates the catching of an exception.
• Finally − The Finally block is used to execute a given set of statements,
whether an exception is thrown or not thrown. For example, if you open a
file, it must be closed whether an exception is raised or not.
• Throw − A program throws an exception when a problem shows up. This is
done using a Throw keyword.
Exmaple:
Try [ tryStatements ]
[ Exit Try ]
[ Catch [ exception [ As type ] ] [ When expression ]
[ catchStatements ]
[ Exit Try ] ]
[ Catch ... ]
[ Finally
[ finallyStatements ] ]
End Try
Features in C#
• C# is object oriented programming language. It provides a lot of features that
are given below.
1)Simple
2)Modern programming language
3)Object oriented
4)Type safe
5)Interoperability
6)Scalable and Updateable
7)Component oriented
8)Structured programming language
9)Rich Library
10)Fast speed
1) Simple
C# is a simple language in the sense that it provides structured approach (to break the
problem into parts), rich set of library functions, data types etc.

2) Modern Programming Language


C# programming is based upon the current trend and it is very powerful and simple for
building scalable, interoperable and robust applications.

3) Object Oriented
C# is object oriented programming language. OOPs makes development and
maintenance easier where as in Procedure-oriented programming language it is not easy
to manage if code grows as project size grow.

4) Type Safe
C# type safe code can only access the memory location that it has permission to execute.
Therefore it improves a security of the program.

5) Interoperability
Interoperability process enables the C# programs to do almost anything that a native C++
application can do.

6) Scalable and Updateable


C# is automatic scalable and updateable programming language. For updating our
application we delete the old files and update them with new ones.
7) Component Oriented
C# is component oriented programming language. It is the predominant software
development methodology used to develop more robust and highly scalable applications.

8) Structured Programming Language


C# is a structured programming language in the sense that we can break the program into
parts using functions. So, it is easy to understand and modify.

9) Rich Library
C# provides a lot of inbuilt functions that makes the development fast.

10) Fast Speed


The compilation and execution time of C# language is fast.
Object-oriented Programming in c#
• C# Object
In C#, Object is a real world entity, runtime entity, it is created at runtime.
• C# Class
In C#, class is a group of similar objects. It is a template from which objects are
created.
• C# Constructor
constructor is a special method which is invoked automatically at the time of
object creation.
There can be two types of constructors in C#.
1)Default constructor
A constructor which has no argument is known as default constructor. It is
invoked at the time of creating object.
2)Parameterized constructor
A constructor which has parameters is called parameterized constructor. It is
used to provide different values to distinct objects.
• C# Destructor
• A destructor works opposite to constructor, It destructs the objects of classes. It
can be defined only once in a class. Like constructors, it is invoked automatically.
C# Exception Handling
Exception Handling in C# is a process to handle runtime errors. We perform exception
handling so that normal flow of the application can be maintained even after runtime
errors.
In C#, exception is an event or object which is thrown at runtime. All exceptions the
derived from System.Exceptionclass. It is a runtime error which can be handled. If we
don't handle the exception, it prints exception message and terminates the program.
Advantage
It maintains the normal flow of the application. In such case, rest of the code is
executed event after exception.
C# Exception Handling Keywords
In C#, we use 4 keywords to perform exception handling:
try
catch
finally, and
throw
ASP.NET
• ASP.NET is a web development platform, which provides a
programming model, a comprehensive software
infrastructure and various services required to build up
robust web applications for PC, as well as mobile devices.
• ASP.NET works on top of the HTTP protocol, and uses the
HTTP commands and policies to set a browser-to-server
bilateral communication and cooperation.
• ASP.NET is a part of Microsoft .Net platform. ASP.NET
applications are compiled codes, written using the
extensible and reusable components or objects present in
.Net framework. These codes can use the entire hierarchy
of classes in .Net framework.
Standard Controls
Button Controls
ASP.NET provides three types of button control:
• Button : It displays text within a rectangular area.
• Link Button : It displays text that looks like a hyperlink.
• Image Button : It displays an image.

Text Boxes and Labels


Text box controls are typically used to accept input from the user. A
text box control can accept one or more lines of text depending upon
the settings of the TextMode attribute.
Label controls provide an easy way to display text which can be
changed from one execution of a page to the next. If you want to
display text that does not change, you use the literal text.
Standard Controls
Check Boxes and Radio Buttons
A check box displays a single option that the user can either check or
uncheck and radio buttons present a group of options from which the
user can select just one option.
List Controls
ASP.NET provides the following controls
• Drop-down list,
• List box,
• Radio button list,
• Check box list
Image Control
The image control is used for displaying images on the web page, or
some alternative text, if the image is not available.
Navigation Controls
In ASP.NET 2.0, a menu can be stored in a file to
make it easier to maintain. This file is normally
called web.Sitemap, and is stored in the root
directory of the web.

Basically ASP.NET 2.0 has three navigation controls:


• Dynamic menus
• Tree Views
• Site Map Path
Navigation Controls
1) Dynamic menus
It was the very difficult task to maintain the menu of a large website and time
consuming. It is used to display the Menus. You can use it as easy as other Navigation
controls. Menu can be stored in a file to make it easier to maintain. This file is
normally called web. Sitemap, and is stored in the root directory of the web.
2) Tree Views
A Tree View control displays a hierarchical list of items using lines to connect
related items in a hierarchy. Each item consists of a label and an optional bitmap.
Windows Explorer uses a Tree View control to display directories. You can use the Tree
View control in any situation in which you need to display hierarchical data.
3) Site Map Path
Use of this control is very simple. You can add this control to your page then view
your page in browser. The Sitemap Path control displays the navigation path of the
current page. The path acts as click able links to previous pages.
Using a WCF service
• We need a create a client to be able to use a
web service .However before creating a client,
you have to generate a proxy class that helps
the client application to call the WCF service
• Execute the following command in developer
command prompt for VS2012 to generate the
proxy class:
SVCutil.exe
http://localhost:2045/service.SVC?wsdl
• The command generates a configuration file
(output.config) and a code file (service.cs)
containing the client class.
• Now perform the following steps to create a
client application:
1. Right-Click the name of the application and
select the AddAdd New Item option from
the context menu.
2. Select Visual C# from the left pane and the
web Form from the middle Pane and then
click the add button in the Add New Item.
3. Add the reference of the WFC service to the
project by right-clicking the name of the project
in the solution Explorer and selecting the Add
Service Reference option from the context
menu.
4.Enter the address of the service and click the
GO button in the Add Service Reference dialog
box.
5.Enter the name of namespace in the
Namespace textbox, which in this case is service
reference1,and click the ok button to add the
service reference
• Code for the default aspx.cs file
protected void button1_Click (object sender,
Eventargs e)
{
MyServiceClient client=new MyServiceClient();
Label1.Text=client.MyTask1(TextBox1.Text);
Client.Close();
}
Press the f5 key to run the WCFClient
application
Creating WCF Data Services
• Right-Click the name of the application and
select the AddAdd New Item option from
context menu.
• Select Visual C# from the Installed Templates
pane and ADO.NET Entity Data Model from
the middle pane and then click the Add button
in the Add New Item dialog box.
• The Entity Data Model Wizard appears
• Select the Generate from database option
and click the Next button.
The next page for the Entity Data Model
Wizard appears, prompting the user to select a
data connection.
• Select the check box beside the Tables option.
• Click the Finish button.
• Right-Click the application name in the
Solution Explorer window to add a WCF data
service to the application and select the Add
New Item option from the menu.
• Select the WCF Data service from the Add New
Item dialog box and click the Add button.

Code for WCFDataService.cs File


• Public class
WcfDataService:DataService<NorTHWNDEntities
>
• {
• Config.SetEntitysetAccessRule(“*”,
EntitySetRights.AllRead);
• Config.SetServiceOperationAccessRule(“*”,
ServiceOperationRights.All);
• Config.DataServiceBehaviour.MaxProtocolVers
ion=DataServiceprotocolersion.v2;
• }
• }
Hyper Text Markup language(HTML)was used to
create web sites. As time progressed new scripting
languages, such as Extensible HyperText Markup
Language(XHTML) and JavaScript , and technologies ,
such as cascading Stylesheets (CSS) And Adobe Flash,
Were introduced. These new languages and
technologies helped web developers to create
interactive W ex b site. Some of these technologies
Were expensive to deploy on the web server and
their performance on different platforms also varies.
To address these problems, Microsoft introduced
SilverLight.
SilverLight is a technology used to create web sites
that can have high-resolution multimedia content and
eye-catching visual effects, which in turn provide an
attractive look and feel to your web site.
Features of silverlight
The main features of SilverLight are as follows:
 Supported by .Net programming model.
 Comprehensive user interface (UI)framework
 Support for the Deep zoom technology.
 Support for three dimensional(3D) graphics,
animations, and multimedia .
 support for networking.
 support for higher quality video and audio.
Out-of-browser capabilities.
Explaining the SilverLight Architecture
SilverLight is a combination of various existing
technologies, Such as HTML, javaScript, XHTML,
and. Net framework. These technologies are
incorporated in SilverLight as different components
and services.
SilverLight has two main components:
.NET frameworks for SilverLight: Refers to an
abstract version of the common language
runtime(CLR),which offers basic functionalities ,
such as type checking, debugging ,and garbage
collection. It also allows you to integrate data in
Silverlight applications through XML,LINQ and LINQ
to XML(XLINQ).
The core presentation Framework: Refer to
component that offers features and service for
Designing the UI of silverlight applications
through controls, styles, templates, 2D vector
graphics, animations, and multimedia. This
Component also allows you to accept user input
through input devices , such as mouse and
keyboard
The file which are atomically included in a Silverlight
application are
 App.xaml- application-level resources,
brush and style objects
 App.Xaml.cs-code-behind class for the app.xaml file
 Mainpage.xami- it is used to define a page, similar to a
page in a web site
 Main page.xaml.cs-
Silverlight 5.0 application has three essential files as follows:
 An Asp.net file- loads when a silverlight applications
runand hosts the main page.xaml XAMI file
 An HTML FILE (a test page )- Hosts the silverlight
application.
 A javaScript helpe file – provides methods,such as
createObject() and createObjectEx(), to embed a silverlight
applocation in a web page.
Controls used in silverlight applications:
In silverlight, controls are represented by
Different XAML elements.tje controls or
Elements that you add to silverlight application
Become a part of hierarchical then that is then rendered to
display controls to the clients.

Control Description XAML element example


Border To add a border and a background <Border
to some other control BorderBrush=“blue”
BorderThickness=“3”/>
Button To provide a button that responds <button Content=“Hello”
to the mouse and keyboard events. ClickMode=“press”/>
Calendar To view a calendar and work with <calender
days ,month and year displaymode=“month” is
todayHighlighted=“true”/>
Control Description XAML element example
Canvas To position and arrange the containing <canvas>
controls at given location <button convert=
“hellow”canvas.left=“50”
Canvas. top=“50”/>
</canvas>

contentControl To a control that contains content. <ContentControl


several control are derived from the content=“Silverlight”/>
content Control class
DataGrid To display data in the from of a grid <sdk:DataGrid
with several rows and colimns. itemSourcce=“silverlight”//
>
Datapicker To select a particular data from a given <sdk: Datepicker is
calender or type the desired date. todayHIghted=“true”
selectedDataFormat=“shor
t”/>
hyperlinkButto To display a button with hyperlink <hyperlinkButton
n content=“URL fpr google”
navigateUri=http://www.g
oogle.com/>
Control Description XAML element example
password Box To enter the password <passwordBox
characters that can not be x.Name=“pwdBox”
viewed Margin=“20,10,0,0”Height=
“35”width=“200”passwordc
har=“*”horizontalAlignmen
t=“left”/>
progressBar To indicate the progress of <progressBar
any operation. x.name=“probar”
value=“100”8,110,143,10”
maximum=“200”
height=“15”
isindeterminate=“false”/>
Developing Silverlight Applications:
Silverlight provides you the functionality to develop
web sites that can host multimedia and animations.
Creating a simple silverlight Application
In this application,the GridSplitter control isused so
that a user can resize rows and column of the grid.
Steps:
• Select installedtemplates visual C# silverlight
from the left pane
• silverlight application from the middle pane
• Specify the name of the application
myFirstSilverlightApp in the name text box.
• Select the host the sliverlight application in a new
web site check box.
• Select the ASP>NET web Application project option from the Net Web
Project type drop down box.
• Select Silverlight5from the Silverlight version drop down box.
• Click the ok button.
• Replace the code of the mainpage.xaml file with the code.
< userCOntrol x:class=“MyFirstSilverlightApp.MainPage”
Xmlns=http://schemas.microsoft.com/winfx/2006,xaml/presentation
<grid x:name=“layoutRoot” Background=“Turquoise” Height=“300”
Width=“600”>
<Ellipse x:Name=“face” Height=“75” Width=“75” Fill=“RED”
verticalALignment=“top” Margin=“15”/>
<RotateeTransform Angel=“-25”/>
<path stroke=“Black” stokeThickness=“3” Data=“M 10,50 A 100,50 75 0 0 50 ,
50” horizontalAlignment=“center” margin=“0,10,10,0”/>
<Rectangle X:Name=“shorts3” Height=“55” Width=“55” Fill=“Orange”
Margin=“35,165,0,0”/>
<Rectangle.RebderTransfrom>
</Grid> </userControl>
Hosting video in a web site
Silverlight can also be used to host audio and video files in
a web site. Silverlight provides the MediaElement control
to host audio and video files in a web site.
Steps:
• Select the ASP.NET Web Application project option
from the New web project type combo box.
• Select Silverlight 5 from the silverlight version combo
Box.
• Select the Enable WCF RIA services check box.
• Right-click the application name in the solution Explorer
window and select AddExisting item from the context
menu.`
• Navigate to the location and select the video, which you
want to display on the web page and click Add button.in
this case, we have added the Widlife.wmv file.
• Select the video file(Wildlife.wmv)in the Solution Explorer and press the f4
key . the properties window appears
• The select the copy to output Directory properties window. The default
values of this property is Do not copy.
• Set the Build Action property o the Wildlife.wmv file to Resource in the
properties window.
• Replace the code of the MainPage.Xaml file with the code.
<userControl X:class=“SilverlightVideoapplication.MainPage”
Xmlns=http://Schjemas.microsoft.com/winfx/2006/Xaml/presentation
Xmlns:d=“http://Schjemas.microsoft.com/winfx/2006/Xaml”
<Grid x:Name=“LayoutRoot” Background=“white”>
<MediaElement X:Name=“MediaPlayer”
Source=“wildlife.wmv”></MediaElement>
<Button Content=“play” Name=“button1” VerticalAlignment=“Bottom”
Width=”75”>
Click=“button1-Click”/>
</Grid>
</UserControl>
Create Applications Using Different Controls
Silverlight provides numerous controls that you can
use to define appearance of your Silverlight
applications . Most of the controls are the same as
WPF.
• The AudioComplementeBox control
• The DataPager control
• The TreeView control
• The HyperlinkButton control
• The Popup control
The TabControl control.
• CachingCaching in asp.net
is a technique that is used to
temporarily store the frequently accessed
webpages in memory.
web pages faster, than accessing them
from the original source.
• For example, when you access a webpage
for the first time, it takes some time to get
loaded.
• However subsequent visits to that
webpage become faster because the web
page has been cached on your
requirements.
caching in asp.net
• Caching can be used to improve the
processing time and the performance of
a web application.
• It allows you to access data from the
cache stored in your local computer,
which is faster than retrieving the data
from the database on each request.
Cache class

• In asp.net the
System.Web.Caching.Center class is
used to implement caching for a
web application.
• It is important to note that the
System.Web.Caching cache class
cannot be inheritied.
Property

• Count
• EffectivePercentagePhysicalMemoryLimit
• EffectivePrivateBytesLimit
• Item
• Count
Methods

• Add
• Get
• GetParameter
• Insert
• Remove
Output Caching

• Output caching also known as page level caching,


is the simplest technique of caching in asp.net.
• In output caching if a client requests a webpage for
the first time, the requested webpage is accessed
from the web server and sent to the client and a
copy of that requested webpage is stored in cache.
• Implement output caching by just adding the
@outputcache directive.

• <%@ OutputCache Duration=“10”


VaryByParam=“none” %>
Disk output cache

• The disk output cache can be used to save


cached responses to the disk as well in memory
to use the disk output cache you need to first edit
the web.confg file of a web application to specify
the maximum size per application.
• Next you need to specify the duration for which
the cached responses are saved by the output
cache in the output cache element by using the
duration attribute. to enable the disk output
cache, you also need to set the disk cache
attribute to true
Attribute
• Cache
• Duration
• Location
• Nostore
• Shared
• Sql dependency
The Location Attribute
• The location attribute is used to define the
location where the item needs to be cached.
• It can be on the server side or on the client side
or can even be on the proxy server
• Value
• Any
• Client
• Down
• None
The Vary Custom
• The VaryByCustom attribute is used to define
custom strings to manage customized
caching
requirements.
• For Example, if browser is Specified as the
value of this
attribute, the caching engine saves multiple
copies of data,
depending the type of browser.
The VaryByParam Attribute

• The VaryByParam attribute is used to


cache different copies of a page.
• When the page is generated
dynamically, based on the parameters
recevied in the
Uniform Resource Locator(URL)
Describing Partial-Page Output
Caching
• Caching of a complete web page is not always
requried.
• Sometimes you need to implement caching
can specific content of a web page and the
remaining content of the web page needs to
be refreshed each time the page is requested.
• This can be implemented by using partial
caching or fragement caching.
he steps to apply partial caching are as follows.
1.Identity the parts of a webpage that
require more resources and processing than
other parts.

2.create one or any user controls and


decide cache polices for them. Cache
policies ensure the validity of the cached
data on each user required.
Output cache
• The disk output cache can be used to save cached
responses to the disk as well in memory.

• To use the disk output cache you need to first edit


the web.confg file of a web application to specify the
maximum size per application.

• Next you need to specify the duration for which the


cached responses are saved by the output cache in
the output cache element by using the duration
attribute.

• To enable the disk output cache, you also need to set


Data caching
• Data caching also known as application
caching, is one of the most powerful
features in the whole caching scenario in
asp.net.
• Data caching is all about enabling caching
programmatically.
• Data caching is very useful when you need
to cache custom data into cache memory.
• For example if you need to cache a dataset
to use it later in a website you can use data
caching .
It supports the following basic types of dependency m

• File dependency
• Key dependency
• Sql dependency
• Data caching in .net is implemented by
the cache.class which is contained in the
system.web.caching namespace
cache["myvalue"]=value.
They are three main tasks:

*Adding items to cache

*Retrieving items from cache

*Deleting items from cache


Adding items to cache
To add an item to cache:
cache[“Myvalue"]=value;

To add an item to cache by using the


Cache.Insert method:
cache.Insert[“Myvalue", value);

To specify the dependency of an item

cache.Insert("MyData", data,New
CacheDependency(server
.mappath("data.xml")));
• Retrieving data from cache
value=cache[“Myvalue"];

• Deleting items from cache

• An expiration policy is used to implement


data caching.
this expiration policy removes data
automatically on the basis of the time limit
specified in it.
Implementing data caching
• Open Visual Studio 2012.
• Click FileNew  Website. The New Web Site dialog box
appears.
• Select the Asp.Net Web Forms Site template and name it
DataCachingExample and click the OK button.
• The Default.Aspx web page opens in the source view.
• Select the design tab to view the design of the web page.
• Drag and drop two label controls and one grid view control
on the default.aspx page from the tool box.
• Set the text property of label1 to data caching example.
• Protected void page_load(object sender, Event args e)
• {
• Dataset Dataset1=new Dataset();
• If (Cache[“MyCacheDataSet”]==null)
• {
• DataSet1.ReadXml(Server.MapPath(“Authors.xml”));
• Cache.Insert.(“MyCacheDataset”,DataSet,new
System.Web.Caching.CacheDependency(Server.MapPat
h(“Author.xml”)));
• Label12.Text=“Cache Generate”;
• }
• Else
• Label12.Text=“Using pre-generated Cache”;
• GridView1.DataSource=Cache[“MyCacheDataset”
];
• GridView1.DataBind();
• }
• }

You might also like