Monday 27 February 2012

Introduction to .Net Framework


Microsoft started development on the .NET Framework in the late 1990s originally under the name of Next Generation Windows Services (NGWS). By late 2000 the first beta versions of .NET 1.0 were released.

Version
Release Date
05-01-2002
01-04-2003
07-11-2005
06-11-2006
19-11-2007

.NET Framework 1.0

This is the first release of the .NET Framework. Released on February 13, 2002. Available for Windows 98, NT 4.0, 2000, and XP.

.NET Framework 1.1

This is the first major .NET Framework upgrade and was published on April 3, 2003. It is also part of the second release of Microsoft Visual Studio .NET (released as Visual Studio .NET 2003). This is the first version of the .NET Framework to be included as part of the Windows operating system, shipping with Windows Server 2003.

Changes since 1.0

  • Built-in support for mobile ASP.NET controls. Previously available as an add-on for .NET Framework, now part of the framework.
  • Built-in support for ODBC and Oracle databases. Previously available as an add-on for .NET Framework 1.0, now part of the framework.
  • .NET Compact Framework - a version of the .NET Framework for small devices.
  • Numerous API changes.

.NET Framework 2.0

 Changes since 1.1

  • Numerous API changes.
  • Language support for Generics built directly into the .NET CLR.
  • Many additional and improved ASP.NET web controls.
  • New data controls with declarative data binding.
  • New personalization features for ASP.NET, such as support for themes, skins and webparts.

.NET Framework 3.0

Formerly called WinFX, includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems. It consists of four major new components:

 .NET Framework 3.5

Version 3.5 of the .NET Framework was officially released to manufacturing (RTM) on November 19, 2007.
As with previous versions, a new .NET Compact Framework 3.5 was released in tandem with this update in order to provide support for additional features on Windows Mobile and Windows Embedded CE devices.

Changes since version 3.0

  • New language features in C# 3.0 and VB.NET 9.0 compiler
  • Adds support for expression trees and lambda methods
  • Extension methods
  • Anonymous types with static type inference
  • Language Integrated Query (LINQ) along with its various providers
    • LINQ to Objects
    • LINQ to XML
    • LINQ to SQL
  • Paging support for ADO.NET
  • ADO.NET synchronization API to synchronize local caches and server side datastores
  • ASP.NET AJAX is included

SP1 (codename "Arrowhead")

.NET Framework 3.5 SP1, codenamed "Arrowhead", reportedly will enhance support for occasionally connected applications, and provide built-in support for the Microsoft ASP.NET Model-View-Controller (MVC) Framework.

Future development

Microsoft has not yet made public a roadmap of the development plans for future edition of .NET framework, but has released general information regarding it. To this end, it will include technologies like PLINQ (Parallel LINQ), a parallel implementation of the LINQ engine, and Task Parallel Library, which exposes parallel constructs via method calls.

Introduction to C#


C Sharp (programming language)

C# is an object-oriented programming language developed by Microsoft as part of the .NET initiative and later approved as a standard by ECMA and ISO . Anders Hejlsberg leads development of the C# language, which has a procedural, object-oriented syntax based on C++ and includes influences from aspects of several other programming languages (most notably Delphi and Java) with a particular emphasis on simplification.

History

During the development of .NET, the class libraries were originally written in a language called Simple Managed C (SMC). In January 1999, Anders Hejlsberg formed a team to build a new language at the time called Cool. By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference (PDC), the language had been renamed C# and the class libraries and ASP.NET runtime had been ported to C#.

C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg, who was previously involved with the design of Visual J++, Borland Delphi, and Turbo Pascal. In interviews and technical papers he has stated that flaws in most major programming languages (e.g. C++, Java, Delphi, and Smalltalk) drove the fundamentals of the Common Language Runtime (CLR), which, in turn, drove the design of the C# programming language itself.

Design goals

The ECMA standard lists these design goals for C#:
  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • Because software robustness, durability and programmer productivity are important, the language should include strong type checking, array bounds checking, detection of attempts to use uninitialized variables, source code portability, and automatic garbage collection.
  • The language is intended for use in developing software components that can take advantage of distributed environments.
  • Programmer portability is very important, especially for those programmers already familiar with C and C++.
  • Support for internationalization is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions.
Versions
1.0, 1.5, 2.0 (ECMA), 3.0

Features

C# differs from C and C++ in many ways, including:
  • There are no global variables or functions. All methods and members must be declared within classes. It is possible, however, to use static methods/variables within public classes instead of global variables/functions.
  • Multiple inheritance is not supported, although a class can implement any number of interfaces. This was a design decision by the language's lead architect to avoid complication.
  • Full type reflection and discovery is available.

Features of C# 2.0

New features in C# for the .NET SDK 2.0 (corresponding to the 3rd edition of the ECMA-334 standard) are:
  • Partial classes allow class implementation across more than one source file. This permits splitting up very large classes.
  • Generics or parameterized types.
  • Static classes that cannot be instantiated, and that only allow static members. This is similar to the concept of module in many procedural languages.
  • Anonymous delegates.
  • The accessibility of property accessors can be set independently.
  • Nullable value types which provides improved interaction with SQL databases.
  • Coalesce operator: (??) returns the first of its operands which is not null (or null, if no such operand exists):

Features of C# 3.0

C# 3.0 is the current version, and was released on 19 November 2007 as part of .NET Framework 3.5. It includes new features inspired by functional programming languages such as Haskell and ML, and is driven largely by the introduction of the Language Integrated Query (LINQ) pattern to the Common Language Runtime.[9]
 C# 3.0 was unveiled at the 2005 Professional Developers Conference. It is not currently standardized by any standards organisation, though it is expected that it will eventually become an ECMA and then ISO standard, as did its predecessors.

Criticism

Performance 
C# programs, like all programs written for the .NET and other virtual machine environments such as Java, tend to require more system resources than functionally similar applications that access machine resources more directly.

Platform 
Microsoft's current .NET implementation is only available on Windows.

Saturday 25 February 2012

Restrict Checkboxlist To Single Selection


How we can restrict checkboxlist to single selection
(Or)
How we can do checkboxlist behaves like a radiobuttonlist

Javascript Code:

<script type = "text/javascript">

    function MutExChkList(chk)
    {
        var chkList = chk.parentNode.parentNode.parentNode;
        var chks = chkList.getElementsByTagName("input");
        for(var i=0;i<chks.length;i++)
        {
            if(chks[i] != chk && chk.checked)
            {
                chks[i].checked=false;
            }
        }
    }

</script>

Design View of the CheckBoxList:

                <asp:CheckBoxList ID="cblSelect" runat="server" RepeatLayout="Flow" >
                <asp:ListItem Text="Yes" Value="Y" onclick="MutExChkList(this);" ></asp:ListItem>
                <asp:ListItem Text="No" Value="N" onclick="MutExChkList(this);"></asp:ListItem>
                </asp:CheckBoxList>

All the best,
Prakash

Monday 20 February 2012

AJAX Introduction & How To Download AJAX Toolkit



Hi guys,



Please click the below link and download the file.  In that, you will get notes on AJAX introduction with explanation and examples and also how to download AJAX Toolkit and the procedure on how to add into our visual studio .Net.


AJAX Introduction and How to Download AJAX Toolkit


Regards,
Prakash

How To Install IIS on Windows 7 or Vista


If you are a developer using ASP.NET, one of the first things you’ll want to install on Windows 7 or Vista is IIS (internet information server). Keep in mind that your version of Windows may not come with IIS. I’m using Windows 7 Ultimate edition.
First, go to Control Panel, and then click on Programs. You’ll see a link for “Turn Windows features on or off”


If you expand the Internet Information Services tree node, you can see that there are a lot of options beneath it. You will probably want to explore these options, because even if you click on IIS, some of the necessary options for doing development aren’t checked.
Once you’ve gone ahead and checked the items you want, and clicked OK, you’ll see this dialog for a while….
Now when you navigate in your browser to localhost, you’ll see the new default page… slick!

