Tuesday, May 12, 2009

Master Pages

Master Pages: The master page feature provides the ability to define common structure and interface elements for your site, such as page header, footer or navigation bar in a common location called master page

Adding master pages to solution:
A master page is similar to a ‘.aspx’ page except that it has its own unique extension, ‘.master’. Furthermore, a master page contains a new ‘Master’ directive, along with a ContentPlaceHolder control. we can keep any number of contentPlaceHolders in a single Master page.

Once you have your master page, you obviously want to create content pages using your master page as a template.

Your content page will be like any other .aspx page you have created in the past, except that it will reference the master page in the Page Directive and it will contain a Content Control and between this control will be all your content or at least the all the content for the corresponding ContentPlaceHolder contron in your master page.

<%@ Page Language=”C#” MasterPageFile=”~/Default.master” Title=”Untitled Page” %>

While adding the master page to the content bage, ‘MasterPageFile’ attribute will add with in the page directive.The use of this attribute indicates that this particular .aspx page inherits from another page.

The Location of the masterpage with in the application is specified as the value of the ‘MasterPageFile’ attribute.

After adding the Masterpage the contentpage (Default.aspx) neither contain

tag or any opening or closing HTML tags that would normally included in typical .aspx page.

Specifying which master page to use:

If you want to apply the master page template to only a specific subset of pages (such as pages contained within a specific folder of your application), you can use the element within the ‘Web.config’ file.

Working with masterpage Titles:

When you create content page in your application, by default all the content pages automatically use the title that is declared in the masterpage.

For instance, you have primarily been using a masterpage with the title “My Master page”. Every content page that created using the masterpage also uses the same “My Master page”.

You can avoid this by specifying the pages title using “Title” attribute in the page directive.

You can also work with the page titles programmatically in the content page.

Default.aspx:

Protected void page_LoadCompleted(object sender, EventArgs e)

{

Master.Page.Title=”This page Title”;

}

Working with controls and properties from the MasterPage:

The master page, when inherited by the content page, exposes a property called ‘Master’.

You can use this property to get at control values or custom properties that are contained in the Master page itself.

Default.master

Default.master Code behind:

Protected void page_Load(object sender, EventArgs e)

{

If(!page.IsPostBack)

{

Label1.Text=System.Guid.NewGuid().ToString();

}

}

Default.aspx

Protected void page_Load(object sender, EventArgs e)

{

Label1.Text=(Master.FindControl(“Label1”) as Label).Text;

}

Programatically Assigning the Master Page

You can assign the MasterPage to the content page through the use of the ‘Page.masterpagefile’ property. To accomplish this, use this property through the page_PreInIt event.

The Page_PreInit event is the earliest point in which you can access the page life cycle.

The Page_PreInit is an important event to make note of when you are working with MasterPages, as this the only point where you can affect both the master and content page before they are combined into a single instance.

Protected void page_PreInit(object sender, EventArgs e)

{

Page.masterpagefile=”~/MyMaster.master”;

}







Thursday, May 7, 2009

ASP.Net Basics and Data controls

ASP.Net is the programming framework built on the on Common Language Runtime that can be used in server to build powerful web applications. The first version of a ASP.Net offered several important advantages over previous development models. ASP.Net2.0 improves upon that foundation by adding support for several exiting features in the areas of developer productivity, Administrator management, extensibility, and performance.

ASP.Net 2.0 New features:

1.New Server Controls:ASP.Net 2.0 introduces many new server controls that enables powerful declarative support for data access, login security, wizard navigation, menus, treeview, portals and more.
1.1. Data Controls:Data access in ASP.Net 2.0 can be accomplished completely declaratively ( no code) using the new data bound and data source controls. There are new data source controls to represent different data back-ends to such as SQL data base, business objects and XML, and there are new data bound controls for rendering common UI for data such as gridview, details view and formview.

1.2 Navigation Controls.
The navigation controls provide common UI for navigating between pages in your site, such as treeview, menu, and sitemappath. These controls use the site navigation service in ASP.NET 2.0 to retrieve the custom structure you have defined for your site.

1.3. Login Controls. The new login controls provide the building blocks to add authentication and authorization-based UI to your site, such as login forms, create user forms, password retrieval, and custom UI for logged in users or roles. These controls use the built-in membership and role services in ASP.NET 2.0 to interact with the user and role information defined for your site.

1.4. Web Part Controls. Web parts are an exciting new family of controls that enable you to add rich, personalized content and layout to your site, as well as the ability to edit that content and layout directly from your application pages. These controls rely on the personalization services in ASP.NET 2.0 to provide a unique experience for each user in your application.

2. Master Pages.
This feature provides the ability to define common structure and interface elements for your site, such as a page header, footer, or navigation bar, in a common location called a "master page", to be shared by many pages in your site. In one simple place you can control the look, feel, and much of functionality for an entire Web site. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behavior.

3.Themes and Skins. The themes and skins features in ASP.NET 2.0 allow for easy customization of your site's look-and-feel. You can define style information in a common location called a "theme", and apply that style information globally to pages or controls in your site. Like Master Pages, this improves the maintainability of your site and avoid unnecessary duplication of code for shared styles.

