Thursday, November 26, 2009

Usage of @MasterType

The @MasterType Page Declarative of a page is used to access the public properties and methods of a master page to the sub level of content page

Example :

Step 1:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage_MasterPage" %>

<title>ScriptManager in Master Page Example</title>


<form id="form1" runat="server">
<div>
<asp:scriptmanager id="ScriptManager1" runat="server">
<asp:panel id="MasterPanel1" runat="server" groupingtext="Master Page">
<asp:button id="Button1" runat="server" text="Full Page Refresh">
<asp:button id="Button2" runat="server" text="Refresh Panel" onclick="MasterButton2_Click">
</asp:button>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</asp:button></asp:panel></asp:scriptmanager></div>
</form>



Step 2:

Create a public property in the MasterPage.master.cs

public partial class MasterPage_MasterPage : System.Web.UI.MasterPage
{
public DateTime LastUpdate
{
get
{
return (DateTime)(ViewState["LastUpdate"] ?? DateTime.Now);
}
set
{
ViewState["LastUpdate"] = value;
}
}
}


Step 3:

Define the <%@ MasterType %> like this

<%@ Page Language="C#" MasterPageFile="~/MasterPage/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MasterPage_Default" Title="Untitled Page" %>

<!--define like this-->

<%@ MasterType VirtualPath="~/MasterPage/MasterPage.master" %>



<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="Server">
<asp:panel id="Panel2" groupingtext="ContentPage" runat="server">
<asp:updatepanel id="UpdatePanel1" updatemode="Conditional" runat="server">
<contenttemplate>
<p>
Last updated: <strong><%= Master.LastUpdate.ToString() %></strong>
</p>
<asp:button id="Button3" text="Refresh Panel" onclick="Button3_Click" runat="server">
</asp:button>
</contenttemplate>
</asp:updatepanel>
</asp:panel>

Step 4:

Then we can use to access the public methods and properties from master page to content page.

protected void Button3_Click(object sender, EventArgs e)
{
Master.LastUpdate = DateTime.Now;
}

Tuesday, November 24, 2009

PageRequestManager

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_pageLoaded(PageLoadedEventHandler);

function PageLoadedEventHandler()

{

alert("Inside PageLoadedEventHandler Working");

}

Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);

function InitializeRequest()

{

alert('Initial requets inside...');

}



By this way, we can fire all the Five ajax page life cycle events.

Ajax + asp.net Page life cycle

During ordinary page processing in the browser, the window.onload DOM event is raised when the page first loads. Similarly, the window.onunload DOM event is raised when the page is refreshed or when the user moves away from the page.

However, these events are not raised during asynchronous postbacks. To help you manage these types of events for asynchronous postbacks, the PageRequestManager class exposes a set of events. These resemble window.load and other DOM events, but they also occur during asynchronous postbacks. For each asynchronous postback, all page events in the PageRequestManager class are raised and any attached event handlers are called.

NoteNote:

For synchronous postbacks, only the pageLoaded event is raised.

You can write client script to handle events raised by the PageRequestManager class. Different event argument objects are passed to handlers for different events. The following table summarizes the PageRequestManager class events and the corresponding event argument classes. The order of the events in the table is the order of the events for a single asynchronous postback without errors.

initializeRequest

Raised before the request is initialized for an asynchronous postback. Event data is passed to handlers as an InitializeRequestEventArgs object. The object makes available the element that caused the postback and the underlying request object.

beginRequest

Raised just before the asynchronous postback is sent to the server. Event data is passed to handlers as a BeginRequestEventArgs object. The object makes available the element that caused the postback and the underlying request object.

pageLoading

Raised after the response to the most recent asynchronous postback has been received but before any updates to the page have been made. Event data is passed to handlers as a PageLoadingEventArgs object. The object makes available information about what panels will be deleted and updated as a result of the most recent asynchronous postback.

pageLoaded

Raised after page regions are updated after the most recent postback. Event data is passed to handlers as a PageLoadedEventArgs object. The object makes available information about what panels were created or updated. For synchronous postbacks, panels can only be created, but for asynchronous postbacks, panels can be both created and updated.

endRequest

