ASP.NET Basics: Delegates vs. Interfaces

The reason for using interfaces is that when exposing properties you want clients to only use what you allow them to, but save yourself the work of recreating a whole other control to do what NavigatorControl is already doing.

Notice now that the main page is not involved since all needed actions are happening on the two user controls.

using delegates

class NavigatorControl() : UserControl
    public event EventHandler SelectedItemChanged;

     //your navigation button handler
    protected void NextItemButton_OnClick(Object sender, EventArgs e)
      //Check for event registrations
      if(SelectedItemChanged != null)
        //passing a reference to the user control itself here with ‘this’
        //but it could be a reference to the actual item
        SelectedItemChanged(this, EventArgs.Empty);
// And then wireup that event in the parent user control:

public class ParentControl : UserControl
  protected void Page_Init(Object sender, EventArgs e)
    myNavControl.SelectedItemChanged += new EventHandler(myNavigatorControl_SelectedItemChanged);

  //the handler for the item changed event
  protected void myNavigatorControl_SelectedItemChanged(Object sender, EventArgs e)
     //and your parent level save…

Another solution which is slightly more complicated but more controlled.


public interface ISave{    void Save();}public class Navigator : System.Web.UI.UserControl, ISave{     public void Save()     {     }}// To make things really simple you could just// reference the control directly from the page// and call its save methodpublic class Profile: System.Web.UI.UserControl{    public ISave SaveControl    {        get { return ucNavigatorControl as ISave; }    }    public void ButtonClick(object sender, EventArgs e)    {        SaveControl.Save();        // Do something else    }}


Don’t depend on others to make things happen

Do it yourself

Creating, planning, financing, producing and marketing.

  • Personal and professional projects benefit each other.
  • Creating platforms is powerful – participation & collaboration

When you have a good idea, protect it.  Don’t show it to anybody and keep it to yourself.  Do the above and make a lot of money out of it.

BlackBerry Torch 9800: Top Features

I’ve been using a BlackBerry Torch 9800 for a few weeks now and think it’s a fantastic device.  Here are my favourite things about it; taking into account both the new device and BlackBerry OS 6.

  1. It’s as solid as ever
    Despite the new features, the operating system still feels as solid as ever.
  2. Battery life still decent
    Even with the larger screen and updated OS, my battery has been lasting a good few days.
  3. Multi-touch
    A bit jerk-o-matic at times, but a great implementation.
  4. The home screen
    Frequently used apps is a very nice touch and very intuative
  5. Modal style popup commands on tap/hold
    This is a really nice way to present lots of information
  6. Better music player & file management
    File management was pretty hideous on earlier versions of BlackBerry OS so the new interface is refreshing.
  7. A half decent browser
    Not fantastic, and still not in the same league as WebKit (Android) but very good nonetheless.
  8. Nice graphics & display
    UI was always BlackBerry’s weak point. It felt solid but was never too aesthetically pleasing. OS 6 changes this.

Do you need be creative to create?

I just watched a great video at 99% by Michael Bierut called 5 Secrets from 86 Notebooks and it got me thinking.

Do you need to be a creative person to take an idea to market?

After watching Michael’s video, I believe that a degree of creativity and a holistic approach to delivery are two vital ingredients to take an idea from concept to creation, but not nessesariliy the type of creativity and invention traditionally associated with entrepreneurship.  It is inspiring to watch someone open up that has made such an positive impact on the design community in general and Michael’s presentation certainly goes some way towards answering my question.

Elliot Eisner defines four different types of creative people in "A Typology of Creative Behavior in the Visual Arts“ (pages 323 – 335)

  • Boundary Pushing (the rules are too constraining) 
  • Boundary Breaking   (the rules are the problem) 
  • Aesthetic Organizing (order and beauty from chaos)   
  • Qualitative organizing.  The need to produce order, harmony, and unity.  Differs from the others in that novelty is not required.

