Wednesday, 28 December 2011

Lets start with Introduction of ASP.NET

Microsoft's previous server side scripting technology ASP (Active Server Pages) is now often called classic ASP.
ASP 3.0 was the last version of classic ASP.
ASP.NET is the next generation ASP, but it's not an upgraded version of ASP.
ASP.NET is an entirely new technology for server-side scripting. It was written from the ground up and is not backward compatible with classic ASP.
You can read more about the differences between ASP and ASP.NET in the next chapter of this tutorial.
ASP.NET is the major part of the Microsoft's .NET Framework.


What is ASP.NET?

ASP.NET is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server.
  • ASP.NET is a Microsoft Technology
  • ASP stands for Active Server Pages
  • ASP.NET is a program that runs inside IIS
  • IIS (Internet Information Services) is Microsoft's Internet server
  • IIS comes as a free component with Windows servers
  • IIS is also a part of Windows 2000 and XP Professional

What is an ASP.NET File?

  • An ASP.NET file is just the same as an HTML file
  • An ASP.NET file can contain HTML, XML, and scripts
  • Scripts in an ASP.NET file are executed on the server
  • An ASP.NET file has the file extension ".aspx"

How Does ASP.NET Work?

  • When a browser requests an HTML file, the server returns the file
  • When a browser requests an ASP.NET file, IIS passes the request to the ASP.NET engine on the server
  • The ASP.NET engine reads the file, line by line, and executes the scripts in the file
  • Finally, the ASP.NET file is returned to the browser as plain HTML

The Microsoft .NET Framework

The .NET Framework is the infrastructure for the Microsoft .NET platform.
The .NET Framework is an environment for building, deploying, and running Web applications and Web Services.
Microsoft's first server technology ASP (Active Server Pages), was a powerful and flexible "programming language". But it was too code oriented. It was not an application framework and not an enterprise development tool.
The Microsoft .NET Framework was developed to solve this problem.
.NET Frameworks keywords:
  • Easier and quicker programming
  • Reduced amount of code
  • Declarative programming model
  • Richer server control hierarchy with events
  • Larger class library
  • Better support for development tools
The .NET Framework consists of 3 main parts:
Programming languages:
  • C# (Pronounced C sharp)
  • Visual Basic (VB .NET)
  • J# (Pronounced J sharp)
Server technologies and client technologies:
  • ASP .NET (Active Server Pages)
  • Windows Forms (Windows desktop solutions)
  • Compact Framework (PDA / Mobile solutions)
Development environments:
  • Visual Studio .NET (VS .NET)
  • Visual Web Developer
ASP.NET has better language support, a large set of new controls, XML-based components, and better user authentication.
ASP.NET provides increased performance by running compiled code.
ASP.NET code is not fully backward compatible with ASP.

New in ASP.NET

  • Better language support
  • Programmable controls
  • Event-driven programming
  • XML-based components
  • User authentication, with accounts and roles
  • Higher scalability
  • Increased performance - Compiled code
  • Easier configuration and deployment
  • Not fully ASP compatible

Language Support

ASP.NET uses ADO.NET.
ASP.NET supports full Visual Basic, not VBScript.
ASP.NET supports C# (C sharp) and C++.
ASP.NET supports JScript.

ASP.NET Controls

ASP.NET contains a large set of HTML controls. Almost all HTML elements on a page can be defined as ASP.NET control objects that can be controlled by scripts.
ASP.NET also contains a new set of object-oriented input controls, like programmable list-boxes and validation controls.
A new data grid control supports sorting, data paging, and everything you can expect from a dataset control.

Event Aware Controls

All ASP.NET objects on a Web page can expose events that can be processed by ASP.NET code.
Load, Click and Change events handled by code makes coding much simpler and much better organized.

ASP.NET Components

ASP.NET components are heavily based on XML. Like the new AD Rotator, that uses XML to store advertisement information and configuration.

User Authentication

ASP.NET supports form-based user authentication, cookie management, and automatic redirecting of unauthorized logins.

User Accounts and Roles

ASP.NET allows user accounts and roles, to give each user (with a given role) access to different server code and executables.

High Scalability

Much has been done with ASP.NET to provide greater scalability.
Server-to-server communication has been greatly enhanced, making it possible to scale an application over several servers. One example of this is the ability to run XML parsers, XSL transformations and even resource hungry session objects on other servers.

Compiled Code

