C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

ASP.NET 2.0, new features


Posted Date: 18 Nov 2007    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: KumarMember Level: Silver    
Rating: 1 out of 5Points: 10



Introduction:
In this article I would deal with the new concepts that were brought in 2.0 framework with some exmaples.

I. Partial Class:

First let me explain the meaning of partial class. A partial class is a class where the definition of the class is split into more than one physical file. But it does not make any difference to the complier. Compiler will treat them as a single entity by grouping them into a single file like any normal class file.

We can develop our page in such a way that the design part is in a single file and the business logic part in another file. Since it allows designing the page in multiple file, we can simultaneously work on the same page in the centralized version also like VSS. usually IDE generates lot of UI related code which the developer hardly need the content and because of this partial class concept this can be hidden from him. Debugging will also become much easier since the page is partitioned divided into separate files.

What are the advantages, if you use the partial classes in your application?

Reason #1: You can separate your application business logic from the design part. This will prevent developers from messing with the code that was generated by UI.

Reason #2: Programmers can work on the same file at the same file from different geographical locations without waiting for the file to be checked in. It is more useful when your class become more and more large in nature.



Usage:

Suppose there is a requirement for developing a class with 2 different functions say “Add Employee” and “FindEmployee”
We can develop a single page for both the functions or we can split them into two different pages (or files) with the same class name and having the “Partial” keyword.

Using partial class concept:

-- AddEmp.vb

Public Class Employee
Public Sub AddEmployee()
' your definition goes here
End Sub
End Class

-- FindEmp.vb

Partial Public Class Employee
Public Sub FindEmployee()
-- your definition goes here
End Sub
End Class

Using normal class concept:

--AddOrFindEmp.vb

Public Class Employee
Public Sub AddEmployee()
-- your definition goes here
End Sub

Public Sub FindEmployee()
-- your definition goes here
End Sub
End Class

You can also define your class in separate files by differentiating them by their content. For example, you can write the public properties of the class in one single file and all the methods in another file for the same class. Now you have that level of flexibility in defining and using the classes in .NET.

But there are few limitations in using the partial classes and few of them are:

• Partial classes can be used to split the definition of classes, structures, and interfaces, which supports simultaneous development or the separation of generated from user-generated code.
• Each part of a partial class must be available at compile time.
• Partial classes must use the same access modifier (e.g. Public Protected, Private).
• If any single part is abstract (MustInherit), then the whole class is abstract.
• If any parts are sealed (NotInheritable), then the whole class is sealed.
• If any part declares a base type, then the whole class inherits that base type.
• Parts can specify different interfaces, but the whole class implements all interfaces.
• Features defined in any part are available to all partials; the whole is the sum of all of the parts.
• Delegates and enumerations cannot use the partial modifier.
• Attributes apply to all parts.

This list may seem like a lot to remember, but just think of partial classes as a class definition split across many files for convenience.

I. Master Page:

One of the finest features of the ASP.NET is to facilitate the creation of master pages.
Using this, you can create consistent base layout file of the application in which various other web pages fit into that. First you need to identify the needs of your web application in terms of the appearance and behavior. In the master page, you add placeholders called ContentPlaceHolders where the content pages will insert their custom content. When users request the content pages, ASP.NET merges the output of the content pages with the output of the master page, resulting in a page that combines the master page layout with the output of the content page.

Master pages have a .master file extension. Apart from the content required to define the standard look and feel of the application, the master pages also contain all the top-level HTML elements for a page, such as , , and . Finally, each master page contains one or more content placeholders that define regions into which the child pages render content.

Step 1: Creating the Master Page

Create a new project and in the IDE, select the websites menu and then select the Add New Item list, which will give us the list of the items that can be add to the current project. Select the Master Page and say “Add”.

A typical master page contains:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>









..








