ASP.NET CodeBehind and Code Re-Use Using Inheritance
CodeBehind is when the HTML portion of the page that contains the HTML mark-up and the server side code are separated into two files. This allows designers to make modifications to the HTML without messing up the programmes server side code. It also allows programmers to edit their code without messing up the designers HTML. When the server side code is compiled into an assembly (DLL) each section of the page can even be published to the server separately.
Dreamweaver users do not have native support for CodeBehind like Visual Studio .NET users have, so this article will go some way towards redressing the balance.
This tutorial will guide you through implementing ASP.NET CodeBehind and Code Re-Use techniques using a .NET feature known as Inheritance. You will learn how to define and use your own class files, about re-using and extending existing .NET Classes using Inheritance. For one example the article will outline how to create a new type of Button Server Control that derives from the standard ASP:Button Server Control, and extends its capabilities by adding an “Are you sure you want to do that?” prompt upon clicking the button. You will also learn how to implement CodeBehind in your ASP.NET applications using only Dreamweaver and how to compile your code into assembly (DLL) files.
The following topics will be covered:
- An introduction to Classes in .NET
- An introduction to Class Inheritance in .NET
- An introduction to ASP.NET CodeBehind
- Implement CodeBehind Classes in a page
- Utilize Code Re-Use with CodeBehind Classes
- Extending the Button Server Control
- Compiling the Button Server Control
- Using the extended Button Server Control in a page
As usual, Kevin gives his sample code in both C# and VB.NET - the two most-used languages for coding ASP.NET pages.
I live in Perth, Scotland and am senior programmer with WebXeL.com Ltd. I have been involved in computer programming since 1990, web based programming using ASP since 1997 and have been building ASP.NET applications since ASP.NET Beta 2 was released.
I have been an avid Dreamweaver user since Version 1 was launched and with the release of MX have moved into developing extensions. WebXeL run a website dedicated to the development of free and commercial Dreamweaver MX extensions for ASP.NET, the site can be found at http://www.webxel-dw.co.uk.
See All Postings From Kevin Marshall >>
Reviews
Non-tested Examples
The artitcle seemed useful enough but the C# examples were riddled with errors. I skipped over the VB examples so I'm not sure about those.
Two examples of C# errors are:
- page 4: first example should read "new PersonsName()" not "new PersonsFirstName()" as that was not the name of the class you created in your example on page 3
- page 6: missing { to start the WebForm1 class
I'm only up to page 6 so far but not a good sign. I would hardly care about little things like this, but to expect people to pay per article like I did, one should expect a higher level of accuracy.
RE: Non-tested Examples
The code has been updated.
Martha Graham
DMXzone.com
Still full of errors
I followed the C# examples and wasn't impressed with the number of errors. Even after the code was apparently updated. I would think again about paying for premium content is this is the level of accuracy put into articles.
RE: Still full of errors
What error did you find?
See all 8 Reviews You must me logged in to write a review.