The first request for an ASP.NET page on the server will compile the ASP.NET code and keep a cached copy in memory. The result of this is greatly increased performance.

Easy Configuration

Configuration of ASP.NET is done with plain text files.
Configuration files can be uploaded or changed while the application is running. No need to restart the server. No more metabase or registry puzzle.

Easy Deployment

No more server-restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.

Compatibility

ASP.NET is not fully compatible with earlier versions of ASP, so most of the old ASP code will need some changes to run under ASP.NET.
To overcome this problem, ASP.NET uses a new file extension ".aspx". This will make ASP.NET applications able to run side by side with standard ASP applications on the same server.

Using Microsoft Office Access as database in asp.net


Using Microsoft Office Access as database in asp.net


ESTABLISHING A CONNETION TO THE ACCESS DATABASE :

OleDbConnection connection= new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " + "Data Source=" + Server.MapPath("PATH OF THE ACCESS DATABASE"));
        OleDbCommand command = new OleDbCommand();

        command .CommandText = "TYPE YOUR SQL QUERY HERE";
        command .CommandType = CommandType.Text;
        command .Connection = connection;

        connection.Open();

        command .ExecuteNonQuery();
   
        connection.Close();

----------------------------------------------------------------------------------------------------------
BINDING THE DATA CONTROL WITH ACCESS DATABASE :

OleDbConnection connection= new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " + "Data Source=" + Server.MapPath("App_Data/Database1.accdb"));
        OleDbCommand command = new OleDbCommand("Select * FROM Table_Detail", conn);
        connection.Open();

        OleDbDataReader reader = command .ExecuteReader();

        GridView1.DataSource = reader;
        GridView1.DataBind();

        connection.Close();

Using Microsoft SQL Server as Database in asp.net ESTABLISHMENT OF CONNECTION TO SQL SERVER :


Using Microsoft SQL Server as Database in asp.net

ESTABLISHMENT OF CONNECTION TO SQL SERVER :



SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();


if (connection .State == ConnectionState.Closed)
{
        connection .ConnectionString = "CONNECTION STRING HERE";
        connection .Open();
}
command .CommandText = "SQL QUERY HERE";
command .Connection = connection ;

//PERFORM THE OPERATIONS HERE ACCORDINGLY

connection .Close();
----------------------------------------------------------------------------------------------------------
USING SqlDataReader :



SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();


if (connection .State == ConnectionState.Closed)
{
        connection .ConnectionString = "CONNECTION STRING HERE";
        connection .Open();
}
command .CommandText = "SQL QUERY HERE";
command .Connection = connection ;

SqlDataReader datareader = command .ExecuteReader();

connection .Close();
---------------------------------------------------------------------------------------------------------
USING DataAdapter :


DataSet obj = new DataSet();

SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
SqlDataAdapter adapter = new SqlDataAdapter();


if (connection .State == ConnectionState.Closed)
{
        connection .ConnectionString = "CONNECTION STRING HERE";
        connection .Open();
}
command .CommandText = "SQL QUERY HERE";
command .Connection = connection ;


adapter .SelectCommand = command ;
adapter .Fill(obj);


connection .Close();


How to Store Image in Database in ASP.NET


How to Store Image in Database in ASP.NET


byte[] imgbyte = FileUpload1.FileBytes;
            SqlConnection connection = new SqlConnection("Type Connection String Here");
            SqlCommand command = new SqlCommand("INSERT INTO Table_Image(Name,Image) VALUES (@name,@image)", connection );

            connection .Open();
            command .Parameters.AddWithValue("@name", TextBox1.Text);

            SqlParameter img = new SqlParameter("@image", SqlDbType.Image, imgbyte.Length);
            img.Value = imgbyte;
            command .Parameters.Add(img);

            command .ExecuteNonQuery();
            connection .Close();

Applying pagination in DataList


Applying pagination in DataList

DataListPagination.aspx :


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataListPagination.aspx.cs" Inherits="DataListPagination" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <br />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="Default.aspx">Default</asp:HyperLink>
        <br /><br /><br /><br />
    <div>
     
        <asp:DataList ID="DataList1" runat="server" BackColor="White"
            BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
            DataKeyField="id" GridLines="Both"
            RepeatColumns="3" RepeatDirection="Horizontal">
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            <ItemStyle BackColor="White" ForeColor="#003399" />
            <ItemTemplate>
                id:
                <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                <br />
                Fname:
                <asp:Label ID="FnameLabel" runat="server" Text='<%# Eval("Fname") %>' />
                <br />
                Lname:
                <asp:Label ID="LnameLabel" runat="server" Text='<%# Eval("Lname") %>' />
                <br />
                Username:
                <asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
                <br />
                Email:
                <asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
                <br />
                DOB:
                <asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
                <br />
