Skip to main content

Caching:Varying the Output Cache By Parameter in ASP.NET

OutPutCacheByPrameter.aspx

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



 



<!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>Caching; Varying the Output Cache By Parameter</title>



</head>



<body>



<form id="form1" runat="server">



<div>



<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="False"



ShowHeader="False">



<Columns>



<asp:HyperLinkField DataTextField="EmpName" DataNavigateUrlFields="EmpId"



DataNavigateUrlFormatString="EmployeeDetails.aspx?EmpId={0}" />



</Columns>



</asp:GridView>



</div>



</form>



</body>



</html>






Code File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class OutPutCacheByPrameter : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees";



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



grdEmployee.DataSource = ds;



grdEmployee.DataBind();



}



}



}






web.config:





<connectionStrings>



<add name="ConnectionStr" connectionString="Data Source=.;Initial Catalog=asp;User Id=sa;Password=niitbpl123"/>



</connectionStrings>






Code Behind File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class OutPutCacheByPrameter : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees";



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



grdEmployee.DataSource = ds;



grdEmployee.DataBind();



}



}



}






EmployeeDetails.aspx





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



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



<!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>CACHING: Output Cache By Parameter: Employee Details</title>



</head>



<body>



<form id="form1" runat="server">



<div>



<asp:Label ID="lblTime" runat="server"></asp:Label><br />



<br />



<asp:DetailsView ID="dtlEmployee" runat="server">



</asp:DetailsView>



</div>



</form>



</body>



</html>






Code Behind File:





using System;



using System.Collections;



using System.Configuration;



using System.Data;



using System.Linq;



using System.Web;



using System.Web.Security;



using System.Web.UI;



using System.Web.UI.HtmlControls;



using System.Web.UI.WebControls;



using System.Web.UI.WebControls.WebParts;



using System.Xml.Linq;



using System.Data.SqlClient;



 



public partial class EmployeeDetails : System.Web.UI.Page



{



SqlConnection con;



SqlCommand cmd = new SqlCommand();



DataSet ds = new DataSet();



SqlDataAdapter da;



protected void Page_Load(object sender, EventArgs e)



{



lblTime.Text = System.DateTime.Now.ToString();



BindData();



}



public void BindData()



{



string Appcon = ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString;



con = new SqlConnection(Appcon);



cmd.CommandText = "Select * from Employees where EmpId=" + Request.Params[0].ToString();



da = new SqlDataAdapter(cmd);



cmd.Connection = con;



con.Open();



cmd.ExecuteNonQuery();



da.Fill(ds);



if (ds.Tables[0].Rows.Count > 0)



{



dtlEmployee.DataSource = ds;



dtlEmployee.DataBind();



}



}



}






Output:



1a1b

Comments

  1. We provide personal finances for debt consolidation, bad credit finances, unsecured finances, finances for bad credit and instant secured finances with cheap rates. Do you have a firm or company that need finance to start up a business or need,personal finance, Debt consolidation? For more information. We will provide you with finance to meet your needs. For more information contact.

    We offer Easy and Fast Credit facility.
    Email: royalworldfundings@gmail.com

    Note: We offer the following finances to individuals-
    Commercial finances
    Personal finances
    Business finances
    Investments finances
    Development finances
    Acquisition finances
    Construction finances
    Business finances And many More at 3% interest rate;
    Contact Us At : royalworldfundings@gmail.com

    ReplyDelete
  2. If you had financial problems, then it is time for you to smile. You only need to contact Mr. Benjamin  with the amount you wish to borrow and the payment period that suits you and you will have your loan  within three working days. I just benefited for the sixth time a loan of 700 thousand dollars for a period of 180 months with the possibility of paying before the expiration date. Mr Benjamin has be helping me with loan.Make contact with him and you will see that he is a very honest man with a good heart.His email is lfdsloans@lemeridianfds.com and his WhatApp phone number is + 1-989-394-3740 

    ReplyDelete

Post a Comment

Popular posts from this blog

Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than 7000.

  #include<iostream.h> #include<conio.h> void main() { int totalexp, qty, price, discount; cout<<" Enter quantity: "; cin>>qty; cout<<" Enter price: "; cin>>price; totalexp=qty*price; if (totalexp>7000) { discount=(totalexp*0.1); totalexp=totalexp-discount; } cout<<" Total Expense is Rs. "<<totalexp; getch(); }

How to Create Project report(Vehicle Management System)

INTRODUCTION Vehicle Management System is software which is helpful for bus operators, who wants to operate many bus trips in a day. Vehicle Management System is a windows application written for 32-bit Windows operating systems which focused in the area of adding, editing and deleting the passengers, staff and the bus routes. In this software a person can be register as a user and he can manage the bus routes and the staff, passengers’ details.  He can add a bus and its details including bus route details. User can also add the details of the staff and their duty time in the system. There are mainly 5 modules in this software Bus Management Route Management Employee Management Passenger Management             In Bus module a user can add a new bus details to the database. He can set the details of the route and the timing also. Bus details like the type, engine number, seating capacity and ...

C++ Casino Game Project

Description: This C++ program on CASINO GAME is a simple text base game.We have used procedure oriented method to design this game. This program is without grahics to keep program easy for beginners . Player can deposit his money to play. From this amount he can bet on number between 1 to 12. If he win he gets 10 times of money otherwise lost his money. In this project, We have used programming concept like do..while loop, user defined function, library function like randomize(), random() etc. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<stdio.h> #include<time.h> void draw_line( int n, char ch); void rules(); void main() { int balanceamt,amt,no,dice; char playername[80],ch; clrscr(); draw_line(60,'='); cout<<" \n\n\n\n\t\tCASINO GAME\n\n\n\n "; draw_line(60,'='); cout<<" \n\n\nEnter Your Name : "; gets(playername); cout<<" \n\n\Enter Deposit amount to play game : ...