Bracket styles: Allman vs. K&R

February 28, 2012 at 3:37 PMMadestro

I have been coding for a number of years now and most of the code I have come across (I would say 98%, no exaggeration) is in Allman's format.

For those of you who are not familiar with these bracket styles (or maybe you are but don't associate the name with the style), Allman's format is about putting the brackets each in its own line:

if (a == b)
{
     return true;
}
else
{
     return false;
}

While K&R is about putting the bracket at the end of the control statement:

if( a == b) {
     return true;
} else {
     return false;
}

I personally like Allman's. In my opinion it's totally easier to read. This of course is my personal preference. Either method [obviously] works and produces the same result, but I do find having to read K&R style annoying. So annoying in fact that I decided to write this post... :-)

Thoughts?

Posted in: General Development

Tags:

ASP.NET MVC lifecycle

February 23, 2012 at 4:47 PMMadestro

I was working on something and needed to refer to the ASP.NET MVC lifecycle so I went out there and found the following information which I have compiled for your benefit:

Overview of the Lifecycle Steps

There are five main steps that happen when you make a request from an ASP.NET MVC website:

1. The RouteTable is Created

This first step happens only once when an ASP.NET application first starts. The RouteTable maps URLs to handlers.

2. The UrlRoutingModule Intercepts the Request

This second step happens whenever you make a request. The UrlRoutingModule intercepts every request and creates and executes the right handler.

3. The MvcHandler Executes

The MvcHandler creates a controller, passes the controller a ControllerContext, and executes the controller.

4. The Controller Executes

The controller determines which controller method to execute, builds a list of parameters, and executes the method.

5. The RenderView Method is Called

Typically, a controller method calls RenderView() to render content back to the browser. The Controller.RenderView() method delegates its work to a particular ViewEngine

Source: http://stackoverflow.com/questions/2355139/what-is-the-lifetime-of-a-asp-net-mvc-controller

I also found a chart by Steve Sanderson you can print and keep around your desk:

http://blog.stevensanderson.com/2009/10/08/aspnet-mvc-learning-resource-request-handling-pipeline-poster/

Posted in: ASP.NET MVC

Tags:

Ajax action link not calling the corresponding method in controller

January 30, 2012 at 2:38 PMMadestro

So I was working on an ASP.NET MVC application and stumbled upon a little situation that was driving me nuts. I had an action link which used a confirmation message box that would allow the user to delete a record. The code was straight forward but for some reason the action would not fire on the controller.

After trying a few things I realized I was using some boiler plate code that provided standard handlers for the events:

new AjaxOptions() { Confirm = "Are you sure you want to delete this record from the system?", UpdateTargetId = "Results", HttpMethod = "POST", LoadingElementId = "LoadingContainer", OnSuccess = "Ajax_OnSuccess", OnFailure = "Ajax_OnFailure", OnBegin = "Ajax_OnBegin", OnComplete = "Ajax_OnComplete" }

(Scroll to the right on the code line, notice the "Ajax_" event handlers)

The issue turned out to be that I had forgotten to include the script file with these functions into my page. Apparently, if you provide method names but do not provide the implementation, it breaks the call to the action.

I hope this saves someone else some time...

Posted in: ASP.NET MVC

Tags:

Expanding the list of databases in SQL Management Studio 2008 takes a long time or loads indefinitely

January 13, 2012 at 1:38 PMMadestro

I was trying to connect to my hosted database with SQL Management Studio 2008 when I ran into an issue. I was able to connect fine using my database credentials but when I attempted to expand the Databases node, Object Explorer just hung trying to load the list of databases. I could run queries and everything, but the database list node would not load.

The issue turned out to be the amount of data being loaded by Object Explorer. Because my provider hosts a lot of databases, Object Explorer was taking an unusually long time loading all the information for every database in the list.

The solution to this issue is:

  • Login to any database server
  • Select the "Databases" node in Object Explorer
  • In the top menu, select "View -> Object Explorer Details"
  • When the "Object Explorer Details" tab opens, right click on any of the headers (.e.g Name, Owner, etc) to get a list of columns to display
  • Uncheck all the columns you don't need. I personally keep only the Name and Owner columns checked
  • Restart SQL Management Studio

Log in to your server again and the databases should be displayed normally.

Here is the link to the original post I found in order to troubleshoot this issue: http://stackoverflow.com/questions/2013923/expanding-list-of-databases-in-sql-server-2008-management-studio-takes-longer-th

Posted in: Databases

Tags:

Finally running my own blog

January 12, 2012 at 10:34 AMMadestro

Well, it had to happen sometime. I finally got my own blog up and running!

Welcome and thanks for stopping by!

I must say, I am impressed with what the BlogEngine.NET guys have done. Their blog engine is very easy to setup. I was up and running in no time so special thanks to them. If you are looking for blog software, please visit their page at http://www.dotnetblogengine.net.

Posted in: Everything else

Tags: