Wednesday, October 31, 2007

What is caching

Caching is a way to improve the performance of your website. Caching is the technique of storing an in-memory copy of some information that’s expensive to create. You can store the list of query or a output html form.

The following are the techniques of caching

1. Output caching
2. Data caching

1. Output caching - This is the simplest type of caching. It stores a copy of the final HTML page that is sent to the client. When next client submits a request for same page doesn’t actually run the page. Instead, the final HTML output is sent automatically. The time that would have been required to run the page and its code is completely reclaimed.

If you want to use output caching just add the following line of code at top of your directive in your aspx page

Replace ><> after copy paste in your application

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

the duration attribute tells the asp.net to cache this page for 20 seconds

2. Data Caching
- It is done manually in your code. To use data caching, you store important pieces of information that are time-consuming (such as a DataSet retrieved from a database) in the cache. Other pages can check for the existence of this information and use it. Data caching
is conceptually the same as using application state, but it’s much more server-friendly because items will be removed from the cache automatically when it grows too large and performance could be affected. Items can also be set to expire automatically.

Tuesday, October 30, 2007

What is cross page posting in asp.net 2.0

cross page posting is a good feature in asp.net 2.0

Cross-page posting enables you to submit a form (suppose, Page1.aspx) and have this
form and all the control values post themselves to another page (suppose, Page2.aspx). now you can get values of all controls on one web form from other web form

How to do this practically

Add a new website in visual studio 2005 and add two web form (suppose page1.aspx and page2.aspx)

Page1.aspx

Add two controls in this page from tool box, one textbox and one button

/asp:Button ID=”Button1” Runat=”server” Text=”Submit page to Page2.aspx”
PostBackUrl=”Page2.aspx”/

Page2.aspx

Add a label in page 2

protected void Page_Load(object sender, System.EventArgs e)
{
TextBox pp_Textbox1;
pp_Textbox1 = (TextBox)PreviousPage.FindControl(“Textbox1”);
Label1.Text = “Hello “ + pp_Textbox1.Text;
}

Monday, October 8, 2007

How to create a login form

Here we will discuss how to create a login form in Asp.net 2.0 using C#
Sql Server 2000

create a database table in sql server with following fields

user_name varchar(50) Not Null
password varchar(50) Not Null

and add one or two values in table thru Enterprise Manager

Or you can use query analyzer to create tables

Add the following code in login.aspx.cs file

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class Admin_Login : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = WebConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
con.Open();
}
// check authorization for registered admin
protected void Button1_Click(object sender, EventArgs e)
{
string a = uname.Text;
Session["ds"] = a; //here we have created session for admin
if (uname.Text == "")
{
Label1.Text = "User Name Cannot be null";
Label1.Visible = true;
}
if (password.Text == "")
{
Label1.Text = "Password Cannot be null";
Label1.Visible = true;
}
string u =Convert.ToString (uname.Text);
string p =Convert.ToString( password.Text);
//Response.Write(u);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select user_name, password from Pefa_Admin ";
SqlDataReader dr = cmd.ExecuteReader();
////cmd.ExecuteReader = dr;
while (dr.Read())
{
string username =Convert.ToString( dr[0]);
string pass =Convert.ToString( dr[1]);
if (u == username && p == pass)
{
Response.Redirect("Wait.aspx");
}
else
{
Response.Write("Not Authprised");
}
}
}
}


And add a web.config file to create a connection