Raised when request processing is finished. Event data is passed to handlers as an EndRequestEventArgs object. The object makes available information about errors that have occurred and whether the error was handled. It also makes available the response object.

Monday, November 23, 2009

For creating and adding Dynamic templated column using Itemplate interface

First have to override the OnIt() method and then we can add the TemplatedColumn in it for creating check box control.

protected
override void OnInit(EventArgs e)

{

base.OnInit(e);

// Create a templated column

TemplatedColumn col = new TemplatedColumn(true);

this.UltraWebGrid1.DisplayLayout.Bands[0].Columns.Add(col);

col.Key = "CheckBoxCol";

col.Header.Caption = "";

GridHeaderTemplate tempHeader = new GridHeaderTemplate();

// Set the header template.

col.HeaderTemplate = tempHeader;

this.UltraWebGrid1.DataSource = LoadGrid();

this.UltraWebGrid1.DataBind();

}

/// Class with implementing the ITemplate

-----------------------------------------------------------

public class GridHeaderTemplate : ITemplate

{

public void InstantiateIn(Control container)

{

// Cast the container to a HeaderItem

HeaderItem headerItem = (HeaderItem)container;

CheckBox checkBox = new CheckBox();

CheckBox cb = new CheckBox();

cb.ID = "headerCB";

cb.Attributes.Add("onclick", "HeaderCheckedChanged();");

headerItem.Controls.Add(cb);

}

}




Friday, November 20, 2009

.net Features in C# 3.5

. Automatic Property setters/getters


Whenever you declare a class, most of the times the class is used only as a placeholder with getters and setters for holding property values without any additional logic. For example, consider a simple class like the following:

public class Person
{
int _id;
string _firstName;
string _lastName;
public int ID { get{return _id;} set{_id = value;} }
public string FirstName { get{return _firstName;} set{_firstName = value;} }
public string LastName { get{return _lastName;} set{_lastName = value;} }
public string FullName { get{return FirstName + " " + LastName;} }
}

As you can see from the above class declaration, it doesn't contain any additional logic. The get and set properties are repetitive and they simply set or get the values of the properties without adding any value. In C#, you can simplify that by leveraging the new feature named Auto-Implemented properties. By taking advantage of this new feature, you can rewrite the above code as follows:

public class Person
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get
{
return FirstName + " " + LastName;
}
private set {;}
}
}

In the above code, when you declare a property, the compiler automatically creates a private, anonymous field that is available only to the property's get and set accessors. Note that the auto implemented properties must declare both a get and set accessor. However if you need to create a read-only property, modify the scope of the set accessor to be private.

· Object Initializers
· Collection Initializers
· Extension Methods
· Implicitly Typed Variable
· Anonymous Types


New features in asp.net 3.5
////-----------------------------

. ASP.NET AJAX
. New Controls (ListView and DataPager)
. New Data Source Control (LinqDataSource)
. LINQ (Language Integrated Query)
. ASP.NET Merge Tool:
(ASP.NET 3.5 includes a new merge tool (aspnet_merge.exe). This tool lets you combine and manage assemblies created by aspnet_compiler.exe)
. New Assemblies
· System.Core.dll - Includes the implementation for LINQ to Objects
· System.Data.Linq.dll - Includes the implementation for LINQ to SQL
· System.Xml.Linq.dll - Includes the implementation for LINQ to XML
· System.Data.DataSetExtensions.dll - Includes the implementation for LINQ to DataSet

.Net Framework 3.0 features


Framework 3.0 features:

. Implicitly typed local variables

// i is compiled as an int
var i = 5;

// s is compiled as a string
var s = "Hello";

// a is compiled as int[]
var a = new[] { 0, 1, 2 };

// expr is compiled as IEnumerable
// or perhaps IQueryable
var expr =
from c in customers
where c.City == "London"
select c;

// anon is compiled as an anonymous type
var anon = new { Name = "Terry", Age = 34 };

// list is compiled as List
var list = new List();

. Anonymous types

C# 3.0 gives you the flexibility to create an instance of a class without having to write code for the class beforehand. So, you now can write code as shown below:

new {hair="black", skin="green", teethCount=64}
The preceding line of code, with the help of the "new" keyword, gives you a new type that has three properties: hair, skin, and teethCount. Behind the scenes, the C# compiler would create a class that looks as follows:

class __Anonymous1
{
private string _hair = "black";
private string _skin = "green";
private int _teeth = 64;
public string hair {get { return _hair; } set { _hair = value; }}
public string skin {get { return _skin; } set { _skin = value; }}
public int teeth {get { return _teeth; } set { _teeth = value; }}
}


. Extension methods

Extension methods enable you to extend various types with additional static methods. However, they are quite limited and should be used as a last resort—only where instance methods are insufficient.

Extension methods can be declared only in static classes and are identified by the keyword "this" as a modifier on the first parameter of the method. The following is an example of a valid extension method:

public static int ToInt32(this string s)
{
return Convert.ToInt32(s) ;
}

If the static class that contains the above method is imported using the "using" keyword, the ToInt32 method will appear in existing types (albeit in lower precedence to existing instance methods), and you will be able to compile and execute code that looks as follows:

string s = "1";
int i = s.ToInt32();

This allows you to take advantage of the extensible nature of various built-in or defined types and add newer methods to them.


. Object and collection initializers

public class CoOrdinate
{
public int x ;
public int y;
}

You then could declare and initialize a CoOrdinate object using an object initializer, like this:

var myCoOrd = new CoOrdinate{ x = 0, y= 0} ;
The above code may have made you raise your eyebrows and ask, "Why not just write the following:"

var myCoOrd = new CoOrdinate(0, 0) ;

Note: I never declared a constructor that accepted two parameters in my class. In fact, initializing the object using an object initializer essentially is equivalent to calling a parameterless (default) constructor of the CoOrdinate object and then assigning the relevant values.Similarly, you should easily be able to give values to Collections in a rather concise and compact manner in C# 3.0.For instance, the following C# 2.0 code:

List animals = new List();
animals.Add("monkey");
animals.Add("donkey");
animals.Add("cow");
animals.Add("dog");
animals.Add("cat");

Now can be shortened to simply:

List animals = new List {
"monkey", "donkey", "cow", "dog", "cat" } ;


. Lambda expressions

It Allowes you to write code blocks in methods, which you could invoke easily using delegates. Delegates are definitely useful, and they are used throughout the framework, but in many instances you had to declare a method or a class just to use one. Thus, to give you an easier and more concise way of writing code, C# 2.0 allowed you to replace standard calls to delegates with anonymous methods. The following code may have been written in .NET 1.1 or earlier:

class Program
{
delegate void DemoDelegate();
static void Main(string[] args)
{
DemoDelegate myDelegate = new DemoDelegate(SayHi);
myDelegate();
}
void SayHi()
{
Console.Writeline("Hiya!!") ;
}
}

In C# 2.0, using anonymous methods, you could rewrite the code as follows:

class Program
{
delegate void DemoDelegate();
static void Main(string[] args)
{
DemoDelegate myDelegate = delegate()
{
Console.Writeline("Hiya!!");
};
myDelegate();
}
}


Lambda expressions are simply functions and they are declared in the context of expressions than as a member of a class. It is an inline expression or a statement block which can be used to pass arguments to a method or assign value to delegate. All lambda expressions use the lambda operator => and the left side of the operator denotes the results and the right side contains the expression to be evaluated. For instance, consider the following lambda expression:

age => age + 1;

The above function takes one argument named age, and returns age + 1 as the result. As you can see, Lambda expressions follow the below syntax:

(parameter-list) => expression;

where expression can be any C# expression or a block of code. Just like anonymous methods you can use a lambda expression in place of a delegate. Here are some sample lambda expressions and their corresponding delegates.

//Explicitly typed parameter
(Person obj) => MessageBox.Show(obj.FirstName.ToUpper());

//Implicitly typed parameter
(obj) => obj.FirstName == "Thiru";

//Explicitly typed parameter
(int a, int b) => a + b

//Implicitly typed parameter
(x, y) => { return x + y; }

As you see from the preceding lines of code, lambda expressions can be written in such a way that itcan infer the parameter type from the signature of the delegate it is assigned to.




. Query expressions

Even though further enhancements may be introduced in the coming months as C# 3.0 matures, the new features described in the preceding sections make it a lot easier to work with data inside C# in general. This feature, also known as LINQ (Language Integrated Query), allows you to write SQL-like syntax in C#.