<br />
            </ItemTemplate>
            <SelectedItemStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        </asp:DataList>
        <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Previous</asp:LinkButton>
        <asp:DataList ID="DataList2" runat="server"
            onitemcommand="DataList2_ItemCommand"
            onitemdatabound="DataList2_ItemDataBound" RepeatColumns="10"
            RepeatDirection="Horizontal">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("PageIndex") %>' CommandName="lnkbtnPaging" Text='<%# Eval("PageText") %>'></asp:LinkButton>
            </ItemTemplate>
        </asp:DataList>
        <asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click">Next</asp:LinkButton>
        <br />

    </div>
    </form>
</body>


DataListPagination.aspx.cs ::


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.SqlClient;
using System.Configuration;

public partial class DataListPagination : System.Web.UI.Page
{
    PagedDataSource pds = new PagedDataSource();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    public int CurrentPage
    {

        get
        {
            if (this.ViewState["CurrentPage"] == null)
                return 0;
            else
                return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
        }

        set
        {
            this.ViewState["CurrentPage"] = value;
        }

    }

    private void BindGrid()
    {
        string sql = "SELECT [id], [Fname], [Lname], [Username], [Email], [DOB] FROM [Table_Login]";
        SqlDataAdapter da = new SqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["mystring"].ConnectionString);
        DataTable dt = new DataTable();
        da.Fill(dt);
     
        pds.DataSource = dt.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 3;
        pds.CurrentPageIndex = CurrentPage;
        LinkButton3.Enabled = !pds.IsLastPage;
        LinkButton2.Enabled = !pds.IsFirstPage;

        DataList1.DataSource = pds;
        DataList1.DataBind();

        doPaging();
    }
    private void doPaging()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("PageIndex");
        dt.Columns.Add("PageText");
        for (int i = 0; i < pds.PageCount; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = i;
            dr[1] = i + 1;
            dt.Rows.Add(dr);
        }

        DataList2.DataSource = dt;
        DataList2.DataBind();
    }


    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("lnkbtnPaging"))
        {
            CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
            BindGrid();
        }
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        CurrentPage -= 1;
        BindGrid();
    }

    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        CurrentPage += 1;
        BindGrid();
    }

    //protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    CurrentPage = 0;
    //    BindGrid();
    //}

    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("LinkButton1");
        if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
        {
            lnkbtnPage.Enabled = false;
            lnkbtnPage.Font.Bold = true;
        }
    }
}

How to use Accordion


How to use Accordion


<asp:Accordion ID="Accordion1" runat="server" SelectedIndex="0"
            HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected"
            ContentCssClass="accordionContent" FadeTransitions="false" FramesPerSecond="40"
            TransitionDuration="250" AutoSize="None" RequireOpenedPane="false" SuppressHeaderPostbacks="true">
           <Panes>

                <asp:AccordionPane ID="a1" runat="server">
                    <Header>
                        1. Accordion
                    </Header>
                    <Content>
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
                    </Content>
                </asp:AccordionPane>

                <asp:AccordionPane ID="a2" runat="server">
                    <Header>
                        2. Accordion
                    </Header>
                    <Content>
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
                    </Content>
                </asp:AccordionPane>

                <asp:AccordionPane ID="a3" runat="server">
                    <Header>
                        3. Accordion
                    </Header>
                    <Content>
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
                    </Content>
                </asp:AccordionPane>

            </Panes>
        </asp:Accordion>

AutoCompleteExtender in ASP.NET


AutoCompleteExtender in ASP.NET


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
            TargetControlID="TextBox1" ServiceMethod="GetCompletionList"
            ServicePath="AjaxLearning.asmx" MinimumPrefixLength="1"
            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
            CompletionListItemCssClass="autocomplete_listItem"
            CompletionListCssClass="autocomplete_completionListElement"
            ShowOnlyCurrentWordInCompletionListItem="True">

        </asp:AutoCompleteExtender>

No comments:

Post a Comment