· WE CAN RETRIEVE THE VALUE AT THE SAME PAGE, WE CAN NOT RETREIVE THE
VALUE AT THE NEXT PAGE, WE CAN STORE ONLY STRING VALUE IN HIDDEN FIELD
· HERE VALUES ARE MAINTAINED FOR THE SAME PAGE
· HIDDEN FIELD IS AN CONTROL IN TOOLBOX WHICH IN INVISIBLE AT RUN TIME.
· THIS IS ALSO NOT A SECURE TECHNIQUE TO MANAGE THE STATE
using System;
using System.Configuration;
using System.Xml.Linq;
public partial
class _Default
: System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
int i;
protected void Button1_Click(object
sender, EventArgs e)
{
if
(HiddenField1.Value != "")
{
i = int.Parse(HiddenField1.Value);
}
i++;
HiddenField1.Value=i.ToString();
if(i==3)
{
Response.Redirect("Default2.aspx");
}
}
}
·
ASP.NET ALWAYS USED VIEW
STATE INTERNALLY TO MANAGE THE VALUE
OF CONTROLS( STATE OF CONTROLS )
·
VIEW STATE IS AN OBJECT WHICH KEEP
DICTIONARY ARCHITECTURE
·
VIEW STATE IS CONVERTED OF STREAM OF BITS AND STORED IT IN
HIDDEN FIELD THIS IS CALLED SERIALIZATION
·
·
SAVE STATE COMPLETE
SAVE THE CHANGES
HAPPENED BY THE CLIENT ON THE CONTROLS LIKE LABEL
·
IF A PROGRAMMER DONOT WANT TO MAINTAINED THE VIEW STATE
OF ANY CONTROLS
RIGHT CLICK ON
CONTROL PROPERTIES ENABLE
VIEW STATE =
FALSE
int i = 0;
protected void Button1_Click(object
sender, EventArgs e)
{
if
(Label1.Text == "")
{
Label1.Text = i.ToString();
}
else
{
i = int.Parse(Label1.Text);
i++;
Label1.Text = i.ToString();
}
}
BASE STRING 64 IS AN FORMAT TO ENCODE THE DATA
OF CONTROLS AND WE CAN ALSO RECONVERT IT
INTO STRING, SO IT IS NOT A SECURE TECHNIQUE.
· IF A PROGRAMMER DO NOT WANT TO
MANAGE THE VIEW STATE OF THE FULL PAGE WRITE THIS IN
SOURCE CODE THIS
<% PAGE ENABLEVIEWSTATE=” FALSE”
LANGUAGE=” C# AUTOEVENWIREUP=”TRUE” CODE FILE=”DEFAULT.ASPX.CS”
INHERITS=”DEFAULT” %>
· IF A PROGRAMMER DON’T WANT TO MANAGE THE VIEW STATE
FOR THE FULL APPLICATION SO DO THIS
OPEN WEBCONFIG WRITE
< SYSTEM.WEB>
<PAGES.ENBALEVIEWSTATE=”FALSE”>
</PAGES>
· IF A PROGRAMMER DO NOT WANT TO
MANAGE THE VIEW STATE FOR THE PAGES MORE THAN ONE WHICH
ARE STORED IN A FOLDER, SO DO THIS
RIGHT CLICK ON FOLDER ADD NEW ITEM ADD WEB CONFIGURATION FILE
WRITE THIS
<PAGE ENABLEVIEW
STATE =”FALSE”></PAGE>
· WEB APPLICATION NEVER CREATE
.EXE IT ALWAYS CREATE DLL,
· THEIR ARE FEW CONTROLS OF THEIR SINGLE VALUE IS MAINTAIND IN POST DATA
WHEN WE HAVE DONE THE VIEW STATE OFF IS NOT DEPENDENT THIS POST DATA IS APPLIED
AFTER LOAD STATE
· FOR THOSE CONTROLS TO WHOM
I.POST HANDLER INTERFACE IS IMPLEMENTED SO THE VALUE OF THESE CONTROLS ARE
MAINTAIND IN POST DATA LIKE TEXTBOX.TEXT
· ONLY TEXT IS MAINTAIN NOT
COLOR OF THAT TEXTBOX
@ VIEW STATE
IS APPLIED ON CONTROLS IN WHICH STATE OF THE LIFE CYCLE OF A PAGE
ANS.
AFTER THE INIT COMPLETE AND BEFORE PRELOAD STATE
· WE CAN STORE THE OBJECT TYPE OF DATA IN VIEW STATE
· VIEW STATE ALWAYS STORE THE SERIALIZED DATA
PRACTICAL OF VIEWSTATE
using System;
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.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
List<student> li;
protected void Button1_Click(object
sender, EventArgs e)
{
if
(ViewState["data"] == null)
{
li = new
List<student>();
}
if (ViewState["data"]
!= null)
{
li = (List<student>)ViewState["data"];
}
student
obj = new student();
obj.Sid = Convert.ToInt32(TextBox1.Text);
obj.Sname = TextBox2.Text;
obj.Sal = Convert.ToInt32(TextBox3.Text);
li.Add(obj);
Response.Write(li.Count);
ViewState["data"]
= li;
}
int x;
protected void Button2_Click(object
sender, EventArgs e)
{
if
(ViewState["count"] != null)
{
x = (int)ViewState["count"];
}
List<student> li = (List<student>)ViewState["data"];
student
s = li[x];
TextBox1.Text = s.Sid.ToString();
TextBox2.Text = s.Sname.ToString();
TextBox3.Text = s.Sal.ToString();
ViewState["count"]
= x;
}
protected void Button3_Click(object
sender, EventArgs e)
{
if
(ViewState["count"] != null)
{
x = (int)ViewState["count"];
}
List<student> li = (List<student>)ViewState["data"];
x++;
student
s = li[x];
TextBox1.Text = s.Sid.ToString();
TextBox2.Text = s.Sname.ToString();
TextBox3.Text = s.Sal.ToString();
ViewState["count"]
= x;
}
protected void Button4_Click(object
sender, EventArgs e)
{
if
(ViewState["count"] != null)
{
x = (int)ViewState["count"];
}
List<student> li = (List<student>)ViewState["data"];
student
s = li[x];
TextBox1.Text = s.Sid.ToString();
TextBox2.Text = s.Sname.ToString();
TextBox3.Text = s.Sal.ToString();
x--;
ViewState["count"]
= x;
}
protected void Button5_Click(object
sender, EventArgs e)
{
if
(ViewState["count"] != null)
{
x = (int)ViewState["count"];
}
List<student> li = (List<student>)ViewState["data"];
x = li.Count - 1;
student
s = li[x];
TextBox1.Text = s.Sid.ToString();
TextBox2.Text = s.Sname.ToString();
TextBox3.Text = s.Sal.ToString();
ViewState["count"]=null;
}
protected void Button6_Click(object
sender, EventArgs e)
{
}
}
No comments:
Post a Comment