Posts

Showing posts from 2008

IIS Compression in IIS6.0

Hold on to your hats folks. If you don't have compression installed on your web server, either IIS Compression or a 3rd party, and you have IIS6.0 and pay for bandwidth you're missing out on something good. In the day of IIS5 and earlier the compression built into IIS had various issues and was really not worth implementing. To enable compression you would need to go with a 3rd party solution like www.port80software.com or www.xcompress.com. This has all changed in IIS6! At www.orcsweb.com we've been running IIS6.0 compression on some servers for a number of month with few issues, just huge performance and bandwidth benefits. Expect upwards of 4 times the compression which directly translates to bandwidth savings. This means faster loading of pages for the end user also. The only time we had to disable it was for a custom audio application for one of our clients that didn't work with compression. I'll mention at the end of this how to disable compression for an ...

ASP.NET 2.0 MasterPages and FindControl()

The problem is that when you use MasterPages the page hierarchy drastically changes. Where a simple this.FindControl() used to give you a control instance you now have to drill into the container hierarchy pretty deeply just to get to the content container. So in the past I might have done this in my C# base class: protected Label lblError = null; protected DataGrid dgItemList = null; protected void AssignControls() { this.lblError = this.FindControl("lblError") as Label; this.dgItemList = this.FindControl("dgItemList") as DataGrid; } you now have to drill into the containership with code like this: protected void AssignControls() { this.lblError = this.Master.FindControl("Content").FindControl("lblError") as Label; this.dgItemList = this.Master.FindControl("Content").FindControl("dgItemList") as DataGrid; } This isn't so bad, except when you're trying to figure out how to get to your controls. It really seems lame tha...

Browser detection and Redirection using Javascript

http://usefulscripts.wordpress.com/2007/10/26/browser-detection-and-redirection-using-javascript/

String Formatting in C#

String Formatting in C# I couldn’t find a quick reference to .NET string formatting using the String.Format() function, so I created this one (which has also spawned this String Formatting FAQ and strangely enough, this cartoon. When I started working with the .NET framework, one thing puzzled me. I couldn’t find sprintf(). sprintf() is the C function that takes an output buffer, a format string, and any number of arguments, and builds a string for you. For example: char szError[256]; sprintf(szError, “Error %d occurred.\n”, nError); This would write “Error 12 occurred.” into the szError buffer (assuming nError was 12). It’s a basic part of C programming and most C++ programmers still use it though better functionality is available in the STL because sprintf is simple to use and clear. The STL equivalent would be: str Or something close to that. It’s type-safe, and more OO than sprintf, but not as easy to read and not as easy to localize. The .NET framework handles strings very nicely ...

Value vs Reference Types

C# Concepts: Value vs Reference Types http://www.albahari.com/value%20vs%20reference%20types.html Introduction One area likely to cause confusion for those coming from a Java or VB6 background is the distinction between value types and reference types in C#. In particular, C# provides two types—class and struct, which are almost the same except that one is a reference type while the other is a value type. This article explores their essential differences, and the practical implications when programming in C#. This article assumes you have a basic knowledge of C#, and are able to define classes and properties. First, What Are Structs? Put simply, structs are cut-down classes. Imagine classes that don’t support inheritance or finalizers, and you have the cut-down version: the struct. Structs are defined in the same way as classes (except with the struct keyword), and apart from the limitations just described, structs can have the same rich members, including fields, methods, properti...

GridView Tips and Tricks using ASP.NET 2.0

Good article for Grid View. http://www.dotnetcurry.com/ShowArticle.aspx?ID=107&AspxAutoDetectCookieSupport=1

ShortGuid - A shorter and url friendly GUID class in C#

Using the ShortGuid The ShortGuid is compatible with normal Guid's and other ShortGuid strings. Let's see an example: Guid guid = Guid.NewGuid(); ShortGuid sguid1 = guid; // implicitly cast the guid as a shortguid Console.WriteLine( sguid1 ); Console.WriteLine( sguid1.Guid ); This produces a new guid, uses that guid to create a ShortGuid, and displays the two equivalent values in the console. Results would be something along the lines of: FEx1sZbSD0ugmgMAF_RGHw b1754c14-d296-4b0f-a09a-030017f4461f Or you can implicitly cast a string to a ShortGuid as well. string code = "Xy0MVKupFES9NpmZ9TiHcw"; ShortGuid sguid2 = code; // implicitly cast the string as a shortguid Console.WriteLine( sguid2 ); Console.WriteLine( sguid2.Guid ); Which produces the following: Xy0MVKupFES9NpmZ9TiHcw 540c2d5f-a9ab-4414-bd36-9999f5388773 Read More ...... http://www.singular.co.nz/blog/archive/2007/12/20/shortguid-a-shorter-and-url-friendly-guid-in-c-sharp.aspx

Intro to Constructors in C#

Constructor in C# : Broadly speaking, it is a method in the class which gets executed when its object is created. Usually we put the initialization code in the constructor. Writing a constructor in the class is damn simple, have a look at the following sample : public class mySampleClass { public mySampleClass() { // This is the constructor method. } // rest of the class members goes here. } When the object of this class is instantiated this constructor will be executed. Something like this : mySampleClass obj = new mySampleClass() // At this time the code in the constructor will // be executed Constructor Overloading : C# supports overloading of constructors, that means we can have constructors with different set of parameters. So our class can be like this : public class mySampleClass { public mySampleClass() { // This is the no parameter constructor method. // First Constructor } public mySampleClass(int Age) { // This is the constructor with one parameter. // Second Constructor } p...

Assembly Binding Process

Image

Master Page in asp.net 2.0

Master pages let you make a consistent layout for your application, you can make one master page that holds the layout/look & feel and common functionality of your whole application and upon this master page, you can build all the other pages, we call these pages Content Pages. Visit these links for details http://www.devx.com/dotnet/Article/18042 http://www.codeproject.com/KB/aspnet/masterpages.aspx