CHAN - Bloat free ASP.Net
Introduction | About | Roadmap | Changelog | Licensing | Reference | Download | Guides: Windows , Linux/Mono , Building
Building - SDK
This article has been usurped by the newer Building with Visual Studio Express page. The batch file used to compile the DLL used to contain the following call to CSC, it simply references a couple of system DLL's alongside the Chan DLL and recursively builds every source file under the current directory.
csc /t:library /out:..\bin\Chan_Demo.dll /r:System.dll /r:System.Web.dll /r:..\bin\Chan.dll *.cs
The Chan and Chan_Demo DLLs are built using the Microsoft .Net 2.0 SDK so the first thing you need to do to customise your Chan based site is to download and install that.
Once it's installed go to Start -> [All] Programs -> Microsoft .NET Framework SDK v2.0 -> SDK Command Prompt. You'll need to navigate to the source dir, which in the case of the Chan_Demo site would normally be at C:\inetpub\wwwroot\chan_demo\src. All you'll need to do to build it is to run the build.bat batch file by typing "build".
The \bin sub-folder will now have a new version of Chan_Demo.dll alongside the existing Chan.dll. And if you refresh your http://localhost/ you'll notice a few-second delay as IIS notices the new version and loads it.
Open /src/ and create a new, empty text document called Home.cs alongside the existing Simple_Form.cs etc. Open it in your text editor and enter the following:
using System;
using Chan;
namespace Chan_Demo
{
public class Home : Page_Base
{
protected Chan.Controls.Label lblMyLabel;
protected override void Page_Load()
{
lblMyLabel.Text = "Hello World!";
}
}
}
Let's break this down before we go any farther, first there are only two "using" statements, one for the .Net System and one for Chan. Do not include System.Web.UI as the objects in the Chan namespace will clash heavily with the onese in the Web.UI one.
Next it opens the "Chan_Demo" namespace and creates a class named "Home" in there which inherits from "Page_Base". Basic Page simply parses and loads the HTML template file that the Chan Demo site uses, and because we want to retain that template for the Home page we inherit that. Future Chan releases may fold templating within themselves but at the moment it's up to the developer to police their own templating. (Look inside Page_Base.cs if you like, you'll see it does very little other than exposing a Page_Template property and passing that to the underlying Chan.Page class via a special Template_Init() event.)
Once inside the Chan_Demo.Home class we declare that we have a Label object (more on this later) and create the Page_Load function. If you are used to Visual Studio based ASP.Net development this won't look too out of this world to you, but you may notice that the Page_Load function here is a "classic" overload function with no parameters: Chan does not use events. If you were to inherit from Home.cs to create a new class with it's own Page_Load function you would need to call base.Page_Load() within that for everyting to fire correctly. This is by design, don't be afraid!
OK, so back to that Label we declared above, we need to mirror that declaration in the ASPX page that your visitors will actually see. Open /Home.aspx and add a Chan Label control, anywhere you like but probably after the existing text. Again the syntax is mostly the same as Visual Studio's HTML view:
<Chan:Label runat="server" id="lblMyLabel" />
Finally we'll need to tell the ASPX to use our new "Home" class instead of the default "Page_Base" class, this is at the top of the ASPX file:
<%@ Page Language="c#" Inherits="Chan_Demo.Home"
Open up your SDK prompt and run build again, provided there are no errors you should be able to refresh your browser and see "Hello World!" beaming back at you. Now that you've built your own Chan-driven page take a look at the simple form examples within the Demo site and swot up the online Reference.