Archive for the ‘Development’ Category

10 ASP.NET Performance and Scalability Secrets

5 February, 2008

An article by Omar Al Zabir explains 10 easy ways to make ASP.NET and AJAX web sites faster, more scalable and support more traffic at lower cost. Omar Al Zabir is the CTO of Pageflakes one of the best mashups.

Main points he has discussed in this article

  • ASP.NET pipeline optimisation
  • ASP.NET process configuration optimisation
  • Things you must do for ASP.NET before going live
  • Content Delivery Network
  • Caching AJAX calls on browser
  • Making best use of Browser Cache
  • On demand progressive UI loading for fast smooth experience
  • Optimise ASP.NET 2.0 Profile provider
  • How to query ASP.NET 2.0 Membership tables without bringing down the site
  • Prevent Denial of Service (DOS) attack

Read the full article at code project 10 ASP.NET Performance and Scalability Secrets

Paying for software

25 January, 2008

I found this pretty interesting letter… seems like the argument’s been going on for sometime!

 

http://www.blinkenlights.com/classiccmp/gateswhine.html

System.Data.DataSetExtensions Config Error in Visual Studio 2008 RTM

3 December, 2007

I got the exception shown below when I opened an application that was developed under VS 2008:

ASP.NET runtime error: Could not load file or assembly ‘System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies. The system cannot find the file specified

What’s happened is there is no more an assembly System.Data.DataSetExtensions with version number 2.0. There is a new version for the same assembly name under 3.5.0.0.

To resolve the problem, simply right-click on the web application, properties, then remove the reference to the 2.0.0.0 assembly.

Then, right-click on the web application solution, Add Reference, locate the System.Data.DataSetExtensions and add a reference to it. You may also need to update the entry web / app.config file under the <assemblies> tag. Update the version to 3.5.0.0

I’m in a podcast!

30 July, 2007

Have a listen for yourself http://www.craigmurphy.com/blog/?p=610

It was a sound bite taken by Craig after the DeveloperDeveloperDeveloper event held at MS HQ in Reading.

C# Event handling – Using Delegates and Events.

6 June, 2007

There’s no doubt about it wiring an event through classes in VB.NET is much simpler than C#. All VB requires an object reference and a simple ‘handles’ statement on the end of the method declaration.

A couple of friends have asked about wiring C# events through classes so I have put together an example which is available for download. Don’t forget, if you’re wiring events (custom or otherwise), from UI controls you can use ‘AutoEventWireup’ which will make things much easier.

Right click and ‘Save Target As’ to download, then you will need to rename the extension to .zip

Right click here to download.

Sliding Div Elements. A Full Example Follow-Up

19 March, 2007

A while ago I wrote an article showing how you could build a basic sliding div element using the JQuery library. I have had many questions over that post and I have decided to post a full HTML page with the sliding div example.

You will need to download the JQuery library – you can get it from http://www.jQuery.com

If copying and pasting watch the ” characters :-)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JQuery: Collapsible Menu</title>
<script type="text/javascript" src="js/JQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#div1").mouseover(function(){
$("#div2").slideDown('fast');
});
$("#div1").mouseout(function(){
$("#div2").slideUp('fast');
});
$("#div3").mouseover(function(){
$("#div4").slideDown('fast');
});
$("#div3").mouseout(function(){
$("#div4").slideUp('fast');
});
});
</script>
</head>
<body>
<div id="Nav" style="width:200px;">
<div id="div1" style="border: solid 1px silver;">Navigation 1</div>
<div style="border:solid 1px white; height:5px;"></div>
<div id="div2" style="display:none;background-color:pink;">Welcome to the Navigation 1 area </div>
<div id="div3" style="border: solid 1px silver;">Navigation 2</div>
<div id="div4" style="display:none;background-color:pink;">Welcome to the Navigation 2 area </div>
</div>
</body>
</html>

Option strict and option explicit defined…

23 January, 2007

A friend and coworker asked me today why I use ‘Option Explicit’ and ‘Option Strict’ at the top of all my .net (and for that matter VB6/asp 3.0) classes. I thoguht I’d record the answers here.

‘Option Explicit’ ensures you declare all variables before use. VB.NET doesn’t allow this anymore but in the past it was possible to build an entire application without declaring a single variable!

‘Option Strict’ keeps VB developers coding bad casts as below:

dim x as string = “true”
dim y as boolean = x

or

dim ctl as control
ctl = new textbox

If you’re pure C# you probably can’t believe that this is actually possible. Well it is. More to the point VB developers have bad habits from the ‘days of old’ and code things like this without even batting an eyelid. NOTE: By default VB.NET still allows these bad casts

Option Explicit Statement
By default, the Visual Basic .NET or Visual Basic 2005 compiler enforces explicit variable declaration, which requires that you declare every variable before you use it.

Option Strict Statement
By default, the Visual Basic .NET or Visual Basic 2005 compiler does not enforce strict data typing.

In Visual Basic .NET, you can convert any data type to any other data type implicitly. Data loss can occur when the value of one data type is converted to a data type with less precision or with a smaller capacity. However, you receive a run-time error message if data will be lost in such a conversion. Option Strict notifies you of these types of conversions at compile time so that you can avoid them.

Overloading routines in WebServices

