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
Explain cashing in asp.net.
What is localhost in asp.net?
What is simple data binding?
What are the event handlers that we can have in global.asax file?
Difference between DataGid and Girdview? Difference b/w .Net 2.0, 3.0 and 3.5 ? Diff b/w dispose & Finialize Methods?
Suppose you want an asp.net function (client side) executed on the mouseover event of a button. Where do you add an event handler?
Explain swagger components.
How do you secure your connection string information?
What is difference between inproc and outproc?
What’s the difference between asp.net web forms and asp.net mvc?
How to set the pane area to transparent of a scrollPane component.?
What is a session http?
Describe the Server Control Events of ASP.NET?
How about the security in Activex DLL and Activex EXE ?
Where the cookie value is stored?