Free, Open-Source ASP.Net 2.0 Framework for Data-Driven Websites
A video version of this example is available on our weblog.
The output of this exercise will be a very basic website showing an updateable list of Chambers in the United States. It will make use of UnifiedASP’s User Authentication and Authorization modules so only users with correct permissions will be able to add, update, or delete new chamber records.
Before we get into building it, take a look http://sample.unifiedasp.net/USChamberSample1 so you can get a feel for the requirements. You can log in with the credentials admin/password. This data is reloaded every 30 minutes so any changes you make will be reset.
To complete this exercise, you’ll need to following downloads:
You’ll need access to a SQL Server database and Visual Studio will be helpful but you can extract the files from the solution into whatever IDE you prefer.
High-level steps for this exercise:
Here are detailed, step-by-step instructions for this exercise:

First, you’ll need to change the Connection String to point to your USChamberSample1 database.
When the code generator creates stored procedures, it prefaces them with a code so it’s easier for them to sort together if you have different teams or applications using the same database. In the Sproc Prefix field, type in whatever prefix you would like for stored procedures. In this case, we changed it to “ch”.
The code generator also places all classes in a namespace. You can specify the namespace in the Namespace field. In this case, we changed it to “USChamber”.
The code generator will work through a series of templates to create the stored procedures, classes, and pages for the tables you specify in the next step. By default, the template folder is at the root of the folder containing this executable. If you’ve moved the template folder or have different templates for different sites, you can change the folder here.
You can also specify a folder that the code generator will use to write the completed files. By default it will write to the Output folder at the root of the folder containing the executable.
For now, just leave these paths as the defaults.
If you will be generating code for the same application in batches, you can click on the Update Configuration button and it will store this as your default configuration.
After entering the appropriate information, click the next button. If anything is not correct, the application will throw errors and you can fix it. Now you should see the screen below:

From this screen, you can select tables you’d like to generate code for. Stored Procedures, Classes and Pages already exist for the App* tables, so you can just select Chamber and State and move to the box on the right. Your screen should now look like:

Now click your next button to see the screen below.

From this screen, you will configure how the code generator will handle the columns for each table. The code generator has set defaults for certain fields based on the meta-data in the database. You’ll need to make a few changes.
If you click on the ChamberName column in the Table Columns select list, it will replace the information in the Column Data box with data specific to the ChamberName column. The only change we are going to make now is to change the Label from “ChamberName” to “Chamber Name” because that is how we’d like the field labeled on the generated screens.
Now click on the City column. We would like this column to be a filter on the Chamber Search screen so you need to check the Include in Filters checkbox.
Now click on the StateId column, change its label to State, and click the Include in Filters checkbox so it too will be a filter.
Click on ZipCode and change its label to Zip, click on Phone Number and change its label to Phone Number, click on FaxNumber and change its label to Fax Number, and finally click on WebsiteURL and change its label to URL.
We are not going to make any changes to the State table or its columns because we will not use the generated screens.
Now, just click the Finish button and you should quickly see an alert of “The Code Generation has finished.” Click OK.
From here, you can close the code generator by clicking Cancel or the X button.
Now, if you look in the Output folder specified on the first screen, you will see four folders:
Let’s start by adding the generated stored procedures to your database:
CREATE PROCEDURE dbo.chState_GetAll AS BEGIN set nocount on select s.StateId , s.StateAbbr , s.StateName from State s with (nolock) order by s.StateName END GO
Your database is now ready to use so let’s turn our attention to the classes.
Now that the database and classes are in place, let’s get started on the pages:

Configuration Changes:
Now, we need to add the Chambers menu item. Since the look-and-feel of websites varies so widely, we fully expect you to build your own menuing for your applications. The framework does provide a simple menu that can be controlled in the MasterPage. We’ll add the Chambers link to this menu.
<%=getMenuLink("Chamber/Default.aspx", "Chambers", Nothing)%>
<ul>
<%=getMenuLink("Chamber/Default.aspx", "Chambers", Nothing)%>
<%=getMenuLink("AppUser/Default.aspx", "Users", "AppUser.Read")%>
<%=getMenuLink("AppGroup/Default.aspx", "Groups", "AppGroup.Read")%>
<%=getMenuLink("AppPermission/Default.aspx", "Permissions", "AppPermission.Read")%>
</ul>
Now, we need to make sure all users can see the Chamber list and detail screens. In many modules, you will want users who use the search and detail screens to be logged in and have the correct permissions so the code generator does this by default. That’s not the case in the Chamber module so we need to make a couple of small changes.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsGridEvent = True Then DoLoadData() End If End Sub
If myChamber.HasRecords = False Then
SmartRedirect("Chamber/default.aspx")
End If
The application will now function correctly so let’s fire it up. The other changes will make as we review the application.
Press F5 to launch the project in debug mode and you should see the Chambers list screen Chamber/Default.aspx.
As you can see, there are more columns in the grid than in the example you reviewed before. This is because the Code Generator adds a column for all columns in the table since it’s easier to remove ones you don’t need than add them. Let’s clean it up.
<asp:GridViewX runat="server" ID="grdChamber">
<columns>
<asp:HyperLinkField HeaderText="Chamber" DataTextField="ChamberName" SortExpression="ChamberName" DataNavigateUrlFields="ChamberId" DataNavigateUrlFormatString="~/Chamber/Detail.aspx?ChamberId={0}" />
<asp:BoundField HeaderText="Address" DataField="Address" SortExpression="Address" />
<asp:BoundField HeaderText="City" DataField="City" SortExpression="City" />
<asp:BoundField HeaderText="State" DataField="StateName" SortExpression="StateName" />
</columns>
</asp:GridViewX>
Once you are back on the search screen, click on one of the chamber names to view a detail record. The next requirement we need to take care of is to make the Website Url field a link instead of a label.
<asp:HyperLink runat="server" id="hlnkWebsiteUrl" />
hlnkWebsiteUrl.Text = myChamber.WebsiteUrl hlnkWebsiteUrl.NavigateUrl = myChamber.WebsiteUrl hlnkWebsiteUrl.Target = "_blank"
Now all of the basic functions are in place. All that’s left to do is log in and add the permissions for the Chamber module.
Now, when you go back to the Chambers module, you will see a link for “Add New Chamber”. If you click on it, it will take you to the add screen. You will also see Edit and Remove buttons from the Detail screens.
At this point, the application is functional and is exactly the same code as you saw in the sample application.
Is it perfect, production-ready code?
No way! But it’s a huge head start.