Introducing Visual Studio .NET 2008 – Top 10 Features

27 03 2008

After a long beta period Microsoft pushed Visual Studio .NET 2008 (code named “Orcas”) out to MSDN in November – keeping their promise to deliver it by the end of the year. DevelopMentor has been using Orcas in many of our .NET classes for a while now and I for one, am pretty excited that it’s finally here. There are a ton of new features and enhancements in this release that make it almost a no-brainer to upgrade – I thought I’d take a moment and list my top ten favorites in no particular order:

WPF designer (“Cider”)

I spend a lot of time on a rich-client island and compared to the embarrassing support for WPF provided for VS2005 (through an add-on) VS2008 just plain rocks. Not only does the designer just work, the XAML intellisense is full featured and driven through a real XAML parser and not an XSD file. That means custom types and namespace completion actually function as you would expect them to! The visual designer and XAML views stay synchronized and “mini” thumbnails and scaling bars are used to help you see what you are building. You can also see how the new Cider environment has borrowed from Blend – a Search box is present to filter properties down and the selection in the XAML pane is synchronized with the visual designer so if you highlight a tag, it selects the appropriate object in the visual pane

WPF and Windows Forms integration (“Crossbow”)

Hand in hand with the designer view, VS2008 improves the designer experience for Windows Forms to WPF integration. Specifically, ElementHost is now present in the toolbox and you can drag and drop WPF user controls right onto your Form! You get a live preview of the control and can edit the content right in the designer

ClickOnce improvements

Microsoft introduced a simplified way to deploy Windows Forms clients from the web with Visual Studio 2005 called ClickOnce. With 2008, they’ve improved the experience by allowing deployment through FireFox (previously only IE was supported), better file associations so your application can be launched by activating a data file, better support for certificate expiration and changing the deployment location without resigning the application and support for Office add-ins and WPF XAML Browser application deployment.

 Multi-framework targeting

This release of Visual Studio has a much-needed feature that I wish had been there before – the ability to target multiple versions of .NET. Specifically, you can select your target framework (2.0 SP1, 3.0 or 3.5) and the project types, toolbox, references, intellisense and features will be appropriately set to that version. This selection can occur during project creation – in the project templates dialog or on the project properties dialog. Be aware that selecting .NET Framework 2.0 actually means 2.0 SP1 and not the original .NET 2.0 framework released with Visual Studio 2005.

Better Intellisense support

Web developers benefit from this release too – Visual Studio now has intellisense and code completion support for JavaScript! It’s smart enough to look at the underlying type currently assigned and correctly infer the methods which are available. So, for example if you assign a numeric type, the dropdown will be populated with the proper methods available for the type.

Visual Studio will also look at the comments applied to your methods – just like in C# and VB.NET, it will pull descriptions out of XML based comments on your JavaScript methods and display descriptions as tooltips when you are navigating the intellisen se dropdown.

Another cool feature added to intellisense is the filtering applied – now if you press a letter and start typing, it will begin to restrict your choices displayed, not just scroll to that section. This filters the output and makes it easier to find what you are looking for.

 Organize your “using” statements

Visual Studio now has the ability to organize your using statements. As a project evolves, you often end up with a ton of using statements at the top of each file which are not really being used – either because the project template added it, or because you originally did use something from that namespace which was then removed later. Now you can right click on your using statements and sort and/or remove unused namespaces

 Refactoring enhancements

The refactoring support was a welcome addition to VS 2005 – and Microsoft has enhanced the support in 2008 to support C# 3.0 features and allow you to refactor anonymous types, extension methods and lambda expressions.

 C# 3.0 support

Speaking of C# 3.0, that has got to be one of the coolest features – functional programming seems to be all the rage these days and introducing these features into C# 3.0 will allow you to be the coolest programmer on your floor. Things like automatic properties, lambda expressions (which reduce your typing for anonymous delegates), partial methods, anonymous types and extension methods will radically change how you can build applications. They can seem weird at first for some people, but don’t be afraid of them! They will cut down your typing and provide for some really cool ways to enhance and evolve your projects.

Visual Studio Split View

It is becoming increasingly more common to have multiple monitors on developers desks. Building on the “split” window feature of VS 2005, Visual Studio 2008 now allows you to tile the window horizontally or vertically so you can split your design and code view across monitors! This works in any of the designers (ASP.NET, WinForms, WPF, etc.)

Debugging the .NET source code

There are actually several debugging enhancements (try debugging JavaScript on the client-side for example – it works great!) but I think the coolest feature by far has got to be the debugging enhancements which will allow you to actually debug into the source code of the .NET framework. Scott Guthrie announced a few weeks ago on his blog that they intend to release the source code under the Microsoft Reference License. As part of that release, VS2008 will have integrated debugging support so that you can step into the framework libraries (ever want to know why your DataBind isn’t working??). Visual Studio will automatically download the source file from Microsoft’s server and you will get full watch and breakpoint support. This isn’t quite ready yet, but it’s coming soon and promises to be one of the biggest timesavers added to Visual Studio!

