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

Define msil.

538


Explain the difference between response.redirect vs server.transfer

618


How can we inherit a static member?

588


How to do parallel database export in remote SQL Server in ESSL time track. It is working for local server but not working for remote SQL Server

5677


What is the difference between login controls and forms authentication?

539






Just by seeing the signature of the bean how can you specify whether it is a stateful or stateless session bean?

546


Can you explain composite pattern?

584


Explain parts of assembly?

549


What is the most appropriate lifetime for a database connection/orm context in an asp.net mvc application? : Asp.Net MVC

530


Where do the cookie state and session state information be stored?

506


What is the use of execute non query in asp.net?

481


Describe the method to create a permanent cookie?

577


Explain Optimization technique description?

596


How can you pass multiple complex types in Web API?

564


How information about the user's locale can be accessed?

581