For instance, you may have a class that describes your data as follows:

public class CoOrdinate
{
public int x ;
public int y;
}

You now could easily declare the logical equivalent of a database table inside C# as follows:

// Use Object and collection initializers
List coords = ... ;

And now that you have your data as a collection that implements IEnumerable, you easily can query this data as follows:

var filteredCoords =
from c in coords
where x == 1
select (c.x, c.y)

In the SQL-like syntax above, "from", "where", and "select" are query expressions that take advantage of C# 3.0 features such as anonymous types, extension methods, implicit typed local variables, and so forth. This way, you can leverage SQL-like syntax and work with disconnected data easily.

Each query expression is actually translated into a C#-like invocation behind the scenes. For instance, the following:

where x == 1
Translates to this:

coords.where(c => c.x == 1)
As you can see, the above looks an awful lot like a lambda expression and extension method. C# 3.0 has many other query expressions and rules that surround them.

. Expression Trees

Expression trees represent language-level code in the form of data. The data is stored in a tree-shaped structure. Each node in the expression tree represents an expression, for example a method call or a binary operation such as
x <>> exprTree = num => num < param =" (ParameterExpression)exprTree.Parameters[0];" operation =" (BinaryExpression)exprTree.Body;" left =" (ParameterExpression)operation.Left;" right =" (ConstantExpression)operation.Right;"> {1} {2} {3}",
param.Name, left.Name, operation.NodeType, right.Value);

/* This code produces the following output:

Decomposed expression: num => num LessThan 5
*/



. Implicitly typed arrays.
class ImplicitlyTypedArraySample
{
static void Main()
{
var a = new[] { 1, 10, 100, 1000 }; // int[]
var b = new[] { "hello", null, "world" }; // string[]

// single-dimension jagged array
var c = new[]
{
new[]{1,2,3,4},
new[]{5,6,7,8}
};

// jagged array of strings
var d = new[]
{
new[]{"Luca", "Mads", "Luke", "Dinesh"},
new[]{"Karen", "Suma", "Frances"}
};
}
}

Framework 3.0 Language features:

. WPF
. WCF
. WF


.Net Framework 3.0 features

.Implicitly typed local variables

// i is compiled as an int
var i = 5;

// s is compiled as a string
var s = "Hello";

// a is compiled as int[]
var a = new[] { 0, 1, 2 };

// expr is compiled as IEnumerable
// or perhaps IQueryable
var expr =
from c in customers
where c.City == "London"
select c;

// anon is compiled as an anonymous type
var anon = new { Name = "Terry", Age = 34 };

// list is compiled as List
var list = new List();

. Anonymous types

C# 3.0 gives you the flexibility to create an instance of a class without having to write code for the class beforehand. So, you now can write code as shown below:

new {hair="black", skin="green", teethCount=64}
The preceding line of code, with the help of the "new" keyword, gives you a new type that has three properties: hair, skin, and teethCount. Behind the scenes, the C# compiler would create a class that looks as follows:

class __Anonymous1
{
private string _hair = "black";
private string _skin = "green";
private int _teeth = 64;
public string hair {get { return _hair; } set { _hair = value; }}
public string skin {get { return _skin; } set { _skin = value; }}
public int teeth {get { return _teeth; } set { _teeth = value; }}
}


. Extension methods

Extension methods enable you to extend various types with additional static methods. However, they are quite limited and should be used as a last resort—only where instance methods are insufficient.

Extension methods can be declared only in static classes and are identified by the keyword "this" as a modifier on the first parameter of the method. The following is an example of a valid extension method:

public static int ToInt32(this string s)
{
return Convert.ToInt32(s) ;
}

If the static class that contains the above method is imported using the "using" keyword, the ToInt32 method will appear in existing types (albeit in lower precedence to existing instance methods), and you will be able to compile and execute code that looks as follows:

string s = "1";
int i = s.ToInt32();

This allows you to take advantage of the extensible nature of various built-in or defined types and add newer methods to them.


. Object and collection initializers

public class CoOrdinate
{
public int x ;
public int y;
}

You then could declare and initialize a CoOrdinate object using an object initializer, like this:

var myCoOrd = new CoOrdinate{ x = 0, y= 0} ;
The above code may have made you raise your eyebrows and ask, "Why not just write the following:"

var myCoOrd = new CoOrdinate(0, 0) ;

Note: I never declared a constructor that accepted two parameters in my class. In fact, initializing the object using an object initializer essentially is equivalent to calling a parameterless (default) constructor of the CoOrdinate object and then assigning the relevant values.Similarly, you should easily be able to give values to Collections in a rather concise and compact manner in C# 3.0.For instance, the following C# 2.0 code:

List animals = new List();
animals.Add("monkey");
animals.Add("donkey");
animals.Add("cow");
animals.Add("dog");
animals.Add("cat");

Now can be shortened to simply:

List animals = new List {
"monkey", "donkey", "cow", "dog", "cat" } ;


. Lambda expressions

It Allowes you to write code blocks in methods, which you could invoke easily using delegates. Delegates are definitely useful, and they are used throughout the framework, but in many instances you had to declare a method or a class just to use one. Thus, to give you an easier and more concise way of writing code, C# 2.0 allowed you to replace standard calls to delegates with anonymous methods. The following code may have been written in .NET 1.1 or earlier:

class Program
{
delegate void DemoDelegate();
static void Main(string[] args)
{
DemoDelegate myDelegate = new DemoDelegate(SayHi);
myDelegate();
}
void SayHi()
{
Console.Writeline("Hiya!!") ;
}
}

In C# 2.0, using anonymous methods, you could rewrite the code as follows:

class Program
{
delegate void DemoDelegate();
static void Main(string[] args)
{
DemoDelegate myDelegate = delegate()
{
Console.Writeline("Hiya!!");
};
myDelegate();
}
}


Lambda expressions are simply functions and they are declared in the context of expressions than as a member of a class. It is an inline expression or a statement block which can be used to pass arguments to a method or assign value to delegate. All lambda expressions use the lambda operator => and the left side of the operator denotes the results and the right side contains the expression to be evaluated. For instance, consider the following lambda expression:

age => age + 1;

The above function takes one argument named age, and returns age + 1 as the result. As you can see, Lambda expressions follow the below syntax:

(parameter-list) => expression;

where expression can be any C# expression or a block of code. Just like anonymous methods you can use a lambda expression in place of a delegate. Here are some sample lambda expressions and their corresponding delegates.

//Explicitly typed parameter
(Person obj) => MessageBox.Show(obj.FirstName.ToUpper());

//Implicitly typed parameter
(obj) => obj.FirstName == "Thiru";

//Explicitly typed parameter
(int a, int b) => a + b

//Implicitly typed parameter
(x, y) => { return x + y; }

As you see from the preceding lines of code, lambda expressions can be written in such a way that itcan infer the parameter type from the signature of the delegate it is assigned to.




. Query expressions

Even though further enhancements may be introduced in the coming months as C# 3.0 matures, the new features described in the preceding sections make it a lot easier to work with data inside C# in general. This feature, also known as LINQ (Language Integrated Query), allows you to write SQL-like syntax in C#.

For instance, you may have a class that describes your data as follows:

public class CoOrdinate
{
public int x ;
public int y;
}

You now could easily declare the logical equivalent of a database table inside C# as follows:

// Use Object and collection initializers
List coords = ... ;

And now that you have your data as a collection that implements IEnumerable, you easily can query this data as follows:

var filteredCoords =
from c in coords
where x == 1
select (c.x, c.y)

In the SQL-like syntax above, "from", "where", and "select" are query expressions that take advantage of C# 3.0 features such as anonymous types, extension methods, implicit typed local variables, and so forth. This way, you can leverage SQL-like syntax and work with disconnected data easily.

Each query expression is actually translated into a C#-like invocation behind the scenes. For instance, the following:

where x == 1
Translates to this:

coords.where(c => c.x == 1)
As you can see, the above looks an awful lot like a lambda expression and extension method. C# 3.0 has many other query expressions and rules that surround them.

. Expression Trees