How To Install IIS in Windows XP




To install IIS 5.1 in Windows XP Pro follow these steps:
  1. On the Start menu, click Control Panel.
  2. Double-click Add or Remove Programs.
  3. Click Add/Remove Windows Components.
  4. Click Internet Information Services (IIS) and then click Details.
  5. In Internet Information Services (IIS), select the check boxes for SMTP Service and World Wide Web Service, and then click OK.
  6. In Windows Component selection, ensure that the Internet Information Services (IIS) check box is selected, and then click OK to install the components that you selected.


Friday 17 February 2012

ASP.Net Themes and Skins

ASP.NET Themes and Skins


ASP.NET Themes and ASP.NET skins are another method of adding style and consistency to ASP.NET pages without managing each page and control separately. Themes and skins are an alternative to using Master Pages.

ASP.NET themes are a unified look which can be applied to every page in a web site. ASP.NET skins are also like a theme, but it can be applied to Controls like Buttons Controls, DropDownList Controls. The following ASP.NET tutorial helps you learn the basics on ASP.NET Themes and ASP.NET Skins with a sample Theme you can build on.

Creating an ASP.NET Theme

Themes and skins are good for adding style and consistency to ASP.NET pages without managing each page and control separately. But in order to use ASP.NET Themes and ASP.NET skins, you should first create and ASP.NET Theme.  ASP.NET by default searches for available themes in a folder called App_Themes. The following steps show you how to create this folder and start a new theme, and design skins for two ASP.NET Controls.

1.    Right click the Project name in the Solution Explorer and select Add ASP.NET Folder - -> Theme from the Context Menu.
 
2.    Rename Theme1 to “myTheme”.
 
3.    Right Click the “myTheme” folder and add a Skin File named customSkin.skin. The customSkin.skin file will open with the default skin template.

4.    At the bottom of the customSkin.skin File, after the “--%>” markup, enter the following skin description code.

<asp:DropDownList runat="server" CssClass="myCustomStyle" >
</asp:DropDownList>
<asp:Button runat="server" BorderStyle="Dotted" CssClass="myCustomStyle" />

5.    Right Click on the “myTheme” folder and Add a new Style Sheet named “myCustom.css” to the Project.
6.    Add the following Style Class into the “myCustom.css”.

myCustomStyle
{
background-color:#ccffcc;
font-style: italic;
font-family: Arial, Tahoma, 'Trebuchet MS';
font-size: xx-large;
}

Now you have successfully created a skin for an ASP.NET DropDownList Control and a Button Control. The content of the “customSkin.skin” declares that all controls of these types should use the “CssClass” called “myCustom.css”. The “myCustomStyle” class is in the “myCustom.css”.

The Button control has been programmed to use a dotted border style in the “customSkin.skin”. This property isn’t part of the style sheet and therefore applies only to buttons and not to the DropDownList control.

Applying Theme to a Web Site

The best and the fastest way to tell every page and every control in a web site to use a given theme is to code it in the “web.config” file. The following steps show you how to make a theme available site wide.

1.    Open the “web.config” file from the Solution Explorer.
Note:  If you do not have a “web.config” file, run the application for the first time, and it will ask whether to create one or not.

2.    Go to the element starting with “<pages” within the “<system.web>” section.
Note:  If the “web.config” file does not have “<pages” just type in this tag, and Visual Studio will suggest and help you auto fill it.

3.    Add the following code snippet after the “<pages” for the “theme” attribute.

<pages theme="myTheme">
</pages>

At runtime, every page in the web site now knows to use the “myTheme” ASP.NET theme. This ASP.NET theme makes the DropDownList and the Button Controls within the pages to use the “myTheme” ASP.NET theme styles.

You also can use the “styleSheetTheme” attribute instead of the theme attribute. The “styleSheetTheme” attribute allows local setting to override the global theme.

<pages styleSheetTheme="myTheme">
</pages>

