Need Help with Page Life Cycle(I think it is screwing me up)

Posted by chobo2 on Stack Overflow See other posts from Stack Overflow or by chobo2
Published on 2010-03-22T21:27:57Z Indexed on 2010/03/22 21:31 UTC
Read the original article Hit count: 238

Filed under:
|
|

Hi

I have dragged a empty asp.net table onto my webform. I generate all the rows in the code behind those.

Now my table gets filled up and has dropdown lists. When the user hits save I go through all the rows and update the values from the dropdownlist in the db.

This works all great. However if 2 columns have each have "Present" then those 2 columns should be not be shown anymore and 2 new columns get put in its place with other dropdown lists.

This all works. However you have to refresh the entire page to for the 2 columns that should go away to go away.

So what I tried to do is at the end of the button click event. Clear the whole table and then regenerate it. However when I do this then my values are not saved to the database anymore for whatever reason.

if (IsPostBack == false)
{
    // check if dummy variables exist in db- If true just generate tables with values in db. If not generate them. 

}
else
{
   // grab the values from the database
   // generate tables with the values
}

btn click event
{
   go through all rows in table(foreach loop)
   update each column in the database with cells in each row. while in foreach loop.
   //done
}

So this is how it goes and it works expect(all correct values are saved) the table is just not updated to the user.

Does not work

    if (IsPostBack == false)
    {
        // same code as above
    }

   // if postback is true do nothing. By the time it gets to the click event it says there is zero rows in the table so nothing happens.
    btn click event
    {
       // same code
    }

Fails also.

if (IsPostBack == false)
{
   // same code as above
}
else
{
   // same code as above but moved into its own method.
   gernerateTable();
}

btn click event
{
   // update all rows
   // once done clear the Tables rows
   // call generateTable()
}

This last one does nothing as for some reason it does not update anything. I don't understand why.

So what am I doing wrong with this life cycle something in my process is wrong. The code works just not when I want the table to be updated right away.

© Stack Overflow or respective owner

Related posts about page-lifecycle

Related posts about ASP.NET