views:

68

answers:

6

Hi all!

I've come from a Classic ASP background, done it for years and years and moving to .net has been way overdue, so I've started to learn .net.

It's very different to say the least! It's structured a lot differently, and seems to work a lot differently, it's a huge leap upwards. However, it is appearing to me to be more and more awesome.

I've had a quick search and can't find any similar questions, so I've created this one as a community wiki, if you could list the pitfalls/differences or whatever you think it relevant in your responses it might be helpful to a lot of people.

So in summary, what are the main differences/gotchas moving from Classic ASP to ASP.net? (c# or VB.net). Please don't just list language features of .net, it needs to be in the context of someone moving from one to the other.

Thanks!

A: 

Includes

Good design from Classic ASP comes from using include files to modularise your code.

In .net, this is not possible in the same way as it is based on an object orientated hierachy.

Tom Gullen
You should really ditch server side includes altogether—if for no other reason than that Intellisense goes haywire when you're editing an include file with no `@Page` declaration (if you're working with Visual Studio, that is).
Mark B
A: 

If you are jumping into Webform, then read up and learn about ASP.NET's ViewState; how a page persists across post backs. If you are going to dabble in ASP.NET MVC, read about Model View Controllers. In either framework, ASP.NET is an object oriented language where classic is not.

gnome
C# and VB.NET are object oriented languages; ASP.NET is itself a framework.
Mark B
correct, my error.
gnome
+1  A: 

There are a bunch of useful articles available at your favourite search engine. You will need to answer some questions for yourself to start with (http://www.google.co.uk/#hl=en&source=hp&q=transition+from+asp+to+asp.net&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=a53e9ae07f1cc2a8)

Are you going to use ASP.NET Web Forms or ASP.NET MVC? This blog has a good article on the difference (http://weblogs.asp.net/shijuvarghese/archive/2008/07/09/asp-net-mvc-vs-asp-net-web-form.aspx). Both have value for their purpose.

Are you going to try and port your existing code or make a clean break?

Razor is a new syntax for ASP.NET which I highly recommend. It gives a very natural feel to combining html and c# code syntax. This blog (http://blogs.msdn.com/b/davidebb/archive/2010/07/07/how-webmatrix-razor-asp-net-web-pages-and-mvc-fit-together.aspx) has a good post on one of the latest stack for MS including Razor.

Learn object oriented programming. It is pretty crucial.

Got to http://www.asp.net it is a great resource. use the tutorials and read other peoples code.

EDIT: I forgot to mention, if you are going to focus on ASP.NET WebForms please learn the page life cycle as not understanding this leads to a common class of bugs around dynamic controls. http://msdn.microsoft.com/en-us/library/ms178472.aspx

btlog
+1  A: 

I'm assuming that you are moving to WebForms (but you might consider to jump straight to MVC or Silverlight as WebForms is on its way out)

FWIW when I made the move the following were probably the main gotchas:

  • Resist the temptation to use classic conventions <%=, #include
  • Resist the temptation to edit the ASPX file by hand - try to just use the designer
  • You will need to get up to speed with OO if you haven't done so already
  • For WebForms, you will need to take a VB6 / WinForms approach to button handlers etc
  • Use the ASP.NET controls - you won't need to fuss about micromanaging the state of controls as you did in ASP Classic

Take in some videos: http://www.asp.net/general/videos#Videos%20on%20Migrating%20to%20ASP.NET

nonnb
+1  A: 

I did the same thing quite a few years ago. I can't say I found any “pitfalls”; in fact quite a lot of the annoying thngs that always used to catch me out in classic ASP just disappeared when I moved on to ASP.NET.

I think the biggest difference was moving from ASP/JScript to strongly typed C#. It forced me to be less lazy when declaring variables and as a result I encountered far less bugs relating to scope or data type conversion. Writing reusable, object oriented code is also much easier in C#.

If you're just getting into it, I would advise you (and this is just my opinion) to steer well clear of ASP.NET Web Forms and just jump straight into MVC. It takes a while to readjust your brain to work in the MVC paradigm, but once it “clicks” it all just makes total sense.

We recently got this book at my office, and I thoroughly recommend it; don't let the “Pro” bit put you off, it starts right from the basics and was very plain and easy to understand.

Mark B
I seem to have accidently started developing in web forms, I'd seen MVC mentioned but hadn't looked it up at all, how bad is it to use webforms? I didn't realise there was such a split.
Tom Gullen
Yes, it's a completely different way of working, but it allows for much easier separation of concerns. There's nothing _terrible_ about Web Forms, it's just that MVC seems much, much cleaner to me, not to mention more testable. Have a look at [this article](http://msdn.microsoft.com/en-us/magazine/dd942833.aspx) and [this article](http://www.devcurry.com/2009/09/difference-between-aspnet-webforms-and.html) for some pros and cons of both approaches.
Mark B
Thank you, i'm going to stick with webforms for this project for now then move on to MVC at a later date.
Tom Gullen
+1  A: 

When I started in Classic ASP I hadn't had any other programming experience. I hadn't ever built anything in windows forms or console applications. So, when I moved to asp.net, it took me a while to figure out what the heck was going on with code behind and control event handlers. In my first few projects I was trying to code like a Classic ASP programmer. I would do silly things along the lines of...

public void Page_Load(object sender, EventArgs e) {
    if (Request.ServerVariables["REQUEST_METHOD"] == "POST") {
      string myHtmlOutput = "";
      string firstName = "";
      if (Request.Form["ctl0_MainContent_FirstName"] != null) {
        firstName = Convert.ToString(Request.Form["ctl0_MainContent_FirstName"]);
        myHtmlOutput = "<h1>Hello "+ firstName +"</h1>";

        Response.Write(myHtmlOutput);
      }
    }
}

Instead of the WebForms way...

public void Button1_Click(object sender, EventArgs e) {
    if (!string.IsNullOrEmpty(FirstName.Text)) {
      MessageLiteral.Text = string.Format("Hello {0}", FirstName.Text);
    }
}

I honestly think that if asp.net MVC had been around when I moved from Classic ASP, I would have had an easier time getting the hang of it because I wouldn't have had to spend so much time learning all of the asp.net abstractions.

jessegavin