can we transfer data from one page to another page using
viewstate if so how?if not y?

Answer Posted / vipin agrawal

yes we can do it by cross page posting (cross page
viewstate)

here is the code:

Source page code:
----------------
public partial class ViewStateContainer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ViewState["Page1"] = "Page1 ViewState";
Server.Transfer("AccessViewState.aspx");
}

/*StateBag class: This class is the primary storage
mechanism for all HTML and Web server controls.
It stores attribute/value pairs as strings associated
with the control. It tracks changes to these
attributes only after the OnInit method is executed for
a page request, and saves the changes
to the page's or control's viewstate.*/
public StateBag ReturnViewState()
{
return ViewState;
}

}

Target page code:
----------------

public partial class AccessViewState : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
if (PreviousPageViewState != null)
{
Label1.Text = PreviousPageViewState
["Page1"].ToString();
}
}
Response.Write(((Label)PreviousPage.FindControl
("Label1")).Text);

}

private StateBag PreviousPageViewState
{
get
{
StateBag returnValue = null;
if (PreviousPage != null)
{
Object objPreviousPage = (Object)
PreviousPage;
MethodInfo objMethod =
objPreviousPage.GetType().GetMethod
("ReturnViewState");
return (StateBag)objMethod.Invoke
(objPreviousPage, null);
}
return returnValue;
}
}

}

Is This Answer Correct ?    11 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is enableviewstatemac in asp net?

599


Explain parts of assembly?

557


What is the difference between stored procedure vs function?

581


What is the sequence in which ASP.NET events are processed?

478


what is the difference between response.write() and response.output.write()?

702






Is react a template engine?

525


Explain the code Access Security (CAS) in .net Framework?

694


What do you mean by View State and what is its role?

540


What is a web api?

555


What will happen if the server confugration file and the application confugration file have different values for sassion state ASP.NET?

754


Explain the difference between panel and groupbox classes using .net?

490


Where can I get the details on migration of existing projects using various technologies to asp.net?

522


Where web.config file is used?

576


What are the ways of preserving data on a Web Form in ASP.NET?

624


Define the types of configuration files.

536