Applying Theme to a Page

You also have the capability of setting a theme for an individual page alone by configuring its “theme” or “styleSheetTheme” settings. This allows different themes on different pages. The following steps show you how to apply a theme to an individual page.

1.    Remove any themes assigned in the “web.config” file. (Check Assigning a theme to the whole Web Site). This is because if you leave the theme declared in the “web.config” file, it effects for whole site, thus it overrides any theme applied to an individual page locally.
2.    Go to the Design View of the ASP.NET page.
3.    Select the page by clicking on the blank area and go to the Properties Window of the Document Object (You can also press F4).
4.    Set the “StyleSheetTheme” property to the name of you preferred theme (“myTheme”).

5.    Drag and drop a DropDownList and a Button Control on the page and you will see how the IDE looks up the “myTheme” ASP.NET theme and applies the style information in the Design View.

GridView with Example

GridView:
The GridView view mode displays a list of data items by binding data fields to columns and by displaying a column header to identify the field. The default GridView style implements buttons as column headers. By using buttons for column headers, you can implement important user interaction capabilities; for example, users can click the column header to sort GridView data according to the contents of a specific column.

The following illustration shows a GridView view of ListView content.

GridView view of ListView content

Styled ListView

GridView columns are represented by GridViewColumn objects, which can automatically size to their content. Optionally, you can explicitly set a GridViewColumn to a specific width. You can resize columns by dragging the gripper between column headers. You can also dynamically add, remove, replace, and reorder columns because this functionality is built into GridView. However, GridView cannot directly update the data that it displays.

The below code deals with inserting a data to a database and displaying the items to the grid aas well and this code mainly focuses on how to export the items on the grid to excel.

Here we deal with keywords like htmltextwriter and string writer, the string writer is mainly used for implementing htmltextwriter and the htmltextwriter is used for producing indented outputs and conversion purposes as well and the code is as follows

NOTE: set EnableEventValidation ="fase" at the top of your page


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
public partial class Default6 : System.Web.UI.Page
{
    string connection = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(connection);
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into Country values('" + TextBox1.Text + "','" + TextBox2.Text + "')", con);
        cmd.ExecuteNonQuery();
        con.Close();
        BindGrid();
    }
    private void BindGrid()
    {
        SqlConnection con = new SqlConnection(connection);
        con.Open();
        da = new SqlDataAdapter("Select * from Country", con);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {

    }
   
    private void ExportGridView()
    {
        string attachment = "attachment; filename=Country.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();

    }
   

    protected void btnExcel_Click(object sender, EventArgs e)
    {
        GridView1.Columns[2].Visible = false;
        GridView1.Columns[3].Visible = false;
        ExportGridView();
    }
    private void clear()
    {
        TextBox1.Text = string.Empty;
        TextBox2.Text = string.Empty;
        btnSave.Enabled = true;
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        this.clear();
    }
}

ASP.Net Caching

ASP.Net Caching

Introduction

The majority [if not all] of the pages in a dynamic website are dynamic.  That is, pages that are created on user request.  As we all know, dynamic web pages help to provide dynamic content, customized for the user requesting the page [e.g.: the user's home page].  Dynamic pages also help provide dynamic content fetched from a changing data store without the need for the administrator to change the page content every time something changes in the data store [e.g.: Listing of books in a publisher's website].  The disadvantage is the overhead in creating the pages for every user request.

To overcome this, some websites have page creation engines which create all pages in one go and save them as HTML pages which are then served to the users.  But this will only help in scenarios where the page content is the same for all requests [user-independent].  The listing of books is the same irrespective of the user requesting the page.  Even if there is provision for listing books category wise by providing different category ID values through the querystring, the page output for a particular category of books is the same for all users.

ASP.NET provides support for "caching" which will help us solve this problem to a great extend.  It can cache [store in memory] the output generated by a page and will serve this cached content for future requests.  And this is useful only in the second scenario described earlier, where the page content is the same for all requests [user-independent].  The caching feature is customizable in various ways and we will see how we can do that as we go through this article.