The above code snippet is almost similar to any ASP.NET page containing the and elements except the < @Master> directive on the top and the file(page) extension as .master. Note the use of the ContentPlaceHolder control, which dictates where content pages can insert content. So you can define the header, left/right menus and the footer in the master page itself. Any content page that uses this master page will automatically come with the header, menus and footer. Master page can also contain code apart from the content which helps in peforming generic operations or dynamic loading of controls. The Id attribute of the contentplaceholder helps to uniqely identify this in the container pages.

Step 2: Creating the Container Page (web page)

You can create the webpage (web form) as usual by choosing the Add New Item list from the websites menu. But if you want your web page need to be the container page of the Master page, then you need to select the check box “Select Master Page” before saying “Add”.

A typical container page which is inheriting the master page contains:
A Page directive and the tag.

Page directive <@page> which specifies the title of the page and the language that is been used to developed the page. One important attribute of this directive is MasterpageFile, specifying the path of the master page. You can also give the Title for your web page using the Title attribute of this directive.

tag is the content area where we can design the main content of the specified web page (apart from the header, footer, left/right menus which are driven by the master page). ContentPlaceholderId attribute value should match with the Id given to the placeholder in the master page. (Here MyPlaceHolder, ref to the Step 1 for the Id)

Since the master page already followed the HTML document architecture and the place holder is one of the element in that form; we need not follow the same hierarchy again here. We can directly design using the tag elements of any webpage like ,
and so on. You can design a web page within this tag and you can see the outer layout for this page in design view itself. Now you can identify your piece of page development lies within the framework predefined using the Master page. Using this way of development, not only the rework efforts will be reduced but also the flexibility in web page design will be experienced by the developer.

III. ADO.Net:

DataSet and DataReader Transfer:

In .NET 2.0, you can directly load the DataReader into the Dataset or the Data Table and vice-versa. You have a new method “load” and using this you can load the DataReader into the DataSet or the DataTable. Like you also have another method called “getDataReader”which will return the DataReader back to the DataSet or the DataTable. DataTable is now having most of the methods of the DataSet. For example: WriteXML and ReadXML methods are now available for DataTable also.

Data Paging:

Custom Paging is one the major requirement in the ASP.NET. Earlier we used to write Stored Procedure to implement pagination logic. But in ADO.NET, you can do is very simply using the framework functionality itself. A new API "ExecutePageReader" in SQLCommand will do all the stuff for you and return only the required records. This method is very similar to ExecuteReader but it will accept two extra parameters. One is "Starting row number" and other one is for "number of rows". This will also return DataReader.

Ex:
Dim drEvents As SqlDataReader
Dim conn As New SqlConnection(Conn_str)
conn.Open()
Dim sqlc As New SqlCommand("Select * from tblEvents", conn)
drEvents =
sqlc.ExecutePageReader(CommandBehavior.CloseConnection, 10, 10)

BatchUpdates:

In previous versions of ADO.NET, if you do changes to DataSet and update using DataAdapter.update method. It makes round trips to datasource for each modified rows in DataSet. This is fine with few records, but if there is more than 100 records to be modified, then it will make 100 calls from DataAccess layer to DataBase which is not acceptable. In this release, MicroSoft have changed this behaiour by exposing one property called "UpdateBatchSize". Using this we can metion how we want to groups the rows in dataset for single hit to database.

For example if you want to group 50 records per hit, then you need to mention "UpdateBatchSize" as 50.

Conclusion:

In this document, I would like to share my experiences or views while working with the latest version of .NET 2.0. It make our lives more simpler than earlier by providing the direct functions like user.identity.name for getting the name of the person who logged into the system (provided the settings in IIS should support to Windows Authentication). As a developer, you can feel the difference right from the UI level to the database operations(ADO.Net) level.





Responses

Author: ChandraShekar Thota    27 Nov 2007Member Level: Diamond   Points : 0
gud article
really useful for many people
i used to see many people asking about new features in questions section
this article might be very much useful




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: [Software Review] The Power JavaScript Framework called Prototype.JS
Previous Resource: Useful Tips for Master Page
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use