4.Personalization.
Using the new personalization services in ASP.NET 2.0 you can easily create customized experiences within Web applications. The Profile object enables developers to easily build strongly-typed, sticky data stores for user accounts and build highly customized, relationship based experiences. At the same time, a developer can leverage Web Parts and the personalization service to enable Web site visitors to completely control the layout and behavior of the site, with the knowledge that the site is completely customized for them. Personalizaton scenarios are now easier to build than ever before and require significantly less code and effort to implement.

5.Localization.
Enabling globalization and localization in Web sites today is difficult, requiring large amounts of custom code and resources. ASP.NET 2.0 and Visual Studio 2005 provide tools and infrastructure to easily build Localizable sites including the ability to auto-detect incoming locale's and display the appropriate locale based UI. Visual Studio 2005 includes built-in tools to dynamically generate resource files and localization references. Together, building localized applications becomes a simple and integrated part of the development experience.

Administration and Management

ASP.NET 2.0 is designed with administration and manageability in mind. We recognize that while simplifying the development experience is important, deployment and maintenance in a production environment is also a key component of an application's lifetime. ASP.NET 2.0 introduces several new features that further enhance the deployment, management, and operations of ASP.NET servers.
  • Configuration API. ASP.NET 2.0 contains new configuration management APIs, enabling users to programmatically build programs or scripts that create, read, and update Web.config and machine.config configuration files.

  • ASP.NET MMC Admin Tool. ASP.NET 2.0 provides a new comprehensive admin tool that plugs into the existing IIS Administration MMC, enabling an administrator to graphically read or change common settings within our XML configuration files.

  • Pre-compilation Tool. ASP.NET 2.0 delivers a new application deployment utility that enables both developers and administrators to precompile a dynamic ASP.NET application prior to deployment. This precompilation automatically identifies any compilation issues anywhere within the site, as well as enables ASP.NET applications to be deployed without any source being stored on the server (one can optionally remove the content of .aspx files as part of the compile phase), further protecting your intellectual property.

  • Health Monitoring and Tracing. ASP.NET 2.0 also provides new health-monitoring support to enable administrators to be automatically notified when an application on a server starts to experience problems. New tracing features will enable administrators to capture run-time and request data from a production server to better diagnose issues. ASP.NET 2.0 is delivering features that will enable developers and administrators to simplify the day-to-day management and maintenance of their Web applications.

Flexible Extensibility

ASP.NET 2.0 is a well-factored and open system, where any component can be easily replaced with a custom implementation. Whether it is server controls, page handlers, compilation, or core application services, you'll find that all are easily customizable and replaceable to tailor to your needs. Developers can plug in custom code anywhere in the page lifecycle to further customize ASP.NET 2.0 to their needs.
  • Provider-driven Application Services. ASP.NET 2.0 now includes built-in support for membership (user name/password credential storage) and role management services out of the box. The new personalization service enables quick storage/retrieval of user settings and preferences, facilitating rich customization with minimal code. The new site navigation system enables developers to quickly build link structures consistently across a site. As all of these services are provider-driven, they can be easily swapped out and replaced with your own custom implementation. With this extensibility option, you have complete control over the data store and schema that drives these rich application services.

  • Server Control Extensibility. ASP.NET 2.0 includes improved support for control extensibility, such as more base classes that encapsulate common behaviors, improved designer support, more APIs for interacting with client-side script, metadata-driven support for new features like themes and accessibility verification, better state management, and more.

  • Data Source Controls. Data access in ASP.NET 2.0 is now performed declaratively using data source controls on a page. In this model, support for new data backend storage providers can be easily added by implementing custom data source controls. Additionally, the SqlDataSource control that ships in the box has built-in support for any ADO.NET managed provider that implements the new provider factory model in ADO.NET.

  • Compilation Build Providers. Dynamic compilation in ASP.NET 2.0 is now handled by extensible compilation build providers, which associate a particular file extension with a handler that knows how to compile that extension dynamically at runtime. For example, .resx files can be dynamically compiled to resources, .wsdl files to web service proxies, and .xsd files to typed DataSet objects. In addition to the built-in support, it is easy to add support for additional extensions by implementing a custom build provider and registering it in Web.config.

  • Expression Builders. ASP.NET 2.0 introduces a declarative new syntax for referencing code to substitute values into the page, called Expression Builders. ASP.NET 2.0 includes expression builders for referencing string resources for localization, connection strings, application settings, and profile values. You can also write your own expression builders to create your own custom syntax to substitute values in a page rendering.

Performance and Scalability

ASP.NET is built to perform, using a compiled execution model for handling page requests and running on the world's fastest web server, Internet Information Services. ASP.NET 2.0 also introduces key performance benefits over previous versions.
  • 64-Bit Support. ASP.NET 2.0 is now 64-bit enabled, meaning it can take advantage of the full memory address space of new 64-bit processors and servers. Developers can simply copy existing 32-bit ASP.NET applications onto a 64-bit ASP.NET 2.0 server and have them automatically be JIT compiled and executed as native 64-bit applications (no source code changes or manual re-compile are required).

  • Caching Improvements. ASP.NET 2.0 also now includes automatic database server cache invalidation. This powerful and easy-to-use feature allows developers to aggressively output cache database-driven page and partial page content within a site and have ASP.NET automatically invalidate these cache entries and refresh the content whenever the back-end database changes. Developers can now safely cache time-critical content for long periods without worrying about serving visitors stale data.