2.0: unexpected modification of a field

  • Thread starter Thread starter R.A.M.
  • Start date Start date
R

R.A.M.

Hi,
I wrote a class with a variable which value is modified although
there's no responsible statement, as I see.
Below the code - the class is a user control.

public partial class BooksiDataList : System.Web.UI.UserControl
{
private string ChangedISBN;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
ChangedISBN = null;
}

protected void BooksList_Edit(object sender, DataListCommandEventArgs
e)
{
ChangedISBN = ((Label)e.Item.FindControl("BooksListISBN")).Text;
// here ChangedISBN != null
}

protected void BooksList_Update(object sender,
DataListCommandEventArgs e)
{
if (ChangedISBN != null) // HERE PROBLEM: ChangedISBN == null
...
ChangedISBN = null;
}

}

BooksList_Update is called always after BooksList_Edit - which sets
'ChangedISBN' to non-empty string. But in BooksList_Update ChangedISBN
is always null.
Could you explain me this phenomena?
Thank you very much
/RAM/
 
Hi,


How can you assure than _Edit is called ALways before _Update ?

Also remember that EACH TIME the page is executed ( by user request, or by
handling an event) the variable is recreated and its value return to null.

Put a breakpoint everywhere the var is used and debug your code.
 

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

Back
Top