Thursday, January 03, 2008

Accessing Master Page Properties from a content page

Accessing a property on a MasterPage from the content page. One merely has to check the namespace and the class name of the masterpage, which can be found in the code behind file. Just cast the Content Page’s Master as the class of the masterpage file which it uses, and then access the value.
One way of doing this in the content page,

int valueNeeded = ((MyNameSpace.MyMasterPageClassName)Master).MyProperty;

Or you can do this by doing like this in ContentPage.aspx page
<%@ MasterType VirtualPath="~/MasterPage.master" %>
Just below the Page directive and then you can access the proeprty in codebehind in content file as as:

int valueNeeded = Master.MyProperty;

Using these methods you can access a property of a masterpage file.

VS 2008 Features and support

The official name for the .NET Framework "Orcas" release will be called .NET Framework 3.5 (it includes the new LINQ support, integrated ASP.NET AJAX support, new ASP.NET data controls, and more).

Multi-Targeting

Past few releases of Visual Studio, each Visual Studio release only supported a specific version of the .NET Framework. For example, VS 2002 only worked with .NET 1.0, VS 2003 only worked with .NET 1.1, and VS 2005 only worked with .NET 2.0.

One of the big changes starting with the VS 2008 release is to support "Multi-Targeting" - which means that Visual Studio will now support targeting multiple versions of the .NET Framework, and developers will be able to start taking advantage of the new features Visual Studio provides without having to always upgrade their existing projects and deployed applications to use a new version of the .NET Framework library.

Now when you open an existing project or create a new one with VS 2008, you can pick which version of the .NET Framework to work with - and the IDE will update its compilers and feature-set to match this. Among other things, this means that features, controls, projects, item-templates, and assembly references that don't work with that version of the framework will be hidden, and when you build your application you'll be able to take the compiled output and copy it onto a machine that only has an older version of the .NET Framework installed, and you'll know that the application will work.

Creating a new project in VS 2008 that targets .NET 2.0. While creating a project you can notice with dropdown with different .NET framework in it. You can select what type of Framework you want to use.After you select the framewrork, it will automatically filter the project list to only show those project templates supported on machines with the .NET 2.0 framework installed. If you create a new ASP.NET Web Application with the .NET 2.0 dropdown setting selected, it will create a new ASP.NET project whose compilation settings, assembly references, and web.config settings are configured to work with existing ASP.NET 2.0 servers.

why use VS 2008 if you aren't using the new .NET 3.5 features?

Well, the good news is that you get a ton of tool-specific value with VS 2008 that you'll be able to take advantage of immediately with your existing projects without having to upgrade your framework/ASP.NET version. A few big tool features in the web development space I think you'll really like include:
  • JavaScript intellisense
  • Much richer JavaScript debugging
  • Nested ASP.NET master page support at design-time
  • Rich CSS editing and layout support within the WYSIWYG designer
  • Split-view designer support for having both source and design views open on a page at the same time
  • A much faster ASP.NET page designer - with dramatic perf improvements in view-switches between source/design mode
  • Automated .SQL script generation and hosting deployment support for databases on remote servers

And also, you can upgrade or downgrade to any version on .NET framewrok by pulling properties and selecting the desired framework you want. This will automatically remove the newer assembly references from your project, update your web.config file, and allow you to compile against the older framework (note: if you have code in the project that was written against the new APIs, obviously you'll need to change it).

What about .NET 1.0 and 1.1?


Unfortunately the VS 2008 multi-targeting support only works with .NET 2.0, .NET 3.0 and .NET 3.5 - and not against older versions of the framework. The reason for this is that there were significant CLR engine changes between .NET 1.x and 2.x that make debugging very difficult to support. In the end the costing of the work to support that was so large and impacted so many parts of Visual Studio that we weren't able to add 1.1 support in this release.
VS 2008 does run side-by-side, though, with VS 2005, VS 2003, and VS 2002. So it is definitely possible to continue targeting .NET 1.1 projects using VS 2003 on the same machine as VS 2008.

About the Enterprise Library 3.1

The Microsoft patterns & practices Enterprise Library is a collection of application blocks that can help simplify many common enterprise development challenges. This release of Enterprise Library includes application blocks for Caching, Cryptography, Data Access, Exception Handling, Logging, Policy Injection, Security and Validation.

Application Blocks are reusable, extensible source-code components that provide guidance for common development challenges

Enterprise Library is a collection of general purpose application blocksCaching, Configuration, Cryptography, Data Access, Exception Handling, Logging, SecurityEmphasis on Consistency, Extensibility, Ease of Use and IntegrationOriginally designed for .NET Framework 1.1 (January/June 2005 releases) and updated for .NET Framework 2.0 (January 2006 release)

New application blocks
  • Validation Application Block
  • Policy Injection Application Block

Improvements to existing application blocks

  • Data Access Application Block
  • Logging Application Block

.NET Framework 3.0 integration

  • Logging, Exception Handling and Validation Application Blocks

Configuration improvements

  • Visual Studio-integrated configuration tool
  • Environmental Overrides
  • Manageable Configuration Source

Automation

  • Application Block Software Factory
  • Strong Naming Guidance Package

Migrating from Earlier Releases
In general, applications built using Enterprise Library for .NET Framework 2.0 – January 2006 will function with the Enterprise Library 3.0 or the Enterprise Library 3.1 without the need for any code changes. It will be necessary to update the references to refer to the new assemblies and to update the configuration files to reference the correct version of the assemblies.

Get it from here.... Enterprise Library 3.1 Download

Monday, September 17, 2007

Credit Card Payment Processing with ASP.NET

Rick Strahl has published a excellent (and very comprehensive) new article on techniques to perform credit-card payment processing with ASP.NET. He also includes full source code examples (for both ASP.NET 1.1 and ASP.NET 2.0). You can check it out here.

If you are interested in ecommerce, then you should also check out the ASP.NET 2.0 PayPal-enabled Store Starter Kit that you can download for free from here (it is near the middle of the page). It provides a really easy way to get an e-commerce site up and running using ASP.NET 2.0, and has PayPal payment integration built-in.

Data Access Improvements with LINQ to SQL

LINQ to SQL is a built-in OR/M (object relational mapper) in .NET 3.5. It enables you to model relational databases using a .NET object model. You can then query the database using LINQ, as well as update/insert/delete data from it. LINQ to SQL fully supports transactions, views, and stored procedures. It also provides an easy way to integrate business logic and validation rules into your data model. Below are some of the articles I've written that explore how to use it:

Part 1: Introduction to LINQ to SQL
Part 2: Defining our Data Model Classes
Part 3: Querying our Database
Part 4: Updating our Database
Part 5: Binding UI using the ASP:LinqDataSource Control

You'll find that LINQ to SQL makes it dramatically easier to build much cleaner data models, and write much cleaner data code.