Aug 30, 2006Recently, I had to implement validation on business objects in an already existing
project. The validation should ensure that the different classes in the business object
tier would validate them selves based on business rules. One of the rules on the Product
class was that the Price property never must be negative and the Name property must
be at least one character long.
For some reason I don’t know, none of these validation checks was made and I had to
find a simpl...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 28, 2006It’s a good rule of thumb to overload the equality operators on classes. That ensures
a correct comparison between to class instances of the same type. If you don’t, .NET
automatically uses reflection and that is way slower than a custom implementation.
We all use the equality operators (“==”, “!=”) all the time and we expect them to
be right every time. They are not!, but even if they were there is a good chance that
you want to change them anyway. For instance, if your...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 26, 2006Internet Explorer and the Gecko based browsers (Firefox, Netscape and Mozilla) have
different ways of managing their internal cache. The speed of the browser cache is
much faster that a server caching, so be sure to do your client-side caching cross
browser friendly.
The Gecko based browsers uses the ETag header and Internet Explorer uses the Last-Modified
header, so you have to set both of them to make it work. Here’s a simple method that
does just that.
&nbs...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 25, 2006The new System.IO.Compression namespace in .NET 2.0 makes it easy to implement HTTP compression without having to touch IIS. The best thing about it is that you no longer need any third party compression components, it’s all build directly into .NET Framework.
There are different ways to implement the compression but I think an HttpModule is the right choice for this feature. Let's create one and call it CompressionModule.
The CompressionModule must adhere to the following ...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 24, 2006Whenever you write class libraries, custom control or just about anything else, you
probably raise a lot of home made events. That’s a simple thing to do, but tedious
to write over and over again.
That’s why I always use this snippet for Visual Studio 2005 that writes the whole
thing for me. Download
the snippet and place it in the Visual Studio snippet folder which is placed at
My documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets\.
Just f...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 20, 2006It is always desirable to produce the smallest amount of client-code at any given
time. That includes HTML, JavaScript and CSS files. The more client-code you produce, the longer it takes to download and render the web page. Let’s see how easy it is
to reduce CSS files by 35 % at runtime, but first we have to set some rules for the
feature.
No changes to the original .css files must be made
Must work on all .css files without exception
...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 17, 2006Even though ViewState is unreadable by the human eye, it is nothing but a base64 encoded
string that easily decodes by a piece of software like this
one. With this knowledge in mind, you might want to look at how you can secure
the ViewState to avoid tampering and maybe even identity theft in extreme cases.
Let’s take a look on how to secure the ViewState and at the same time, keeping it
simple to implement.
Encryption
The first thing we need to do is to add ...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 14, 2006I’m sure you’ve used a DataRow a thousand times before without noticing the quirk.
I’m not talking about a bug or missing functionality. No, I’m talking about something
much less important, but still very puzzling.
A DataRow is a class that contains objects, 1 object per column. In order to retrieve
one of the objects, you access it by the index in the collection or by the key, like
so:
DataRow[2] // returns the object in the third column.
...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 12, 2006The JavaScript confirm() function is simple to implement on a Button control, but
you can only use it for one particular purpose and that is to confirm a postback.
Let’s look at an example of this simplicity first and then improve it afterwards.
Below is a Button control with an onclick attribute, that opens the confirm dialog.
If the user presses the OK button, it will continue with the postback, and if Cancel
is pushed nothing will happen.
<asp:Button
Runat="...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!
Aug 10, 2006In highly interactive websites and intranet sites, you probably want to let the users
know what’s going on when they delete, save, export etc. on the site. Those kinds
of status messages are widely used and are often implemented by a JavaScript alert
box on the web page. ASP.NET doesn’t natively support JavaScript functions from the
code-behind files. You manually have to print out a script tag and add the alert()
call to it.
As easy as it may be, the extensive use of...
[More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!