Most of the people I know can be defined by the different "creative” types defined by Eisner above, meaning that those budding entrepreneurs, developers and designers who simply want to see their idea through from concept to creation should be able to do just that.  I believe there are a few simple rules to follow to avoid being zapped up by the low-energy stage that inevetably comes after the excitement of a new concept or idea starts to wear off.

If you have a good idea, you should:

Protect it

Don’t show it to anybody and keep it to yourself.

Don’t depend on others to make things happen

Do it yourself and stay in control but get good people to help you.

Don’t give up: Some things just happen

Whether it’s hitting a brick wall in your design or hitting that low in a project, it’s about anything that can’t be changed, in particular the things you reflect on but where reflecting doesn’t have positive benefits.

Have fun and step back

Spending more time stressing about petty things than looking forward and remembering why you’re working on your idea is bad. If you don’t have a piece of glass embedded in your forehead, then enjoy it and make it work *now*.  Take time to step back now and again in order to retain your creativity.

Don’t hurt anyone in order to achieve your goal

Share your idea and try to make money out of it, but recognise those who help you and share the rewards accordingly.

See it through

Too many designers and creative people are guilty of failing to see projects through to launch.

Be a finisher

Create, plan, finance, produce and market your idea.

Even if you work a 9-5 job and feel you’re stuck in the grind, then you can still make your idea work through:
  • Developing it as a personal project – personal and professional projects benefit each other as you learn development skills and techniques which you can apply to your work.
  • Creating platforms is powerful and good for the mind – participation & collaboration is key!
Good luck!

ASP.NET Security Basics: Caching Roles

Just a quick “request” post covering the basics of caching user roles in an ASP.NET application using forms based authentication.

Role based authentication & authorisation is an important part of most modern web applications.  After successful authentication of a user, an authorisation process must take place to determine which areas of the application the user has access to.

To implement the basic role based security, there are three points to be considered. In this example we are returning a list of roles from a database for a particular user.

We can then add a web.config to each directory we wish to protect in the following format.

<authorization> <allow roles="role1,role2"></allow>
<deny users="*"></deny></authorization>

Application_AuthenticateRequest is defined in Global.asax and will be accessed each time a web request is made if your application. In order to save a database trip for each time you’re grabbing your roles, it’s best to use a cached mechanism for this:

   Try            If HttpContext.Current.User IsNot Nothing Then                If HttpContext.Current.User.Identity.IsAuthenticated Then                    If HttpContext.Current.User.Identity.AuthenticationType <> "Forms" Then                        Throw New Exception(String.Format("You attempted to authenticate with {0} but only forms authentication is accepted.", HttpContext.Current.User.Identity.AuthenticationType)                    End If                    Dim userId As System.Security.Principal.IIdentity = HttpContext.Current.User.Identity                    ' If the roles aren't in cache, do it now.                    If System.Web.HttpContext.Current.Cache(userId.Name) Is Nothing Then						' Just a simple example using a dataset!                        Dim dsRoles As DataSet = SomeStaticClass.GetRoles(User.Identity.Name) ' Get roles as a comma delimited string                        Dim roles As String() = New String(dsRoles.Tables(0).Rows.Count - 1) {}                        For row As Integer = 0 To dsRoles.Tables(0).Rows.Count - 1                            For col As Integer = 0 To dsRoles.Tables(0).Columns.Count - 1                                roles(row) = dsRoles.Tables(0).Rows(row)(col).ToString()                            Next                        Next                        ' Usually this information will be collected from a database.                                   ' One hour expiration time                        System.Web.HttpContext.Current.Cache.Add(userId.Name, roles, Nothing, DateTime.MaxValue, TimeSpan.FromHours(1), System.Web.Caching.CacheItemPriority.BelowNormal, _                         Nothing)                    End If                    'Assign the roles to the user in the current security context                    HttpContext.Current.User = New System.Security.Principal.GenericPrincipal(userId, DirectCast(System.Web.HttpContext.Current.Cache(userId.Name), String()))                End If            End If        Catch ex As Exception            Response.Redirect("/MyErrorPage")        End Try