Step 1 : Design of webform1.aspx


ajax7


Step 2 : Webform1.aspx.cs code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace ConnectToDatabase
{
    public partial class WebForm1 : System.Web.UI.Page
    {
      

        protected void Button1_Click(object sender, EventArgs e)
        {
            string cs = "server=NAGABABU-PC;database=Nagababu;uid=sa;pwd=naga999";
            SqlConnection con = new SqlConnection(cs);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from emp", con);
            SqlDataReader dr = cmd.ExecuteReader();

            GridView1.DataSource = dr;
            GridView1.DataBind();
            con.Close();
                  
           
        }
    }
}

♣    When we execute the above application one request will be generated from the client for webform1.aspx, that request is called as first request which is processing by web server.

♣    When user will click the display button from the same client one more request will be generated for the same webpage which request is called as post back request. The above web page is following client centric programming model, due to that reason this post back request is processing by client, as part of processing this request it is demanding for emp table data due to that reason client will communicate the web server and web server will communicate the database server to get the emp table.