19 January, 2007

Web services are also classes just like any other .NET classes. Since a web service is a class it can utilise all the OO features like method overloading. However to use this feature with WebMethods we need toadd a little extra syntax.

Creating WebMethods
Create a WebService that has the following overloaded methods:

public string GetGreeting()
public string GetGreeting(string p_Name)
public string GetGreeting(string p_Name, string p_Message)

All these three methods return variants of a Greeting message. Now mark the methods as Web Methods, simply add the [WebMethod] attribute.

[WebMethod]
public string GetGreeting()
{
return “Hi Guest”;
}

[WebMethod]
public string GetGreeting(string p_Name)
{
return “Hi ” + p_Name + “!”;
}

[WebMethod]
public string GetGreeting(string p_Name, string p_Message)
{
return “Hi ” + p_Name + “!” + p_Message;
}

Run the WebService in the browser. That should give an error saying that the GetGreeting() methods use the same message name ‘GetGreeting’.

Adding the MessageName property.
Add the MessageName property to the WebMethod attribute as shown below:

[WebMethod]public string GetGreeting()
{
return “Hi Guest”;
}
[WebMethod (MessageName="WithOneString")]
public string GetGreeting(string p_Name)
{
return “Hi ” + p_Name + “!”;
}
[WebMethod (MessageName="WithTwoStrings")]
public string GetGreeting(string p_Name, string p_Message)
{
return “Hi ” + p_Name + “!” + p_Message;
}

Now compile the WebService and run in the browser. You can see that the first method is displayed as GetGreeting but for the second and third method the alias we set using the MessageName property is displayed.

You could of course use the alias’ as your method names – but that’d be taking the fun out of OO :-)

CSS manipulation with jQuery – sliding div elements

19 January, 2007

Please note, I have provided a full example of this in a later post here

I’ve spent a couple of months working with jQuery now and have grown to like it. For a sales pitch recently I used jQuery to put together a few forms and have been impressed by its power.

Here’s a quick example of a sliding div element.

<script>
jQ(document).ready(function(){

$(“#div1″).slideUp(’slow’, function(){
$(“#div2″).slideDown(’slow’);
});

});
</script>

And the HTML:

<html>
<body>
<div id=’div1′>div 1</div>
<div id=’div2′ style=’display:none;’>div 2</div>
</body>
</html>

This will result in div1 sliding up and div2 sliding down into its place on completion of the page load.

The jQuery will execute as follows:

  1. Firstly th script will wait for the document to be ready (loaded)
  2. It will then slide div1 up slowly
  3. Only on completion of div1 sliding up will div2 slide down

As you can see div1 only slides up once the document has loaded and div2 will only slide down once div1 has completed its ’slide up’. This takes all those handcrafted JS time delays out of the code – making things much much nicer :-)

Using the arraylist – populating, sorting and searching

19 December, 2006

 A friend was asking about sorting the arraylist. I’ve knocked together a sort tutorial on the object and soem of it’s abilities.

Adding Objects to the ArrayList

Adding objects is simple just use the add method:

Dim al As New ArrayList()

al.Add(“This”)
al.Add(“Is”)
al.Add(“My”)
al.Add(“New”)
al.Add(“ArrayList”)
al.Add(“Control”)

This adds 6 new objects to the arraylist.
Reading the Values of the ArrayList

To read the values you can iterate though each of the items in the Item collection like so:

Dim i As Integer
  
For i = 0 To al.Count – 1
 Console.WriteLine(CStr(al.Item(i)))
Next

If you prefer you can use an Enumerator like this:

Dim en As IEnumerator = al.GetEnumerator
While en.MoveNext
  Console.WriteLine(en.Current)
End While

Searching The ArrayList

To search for the existence of an object in the ArrayList, you can use the BinarySearch method:

Dim al As New ArrayList()

al.Add(“This”)
al.Add(“Is”)
al.Add(“My”)
al.Add(“New”)
al.Add(“ArrayList”)
al.Add(“Control”)

‘Do a case Insensitive search
Dim idx As Integer = al.BinarySearch(“my”, New CaseInsensitiveComparer())

If idx > 0 Then
   MessageBox.Show(“Found at Index ” & idx)
Else
   MessageBox.Show(“Not Found”)
End If

Note that we use a CaseInsensitiveComparer object above, you could also do this:

Dim idx As Integer = al.BinarySearch(“my”)

If you do not specify the IComparer implementation the default is a case sensitive compare. So the line above will return the “Not Found” message.
Sorting the ArrayList
There are a few different options to sorting but the basic is a simple Ascending Case Sensitive Sort:

   Dim al As New ArrayList()

   al.Add(“This”)
   al.Add(“Is”)
   al.Add(“My”)
   al.Add(“New”)
   al.Add(“ArrayList”)
   al.Add(“Control”)

   Console.WriteLine(“Before Sort:”)
   WriteElements(al)

   al.Sort()
   ‘ Sort descending using this: al.Reverse()

WriteElements(al)

Here’s a routine that will write the contents of the arraylist

Private Sub WriteElements(ByVal al As ArrayList)
  Dim en As IEnumerator = al.GetEnumerator

While en.MoveNext
  Console.WriteLine(en.Current)
  End While
End Sub