State Management

 STATE MANAGEMENT is the process of transferring data from one page to another.

When the website go for roundtrip then the data entered in any TextBox will be lost. Then we use this for data to be stored either in client side or in the memory of server.

1.Session- It is used to transfer data reliably or transferring the sensitive data from one page to another. Default time limit for Session is 60 sec.

i.   Session is always created inside an event. 

ii.  Session data can't be shown in URL.

iii. Session is called in the Page_Load event of the next page.  

Syntax- 

Session["variable_name"] = TextBox1.Text; 

Response.Redirect("Page_name.aspx");

This code should be written inside any event of the page from where data is to be transferred to next page. 

TextBox1.Text(Control) = Whose data is to be transferred

["variable_name"] = Any variable can be given within inverted quotes. 

Next Page-

|>Session is called in the Page_load event of next page.

Control_name.Text = (string) Session["variable_name"];

(string)- for typecasting. 

Control_name.Text - the control you want to show the transferred data. 

["Variable"]- same variable as it was given in the page in which Session is defined.


2.QueryString- It is used to fast data transfer . the data will be shown in URL, No Server resources are required..

|>It is not appropriate for security purposes.

|>Limited Capacity (2083 characters length of URL).

Syntax-  

Response.Redirect ("Page_name.aspx?variable1_name=" + Control1_name + "&variable2_name=" + Control2_name + "&variable3_name=" + Control3_name );

//Less lines of code. 

? - Query String operator 

+ - cascading operator 

Next Page- 

In Page_load event-

Control_name = Request.QuertString["Variable_name"];



Comments

Popular posts from this blog

Parameter Query

Final Project

Grid View Paging