Caching a page

In order to cache a page's output, we need to specify an @OutputCache directive at the top of the page.  The syntax is as shown below:

<%@ OutputCache Duration=5 VaryByParam="None" %>

As you can see, there are two attributes to this directive.  They are:
·                                 Duration - The time in seconds of how long the output should be cached.  After the specified duration has elapsed, the cached output will be removed and page content generated for the next request.  That output will again be cached for 10 seconds and the process repeats. 
·                                 VaryByParam - This attribute is compulsory and specifies the querystring parameters to vary the cache. 
In the above snippet, we have specified the VaryByParam attribute as None which means the page content to be served is the same regardless of the parameters passed through the querystring.

If there are two requests to the same page with varying querystring parameters, e.g.: .../PageCachingByParam.aspx?id=12 and .../PageCachingByParam.aspx?id=15] and separate page content is generated for each of them, the directive should be:

<%@ OutputCache Duration=5 VaryByParam="id" %>

The page content for the two requests will each be cached for the time specified by the Duration attribute.
To specify multiple parameters, use semicolon to separate the parameter names.  If we specify the VaryByParam attribute as *, the cached content is varied for all parameters passed through the querystring.

Some pages generate different content for different browsers.  In such cases, there is provision to vary the cached output for different browsers.  The @OutputCache directive has to be modified to:

<%@ OutputCache Duration=5 VaryByParam="id" VaryByCustom="browser" %>

This will vary the cached output not only for the browser but also its major version.  I.e., IE5, IE 6, Netscape 4, Netscape 6 will all get different cached versions of the output.

Caching page fragments

Sometimes we might want to cache just portions of a page.  For example, we might have a header for our page which will have the same content for all users.  There might be some text/image in the header which might change everyday.  In that case, we will want to cache this header for a duration of a day.

The solution is to put the header contents into a user control and then specify that the user control content should be cached.  This technique is called fragment caching.

To specify that a user control should be cached, we use the @OutputCache directive just like we used it for the page.

<%@ OutputCache Duration=10 VaryByParam="None" %>

With the above directive, the user control content will be cached for the time specified by the Duration attribute [10 secs].  Regardless of the querystring parameters and browser type and/or version, the same cached output is served.

Data Caching

ASP.NET also supports caching of data as objects.  We can store objects in memory and use them across various pages in our application.  This feature is implemented using the Cache class.  This cache has a lifetime equivalent to that of the application.  Objects can be stored as name value pairs in the cache.  A string value can be inserted into the cache as follows:

Cache["name"]="Smitha";

The stored string value can be retrieved like this:

if (Cache["name"] != null)
    Label1.Text= Cache["name"].ToString();

To insert objects into the cache, the Add method or different versions of the Insert method of the Cache class can be used.  These methods allow us to use the more powerful features provided by the Cache class.  One of the overloads of the Insert method is used as follows:

Cache.Insert("Name", strName, 
    new CacheDependency(Server.MapPath("name.txt"), 
    DateTime.Now.AddMinutes(2), TimeSpan.Zero);

The first two parameters are the key and the object to be inserted.  The third parameter is of type CacheDependency and helps us set a dependency of this value to the file named name.txt.  So whenever this file changes, the value in the cache is removed.  We can specify null to indicate no dependency.  The fourth parameter specifies the time at which the value should be removed from cache.  The last parameter is the sliding expiration parameter which shows the time interval after which the item is to be removed from the cache after its last accessed time.

The cache automatically removes the least used items from memory, when system memory becomes low.  This process is called scavenging.  We can specify priority values for items we add to the cache so that some items are given more priority than others:

Cache.Insert("Name", strName, 
    new CacheDependency(Server.MapPath("name.txt"), 
    DateTime.Now.AddMinutes(2), TimeSpan.Zero, 
    CacheItemPriority.High, null);

The CacheItemPriority enumeration has members to set various priority values.  The CacheItemPriority.High assigns a priority level to an item so that the item is least likely to be deleted from the cache.