Expression trees represent language-level code in the form of data. The data is stored in a tree-shaped structure. Each node in the expression tree represents an expression, for example a method call or a binary operation such as
x <>> exprTree = num => num < param =" (ParameterExpression)exprTree.Parameters[0];" operation =" (BinaryExpression)exprTree.Body;" left =" (ParameterExpression)operation.Left;" right =" (ConstantExpression)operation.Right;"> {1} {2} {3}",
param.Name, left.Name, operation.NodeType, right.Value);

/* This code produces the following output:

Decomposed expression: num => num LessThan 5
*/



. Implicitly typed arrays.

class ImplicitlyTypedArraySample
{
static void Main()
{
var a = new[] { 1, 10, 100, 1000 }; // int[]
var b = new[] { "hello", null, "world" }; // string[]

// single-dimension jagged array
var c = new[]
{
new[]{1,2,3,4},
new[]{5,6,7,8}
};

// jagged array of strings
var d = new[]
{
new[]{"Luca", "Mads", "Luke", "Dinesh"},
new[]{"Karen", "Suma", "Frances"}
};
}
}

.Net Framework 2.0 Features (New)

1.C#.Net 2.0 and ASP.Net 2.0
//-------------------------------

a.New Features in C# 2.0
/////----------------------------------------
1.New Features in C# 2.0
. Generic Types

Generics were added to version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations, as shown here:

C#
// Declare the generic class.
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int.
GenericList list1 = new GenericList();

// Declare a list of type string.
GenericList list2 = new GenericList();

// Declare a list of type ExampleClass.
GenericList list3 = new GenericList();
}
}

Generics Overview

--------------------------------------------------------------------------------

Use generic types to maximize code reuse, type safety, and performance.

The most common use of generics is to create collection classes.

The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace.These should be used whenever possible instead of classes such as ArrayList in the System.Collections namespace.

You can create your own generic interfaces, classes, methods, events and delegates.

Generic classes may be constrained to enable access to methods on particular data types.

Information on the types that are used in a generic data type may be obtained at run-time by using reflection.

. Iterators

In this example, the DaysOfTheWeek class is a simple collection class that stores the days of the week as strings. After each iteration of a foreach loop, the next string in the collection is returned.

C#
public class DaysOfTheWeek : System.Collections.IEnumerable
{
string[] days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };

public System.Collections.IEnumerator GetEnumerator()
{
for (int i = 0; i < week =" new">, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A Nullable can be assigned the values true or false, or null. The ability to assign null to numeric and Boolean types is particularly useful when dealing with databases and other data types containing elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.

C#
class NullableExample
{
static void Main()
{
int? num = null;
if (num.HasValue == true)
{
System.Console.WriteLine("num = " + num.Value);
}
else
{
System.Console.WriteLine("num = Null");
}

//y is set to zero
int y = num.GetValueOrDefault();

// num.Value throws an InvalidOperationException if num.HasValue is false
try
{
y = num.Value;
}
catch (System.InvalidOperationException e)
{
System.Console.WriteLine(e.Message);
}
}
}

. Anonymous Methods

Creating anonymous methods is essentially a way to pass a code block as a delegate parameter. For example:

// Create a handler for a click event
button1.Click += delegate(System.Object o, System.EventArgs e)
{ System.Windows.Forms.MessageBox.Show("Click!"); };

// Create a delegate instance
delegate void Del(int x);

// Instantiate the delegate using an anonymous method
Del d = delegate(int k) { /* ... */ };

By using anonymous methods, you reduce the coding overhead in instantiating delegates by eliminating the need to create a separate method.

. Covariant and Contravariant Delegates

Covariance and contravariance provide a degree of flexibility when matching method signatures with delegate types. Covariance permits a method to have a more derived return type than what is defined in the delegate. Contravariance permits a method with parameter types that are less derived than in the delegate type.


Example 1 (Covariance)

--------------------------------------------------------------------------------

This example demonstrates how delegates can be used with methods that have return types that are derived from the return type in the delegate signature. The data type returned by SecondHandler is of type Dogs, which derives from the Mammals type that is defined in the delegate.


Class Mammals
{
}

class Dogs : Mammals
{
}

class Program
{
// Define the delegate.
public delegate Mammals HandlerMethod();

public static Mammals FirstHandler()
{
return null;
}

public static Dogs SecondHandler()
{
return null;
}

static void Main()
{
HandlerMethod handler1 = FirstHandler;

// Covariance allows this delegate.
HandlerMethod handler2 = SecondHandler;
}
}

Example 2 (Contravariance)

--------------------------------------------------------------------------------

This example demonstrates how delegates can be used with methods that have parameters of a type that are base types of the delegate signature parameter type. With contravariance, you can now use one event handler in places where, previously, you would have had to use separate handlers. For example, you can now create an event handler that accepts an EventArgs input parameter and use it with the Button.MouseClick event that sends a MouseEventArgs type as a parameter, and also with TextBox.KeyDown event that sends a KeyEventArgs parameter.


System.DateTime lastActivity;
public Form1()
{
InitializeComponent();

lastActivity = new System.DateTime();
this.textBox1.KeyDown += this.MultiHandler; //works with KeyEventArgs
this.button1.MouseClick += this.MultiHandler; //works with MouseEventArgs

}

// Event hander for any event with an EventArgs or
// derived class in the second parameter
private void MultiHandler(object sender, System.EventArgs e)
{
lastActivity = System.DateTime.Now;
}


. Simplified Delegate Instantiation



. Accessor Accessibility

private string name = "Hello";

public string Name
{
get
{
return name;
}
protected set
{
name = value;
}
}


. Namespace Alias Qualifier

using colAlias = System.Collections;
namespace System
{
class TestClass
{
static void Main()
{
// Searching the alias:
colAlias::Hashtable test = new colAlias::Hashtable();

// Add items to the table.
test.Add("A", "1");
test.Add("B", "2");
test.Add("C", "3");

foreach (string name in test.Keys)
{
// Seaching the gloabal namespace:
global::System.Console.WriteLine(name + " " + test[name]);
}
}
}
}

Example 2

class TestApp
{
// Define a new class called 'System' to cause problems.
public class System { }

// Define a constant called 'Console' to cause more problems.
const int Console = 7;
const int number = 66;

static void Main()
{
// Error Accesses TestApp.Console
//Console.WriteLine(number);
global::System.Console.WriteLine("Working");
}
}

. Static Classes
. extern
. Fixed Size Buffers
. Friend Assemblies
. Compiler Pragma



2.Windows Forms in .NET 2.0
. ToolStrip Control
. SplitContainer Control
. Web Browser Control
. DataGridView Control
. Other New .NET 2.0 Controls
. New Data Binding
. Application Settings
. BackgroundWorker Component
. ClickOnce Deployment



3.New Features in ADO.NET and XML
. Asynchronous Database Operations
. Server Enumeration
. Multiple Active Result Sets
. Bulk Copy in ADO.NET
. Edit Capability in XPathNavigator
. Efficient XSLT Processor


b.New Features in ASP.NET 2.0
/////----------------------------------------
1.Fundamentals of ASP.NET 2.0
. ASP.NET 2.0 Applications
. Visual Web Developer
. Using Components
. New Controls
. Menus
. Master Pages



2.Data Access in ASP.NET 2.0
. Data Source Controls
. Connection String Storage
. GridView
. DetailsView
. FormView
. XML Support
. Object Data Sources



3.Personalization and Security in ASP.NET 2.0
. Themes
. Skins
. Membership and Roles
. Login Controls
. User Profiles
. Web Parts

Wednesday, November 11, 2009

WSDL Article

http://www.w3.org/TR/wsdl#_rpcexample

Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer

useful Link for
--------------->
Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer

http://www.15seconds.com/Issue/050106.htm

Monday, November 9, 2009

ACID properties of the database

Explain ACID properties of the database?

All Database systems which include transaction support implement ACID properties to ensure the integrity of the database. ACID stands for Atomicity, Consistency, Isolation and Durability

  • Atomicity: Each transaction is said to be “atomic.” If one part of the transaction fails, the entire transaction fails. Modifications on the data in the database either fail or succeed.
  • Consistency: This property ensures that only valid data will be written to the database. If, for some reason, a transaction is executed that violates the database’s consistency rules, the entire transaction will be rolled back and the database will be restored to a state consistent with those rules.
  • Isolation: It requires that multiple transactions occurring at the same time not impact each other’s execution.
  • Durability: It ensures that any transaction committed to the database will not be lost.