by aherrick
29. December 2008 01:39
I created this template mostly for myself so that when I am creating web demos/test projects I have a wired up SubSonic project ready to go. Hopefully it will be useful for someone interested in getting started with SubSonic. Setup is currently running SubSonic 2.0.3. I have found this to be the most stable version to date. I will be putting up a version 2.1 (and hopefully 3.0) template soon.
Rob Conery, SubSonic creator, has some great videos on getting started as well. Check it out at http://subsonicproject.com
This solution is completely wired using ASP.NET 2.0 and SQL Server 2005. I broke the solution up to into two projects (DAL and WEB). This way seems to work well and allows for abstraction. In order to run, make sure you are running the Northwind database (just run ins).
Good luck and let me know if you have problems running the solution.
SubSonicNorthwindDBTemplate.zip (869.28 kb)
InstallNorthwind.zip (274.19 kb)
868b02c9-1772-45c3-b23f-08ddd0ffcd2f|1|5.0
Tags:
by aherrick
22. December 2008 07:14
Working on a project I need the ability to programmatically change the web application's associated master page (and associated CSS). Most of the pages in the application were content pages (derived from the content page) however some were just static pages. Since there was no MasterPage assoicated with these static pages, dynamically assigning the CSS was the next best option.
I created a BasePage for ALL pages in the application to derive from.
For the ContentPages (pages that point to a MasterPage) I created a method in the BasePage to assign the necessary master page. This method is called in the Page_PreInit method of the content page. See below.
protected void Page_PreInit(object sender, EventArgs e)
{
// set master page
this.SetMasterPage();
}
SetMasterPage is a simple method to dynmically change the MasterPage...
public void SetMasterPage()
{
// change master page
// will return random number between 1-3...
int masterPage = RandomNumber(1, 4);
string fullMaster = ResolveUrl(string.Format("~/Site{0}.master", masterPage));
this.MasterPageFile = fullMaster;
}
Dynamically set the CSS on the static pages in a similar matter. In the code behind of the specific page, , call SetCSS in the Page_Init method. Dynamically setting the CSS is very easy too...
public void SetCSS()
{
// set CSS
// ALL CSS has to be set programatically...
HtmlLink css = new HtmlLink();
int cssNum = RandomNumber(1, 3);
css.Href = ResolveUrl(string.Format("~/StyleSheet{0}.css", cssNum));
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}
Really that's all there is to it. This code can be tweaked to suit your needs. This gives a lot more flexibility than simply dynamically changing your CSS file.
Attached is the code
ControlMasterPagesProgramatically.zip (34.59 kb)
f41c0785-394e-474b-b011-8d615b7e197f|1|5.0
Tags:
by aherrick
9. December 2008 11:11
I am releasing this application I created to help me organize my music collection. It takes multiple paths and combines ever directory under each path into a single txt/csv file sorted alphabetically. I had a little fun with some of the validation and colors to make it work a little more smoothly.
Usage:
- Select paths using Add
- Select output format (txt or csv)
- List is generated to same directory .exe is located
Attached is the .exe and full source code. It is free for distribution and please feel free to tweak to your needs!
If I tweak this in the future I will post the updated code, consider this V1.0
Enjoy!
DirectoryListV1.0-FullSRC.zip (73.37 kb)
DirectoryListV1.0EXE.zip (12.18 kb)
by aherrick
3. December 2008 06:34
I was working on a project and was looking for more control over the elements I was creating in the HTML. More specifically, I had a MasterPage setup and I wanted all pages to have the same background image throughout the site.
Simple. Add a runat=server to your markup. See below.
<div id="bgimg" runat="server">
</div>
You now have control of this element from the code-behind.
To add a background image to the div, you could do something like this:
bgimg.Style[HtmlTextWriterStyle.BackgroundImage] = ResolveUrl("~/images/bodyback.jpg");
The only thing to realize is what your generated markup is. Asp.Net will auto-generate this tag to prevent naming collisions. Just look out for it if you are trying to style the element with CSS or call it using javascript.
<div id="ctl00_bgimg" style="background-image:url(/HRR/images/bodyback.jpg);">
</div>
Enjoy!