There are a ton of other features that make VS 2008 a worthwhile upgrade – you can experience it yourself by downloading a copy at no cost today Scott Guthrie’s Blog (Express editions have been released) or upgrading from MSDN. VS 2008 co-exists just fine with 2005 and 2003 but be aware that the project format has changed and it’s not backwards compatible, so sharing projects with your coworkers may be slightly painful for you until everyone moves to the new release as you will have to maintain two project and solution files.

Mark started his “official” professional career working with the OS/2 product – it was a fun time filled with lots of kernel debugging and low-level x86 goodness. He had his first real exposure to Windows programming when he worked for Micrografx, a small graphics company in Texas. He worked with a small, talented team of developers providing a simulation layer for OS/2 that allowed Windows applications to run natively on Presentation Manager. Forcibly immersed in Windows, he eventually transitioned to that environment and worked on a variety of projects, including a very popular screen saver titled “AfterDark” (flying toasters ruled!). He decided he liked the independent contractor life so began working with larger companies like Exxon/Mobil, Fidelity Investments and Verisign, designing and building distributed systems and scalable server-side infrastructure. Being in the telecom headquarters of the south, he has spent a fair amount of time in the telephony space, helping companies all over the world become TAPI-enabled through a variety of tools and code that he both sells and gives away through JULMAR.COM. In 2007, Mark became the CTO for DevelopMentor – responsible for mapping out the technical curriculum and direction for the company. He is still involved in both authoring and teaching .NET and lately has spent a lot of time working with Silverlight, WPF, and WCF.





How to pass values from one page to another page without using sessions and query string

14 03 2008

Passing values in the form to another page is a frequently used and the most common task that is done in the web applications and intranet applications. There are many ways by which you can achieve this task. Some of the ways by which you can do this task is to use the Querystring and the session variables. The other method that is used is the Server.Transfer method which we will be seeing in this article. In the ASP.Net each form is posted onto itself and for transferring the control to another form you can use the Server.Transfer() method with some tweaks.

One important aspect that you should know is the Server.Transfer() transfers the control to another form on the server side itself. You might have used another method called the Response.Redirect(). This method uses the browser to make a new request to another page. You will be passing parameters to the Server.Tranfer() method. The parameters that are transferred to this method are the name of the web form to which the control is passed and a Boolean value to preserve or not to preserve the current form state in the new form. These two values are passed while using the Server.Transfer() method.

The following code is used to transfer the control to a destination page.

Server.Transfer(“destination.aspx”, True)

You might see that the above code contains the name of the page to which the control is transferred and a Boolean value ‘True’ to indicate to preserve the current form state in the destination page.

There is one more task that is to be done to make the above code to work properly. If you execute the above code alone you might encounter an error. The error that is caused is due to an attribute called the EnableViewStateMac which is set to True already in the page directive. You have to check the Boolean value of this attribute. It has to be False to make the Server.Transfer() method work properly. You have to check this attribute in the destination page to which the control is transferred. Once you set this attribute to False the Server.Transfer() method is executed properly.

Let us say that you want to transfer the control to destination.aspx. Then you have to see that page directive looks as given below:

<%@ Page Language=”vb” EnableViewStateMac=”False”%>

The important attribute to note is the EnableViewStateMac. Once you set this attribute value to False you can easily access the form values of the source form in the destination.aspx. Suppose you have a TextBox control in the source form. The ID of the textbox control in the source form is TextBox1 and you use the Server.Transfer method to transfer the value of the TextBox1 to the destination.aspx. You can access the value of the TextBox1 in destination.aspx as given below:

Response.Write(Request.Form(“TextBox1″))

provided you set the value of the EnableViewStateMac attribute properly. This is a simple example of accessing the values of controls in source form in another web form.

Consider a scenario where you have lots of controls in the source web form and you want to display the values of these controls in the destination form. One of the way is to use the Request.Form() method to retrieve the values and assign them to the control you need. There is another way that is easier to achieve the same task. Just name the IDs of the controls in the destination web form to that of the source web form. That’s it! And the controls are populated in the destination form with the values of the source web form.

The code given below is an example of the above scenario.

Source.aspx


txtName.Text = “Peter”

Server.Transfer(“Destination.aspx”, True)


Destination.aspx

<%@ Page Language=”vb” EnableViewStateMac=”False”%>


‘Name (ID) a textbox control in this page to txtName as in the Source.aspx
‘You will see the value of the txtName control in this page displayed automatically.

This is an easy method to access values of the source web form in another web form. As we have discussed earlier the Server.Transfer method is used to transfer the control in the server side itself without the need for the browser to make another request. Hands on experience on these methods would give you a clear idea on this.