Linq to SQL Tutorial – Using Load Options to preload data immediately without lazy loading

0

Posted by Joe | Posted in ASP.NET, C#, Linq | Posted on 23-11-2009

Download source

With Linq to SQL lazy loading is used by default. That means that if one object contains another object, the child object will only be loaded when first accessing it. Using Load Options it is possible to tell Linq to SQL to also load the child object at the same time as loading it’s parent.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

ASP.NET FormView SetFocus

0

Posted by Joe | Posted in ASP.NET, C# | Posted on 20-11-2009

I have FormView and on changing to Edit mode I wanted to set focus to the first textbox. I thought I’d do this hooking into the ModeChanged event but this doesn’t work as the textbox hasn’t been rendered.

I then tried overriding the Render method and setting the focus after rendering; at this point the control was created but I get an exception to say focus can only be set in PreRender, but in PreRender the control won’t be available.

One way I found to get this to work was to set the focus in a handler for the DataBound event of the FormView.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Read only Automatic Properties in C#

1

Posted by Joe | Posted in C# | Posted on 17-11-2009

Automatic Properties were a nice addition to C# 3 and I use them all the time. A lot of people may already know this but somehow I only found out this week; you can create a read only automatic property simply by adding the ‘private’ keyword before ’set’:


public class UserEventArgs : EventArgs
{
    public UserEventArgs(int userID)
    {
        UserID = userID;
    }

    public int UserID { get; private set; }
}

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit