Varyanica
Varyanica

Reputation: 409

asp.net page life-cycle question

I have a Table and a Button. Table's cells have controls LiteralControl and CheckBox. I check some fields and then by click on button i remove these fields from database. On event Page_PreRender i clear Table and then fill it with updated data. Then it shows me Table with updated data. But if i check fields of table again and do a click on a button it wont do what i expected. In Page_Load event i see that it dont save properties of controls. Checked CheckBox controls appears as unchecked.

Upvotes: 0

Views: 265

Answers (3)

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

Dynamically adding controls is best executed in the OnInit event.

Upvotes: 0

BritishDeveloper
BritishDeveloper

Reputation: 13379

yeah tricky. really you want to have all the data bound before any event handling. i.e. bind your data OnInit or OnLoad (OnInit is better if you can to save viewstate).

Then handle the events i.e. delete rows or whatever you are doing and THEN get and rebind the new data in the eventhandler itself (after your deletion operation).

Upvotes: 1

chris
chris

Reputation: 37480

I assume that the button is posting back, you're doing your updates, and then you're trying to ensure that the new data is reloaded.

What you probably want to do is redirect to your page after the update - do a search for "GET AFTER POST" for more information.

Upvotes: 0

Related Questions