Archive

Archive for the ‘.net’ Category

Simple Asp.net StringBuilder Literal Control

August 13th, 2009 No comments

It always annoys me that Literal controls only have a text property. This means you have to do:

Literal.Text += "Add me";

Whereas a StringBuilder would make much more sense when building lists etc. Heres a stupidly simple control that just supplies a string builder as the text property. Not exactly a good code example(shouldn’t override the text property etc)  but ideal for this situation. I will write a proper control later ;) Read more…

Categories: Asp.Net Tags:

Creating a CMS Framework – The Plan

May 18th, 2009 No comments

I’ve now written 4 cms’ and have decided as a personal project to create a core system that can easily be adapted to many tasks.  Over the past 4 cms’ I’ve used the same code a lot and created a central core of utils (imaginatively called Gist!) but I want to go a step further and have a central system I can use straight off.

Read more…

Categories: Asp.Net, cms Tags:

Simple way to create a singleton

April 28th, 2009 No comments

Found this is microsoft official line on creating a singleton, much simpler than the normal GOF way :)

// .NET Singleton
sealed class Singleton
{
private Singleton() {}
public static readonly Singleton Instance = new Singleton();
}

Categories: .net, c# Tags:

Create controls dynamically from database

February 11th, 2009 No comments

In my cms’ I usually have the option of creating controls from the database. This is just a simple use for reflection but allows me to add controls to page just by adding a new row.  If its one of my controls it supports a persistance system that allows the control to save and restore itself easily.

Read more…

Categories: .net, c# Tags:

Rendering Paths as a nested List

February 4th, 2009 No comments

Keeping tree data in a database can be a nightmare. There are a number of techniques to achieve it but they are all either unwieldy on the sql side (multiple joins) or on the data side (binary trees). I needed an easy way to render a tree out in a single read from the db.
I achieved this by just having a path field in the table, ordering by it and then dumping it out with the following routine. Needs more work but ok for the mo :) Would need to change to writer instead of StringBuilder and I need to sort out the items that appear at the top (would appear under the folders in a treeview) Read more…

Categories: c# Tags:

Using static properties as class wide data

February 3rd, 2009 No comments

This is one of those things that is so obvious I wonder why it never occured to me before!  If you declare a member as static the compiler only creates one member instance across all class instances.

class ClassWideStatic
{
  protected static int NoOfInstances;
  public ClassWideStatic()
  {
    //setting NoOfInstances here will set it on ALL instances
    //effectively resetting it, but modifying it is fine
    NoOfInstances += 1;
  }
  static ClassWideStatic()
  {
    //This is a special constructor that is only called when
    //the first instance is created
    NoOfInstances = 1;
  }
} 
Categories: c#, Theory Tags: