July31
One of many new features introduced into the .NET 3.5 framework are Lambda Expressions.
Lambda Expressions are a method of programmatically assigning Event Handlers to Events. There are a few ways that this can be acheived though Lambda Expressions prove to be the quickest, cleanest and most effective way of doing so.
Lambda Expressions are similar to anonymous methods only taken one step further. For instance if you had a button on your page and an event in your code behind which you wished to wire up programmatically using an anonymous method it would look similar to the following:
Anonymous Method
protected void Page_Init(object sender, EventArgs e)
{
btnGo.Click += delegate(object sender, EventArgs e)
{
lblDate.Text = DateTime.Now.ToString();
}
}
Read the rest of this entry »
July29
Adding Google maps to your website to show where your business is located is becoming quite a popular feature of many websites. It enables the user to see where you are located and give them a vague idea on how to get to that location. Though wouldn’t it be nice if we could give specific directions depending on the viewer’s location?
In this article I will explain a basic technique that will allow you to create a customized directions system that will plug directly in to Google Maps to output directions based on a users address or postcode.
To start off, we need a Google Maps url to integrate into our system.
Read the rest of this entry »
July25
Displaying random images through JavaScript is becoming a bit ‘old hat’. If your are regularly updating your images and find yourself updating your JavaScript file each time, I don’t need to tell you that it gets a bit boring.
With ASP.NET using a custom user control can simply eliminate this problem. We can create a control that will look into the images folder, select all of the images, find a random one and display it on an asp:image control.
The code for this is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| using System;
using System.IO;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Protected void Page_Load(object sender, EventArgs e)
{
//Show the path to the folder which contains the files you wish to randomly select from
string directory = "/common/images/random/";
//Create a string array to contain the images
string[] images = Directory.GetFiles(HttpContext.Current.Server.MapPath(directory));
//Check to see if any images exist and if so display a random one
if (images.Length > 0)
{
int rnd = new Random().Next(0, images.Length);
imgRandom.ImageUrl = directory + Path.GetFileName{images[rnd]);
}
} |
Read the rest of this entry »
July21
Until now data access has been a tedious task, creating data, entity and service layers grows old after the 400th time. Even when using NHibernate this task can chew up the majority of your development time.
In the .NET 3.5 framework Microsoft have developed a new form of data access, somthing that can free us from our masses of SQL and service layers. Linq.
Linq is a language that resembles SQL script to and immitates SQL script (so your thinking “then isn’t it SQL?”) but there is one major difference… It’s written in C# (or VB if you choose)!
By using linq you completely eleminate stored procedures and data layers and keep one little layer to keep your methods nice and tidy.
Read the rest of this entry »