Need help with asp.net viewstate
Hi all,
Pls somebody help me with viewsate. Suppose i have created two forms. First form contains First name and Last name and one button called NEXT. And Second form contain two fields and two button like Back and Save. While i am entering some value in form1 pressing one NEXT button and redirecting to second page. There when i am pressing Back button from second page it should come to first page whichever data i filled should exists, but in my case its not showing only empty form i can see when i am pressing on back button.
For this i have used viewstate mechanism. in page directory i have set enableviewstate=true.
postbackurl in both the button. Pls somebody help me what is wrong with me.
Thanks,
Sumit
Amit ChoudharyPosted Nov 6, 2009, 12:10 AM
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
try this in you page directive attribute....
========================================
mark as answer if it helps :)
Jorge L FernandezPosted Nov 5, 2009, 2:37 PM
Your problem happens because when you go back to your first page a new instance of the page is created and therefore you have to set up the values by yourself... if you previeusly stored then. Here you may have a clean solution using the MultiView control. Is simple and organized.
check this sample:
and the code behind where you control the navigation of the views. Here you will have you expected behavier of the ViewState.
protected void Page_Load(object sender, EventArgs e)
{
this.MultiView1.ActiveViewIndex = 0;
}
protected void Button1_Click1(object sender, EventArgs e)
{
this.Label1.Text = "You typed : " + this.TextBox1.Text;
this.MultiView1.ActiveViewIndex = 1;
}
protected void Button2_Click(object sender, EventArgs e)
{
this.MultiView1.ActiveViewIndex = 0;
}
If you try this you will get exactly what you need. Then you can customize each view as you want. Review the documentation for more details of MultiView control. But this solve your intered in a very clean way.
If this answer solve your question please Mark is as answered. Thanks and keep in touch.