Viewstate problem?

G

Guest

Yes, the myVar fields is store anywhere, and so it's lost between two
postbacks.

You must save it in the viewstate as following :

protected int MyVar
{
get
{
object o = ViewState["MyVar"];
if ( o != null )
return (string) o;
return "Default Value";
}
set
{
ViewState["MyVar] = value;
}
}
 
M

Mike

Hi

I have the following code and why can't i change the value of myvar in the
DataGrid1_editcommand event so that the (changed) value of myvar is there in
the Update event?? (it fires i debugged it!):

namespace MYproject

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;



public class MyUsercontrol: System.Web.UI.UserControl

{

public string myvar ="hello";



private void Page_Load(object sender, System.EventArgs e)

{


}


public void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{


myvar ="goodbye"; //enters this code first


}



private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

string temp; // enters this code next!!!

temp = myvar; // myvar = "hello" ???? instead of the wanted "goodbye"


}

}

}

how can i program this so i can keep my changes in this variable?

ch Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top