Friday, August 28, 2009

Fun flow diagram


I have found a very funny flow diagram on xkcs. In this diagram non-computer people gets some instructions what do to when they getting an error on the pc BEFORE calling 'computer experts'.

Tuesday, August 25, 2009

Convert usercontrol to control

This article contains some instructions how to convert a UserControl to a Control.

.Root in Source Safe

Frustating everytime I created a project the postfix ".root" is added. Finally I have found a site with the same problem (or an the MSDN website and a SOLUTION.


You are running into a feature referred to as 'Solution Root' added
to VS2003 (and carried forward into VS2005). You can disable this behavior
via the following registry entry:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\SourceControl\DoNotCreateSolutionRootFolderInSourceControl

Builder versus Factory pattern

Copied from some other website, unknown which one...

Difference Between Builder pattern and Factory pattern
The factory pattern defers the choice of what concrete type of object to make until run time. E.g. going to a restaurant to order the special of the day. The waiter is the interface to the factory that takes the abstractor generic message "Get me the special of the day!" and returns the concrete product (i.e. Hawaiian or Spicy pizza)
The builder pattern encapsulates the logic of how to put together a complex object so that the client just requests a configuration and the builder directs the logic of building it. E.g The main contractor (builder) in building a house knows, given a floor plan, how to execute the sequence of operations (i.e. by delegating to subcontractors) needed to build the complex object. If that logic was not encapsulated in a builder, then the buyers would have to organize the subcontracting themselves ("Dear, shouldn't we have asked for the foundation to be laid before the roofers showed up?")
The factory is concerned with what is made, the builder with how it is made. Design patterns points out that Abstract factory is similar to builder in that it too may construct complex objects. The primary difference is that the Builder pattern focuses on constructing a complex object step by step. Abstract factory's emphasis is on families of product objects (either simple or complex). Builder returns the product as the final step, but as far as the Abstract Factory is concerned, the product gets returned immediately.

_Blank variant

On old school tip... when you do not want to use "target=_blank", you can the use following javascript.

<a onclick="window.open(this.href,'_blank');return false;" href="http://some_oother_site.com">Some Other Site</a>

TemplateSourceDirectory invisible

TemplateSourceDirectory can be overridden in the following way:
new public virtual string TemplateSourceDirectory
{
get
{
return Page.TemplateSourceDirectory;
}
}


Now the property is invisible for other classes.

Set time-out-time

On the blog of Sujith K Jagini there is a article with some information about
Time out exceptions. How can the 'time-out-time' be set in a WCF service, web service or for (SQL) database.

Monday, August 24, 2009

Thursday, August 20, 2009

Not showing a login page

When you uses .NET web application authentication the user is automatically redirected to the login screen. Here there is an example how you can prevent this, and now you can show the 'Access denied' page.

SEO: Viewstate on top

The rules for better SEO on your website are not static. So it is better to set the Viewstate information at the bottom of your webpage. How you can do this can you read here.

Composited control

Here you can read something about composited controls. (with validators)

In Place Editing

With the control of AJAX.NET it is now (easy) possible to create a website where the user can update the content with a click on the content which must be updated.

On Misfit Geek there is a nice startup tutorial about Inplace editing.

Redirect Session Expiration

On Schnieds Blog I have read an piece of code about Redirecting when the session is expirated.

I have not yet used this, but it seems nice to integrate this in a webapplication which uses form authentication.

more info

Wednesday, August 19, 2009

Serialization in ASP.NET (2)

Starting with serialization....uhhh I always forget that... I have found a link with an easy example which can be used as startup code fragment.
Simple example for serializing and deserializing

Web Site or Web Application

When you start building a web appication with Visual Studio you must decide which type you use:
- a web application project
- a web site project (introduced in VS2005)

Some links with information about this discussion
- ASP.NET Resources - Web Site vs Web Application Project (WAP)
- ASP.NET Web Site Layout
- asp.net Web Site versus Web Application Project
- ASP.NET Website vs Web Application project
- Understanding Page Inheritance in ASP.NET 2.0 - Rick Strahl's Web Log
- Web Site or Web Application - Blog
- Website versus Web Application - Durban, South Africa

But the conclusion of most of these sites is: decide it by yourself!

Convert Website to Webapplication

When you want to convert a Website to a webapplication you can read
here some instructions for doiing this.

Parameters queries in Access

When developing websites for 'fun', mostly I will use an Access Database. In SQL server you have stored procedures and you can give values to them with params. This is also possible in Access, but Stored Procedures are called Queries and a nice example can be found here.

Tabs in Jquery

On Mikesdotnetting I have read the article about JQuery and Tabs.

I have sent a comment with the questing how to navigate directly to a specific tab? Example of navigate directly to a specific tab

Only IE7 in IE8

Force IE7 compatibility mode in IE8 with a single line in the header of each webpage.


<meta http-equiv="X-UA-Compatible" content="IE=7" />

Sunday, August 2, 2009

String.Empty vs empty quotes vs String.Length

The usage of String.Empty is more efficient that the usage of empty quotes.

When using empty quotes an object is created and this produces more assembly code on the execution stack and for string.Empty is NO object created.

The usage of String.Length == 0 is the best. Now there is a numeric compare applied instead of a string compararision, and numeric compare is quicker.


Only what if the string has the value null? So use string.IsNullOrEmpty method


More info: C# Shiznit, Vikram's Blog

Throw; versus Throw e;

In Coding Standards is the differents between throw and throw e explained.

What is the difference?
The difference is that 'throw;' the original stack trace persists and 'throw ex' truncates the stack trace after the method where the 'throw ex;' is called.

When using 'throw;'?
When in the try{...} a method is called then you must use 'throw;' to take care that you have the original stack trace.


Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}

// Good!
catch(Exception)
{
Log(ex);
throw;
}

Another alternative is to create a new Exception and pass the current exception as inner exception. The stack trace is shown correctly (complete)


Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}

// Good!
catch(Exception)
{
Log(ex);
Throw new NotImplementedException(“some extra information”, ex);
}

See for more information Fabrice's weblog, Signs on the Sand, Joteke's Blog

String.Compare or String.ToLower

// Bad!
Example: (ToLower() creates a temp string)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
if(customerList[i].Name.ToLower() == name)
{
id = customerList[i].ID;
}
}

// Good! (but not for all cultures)
int id = -1;
string name = "lance hunt";
for(int i=0; i < customerList.Count; i++)
{
// The “ignoreCase = true” argument performs a
// case-insensitive compare without new allocation.
if(String.Compare(customerList[i].Name, name, true)== 0)
{
id = customerList[i].ID;
}
}

// Good! (now also for all cultures)
int id = -1;
string name = "lance hunt";
for (int i = 0; i < customerList.Count; i++)
{
// The StringComparison.OrdinalIgnoreCase argument performs a
// case-insensitive compare without new allocation and for several cultures.
if (String.Compare(customerList[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
{
id = customerList[i].ID;
}
}

Een leuke referentie is de zogenaamde Turkey Test.