G
Greg
In my ASP.NET application I have a button that when pressed, data needs to
be saved based on what the user typed in. I have other controls on the same
page that should be updated as a result of the save, which are all
dynamically created in the code behind and have event handlers registered.
In the page life cycle, event handlers are called after the page is loaded.
The problem is, the save is done after the controls are loaded, so the
change is not reflected because it hasn't made it to the database yet (the
controls are loaded from the database or whatever). And I can't
programatically create the controls from my save because the page has
already loaded, and the event handlers won't be registered.
Example:
I select a customer from the list of controls. I change the customer name
from "Bob" to "Fred". When I hit save, the customers are loaded from the DB
*before* the save event is called, so "Bob" still displays even though it
was changed to "Fred".
One work around is to put a "response.redirect" to the page in the save
event, but this creates two postbacks which seems totally inefficient.
Logically, I need to move the save event to fire before the controls are
loaded, but I don't know if/how this is possible. Again, the save event
handler depends on a control on the page that is posting back.
Psuedo code:
Page_Load <-- gets fired before save
LoadCustomerNameControls
cmdSave += new CommandEventHandler(SaveCustomerName)
SaveCustomerName (object sender, CommandEventArgs e)
RunSql("update customername set name=" + SomeField.Text)
be saved based on what the user typed in. I have other controls on the same
page that should be updated as a result of the save, which are all
dynamically created in the code behind and have event handlers registered.
In the page life cycle, event handlers are called after the page is loaded.
The problem is, the save is done after the controls are loaded, so the
change is not reflected because it hasn't made it to the database yet (the
controls are loaded from the database or whatever). And I can't
programatically create the controls from my save because the page has
already loaded, and the event handlers won't be registered.
Example:
I select a customer from the list of controls. I change the customer name
from "Bob" to "Fred". When I hit save, the customers are loaded from the DB
*before* the save event is called, so "Bob" still displays even though it
was changed to "Fred".
One work around is to put a "response.redirect" to the page in the save
event, but this creates two postbacks which seems totally inefficient.
Logically, I need to move the save event to fire before the controls are
loaded, but I don't know if/how this is possible. Again, the save event
handler depends on a control on the page that is posting back.
Psuedo code:
Page_Load <-- gets fired before save
LoadCustomerNameControls
cmdSave += new CommandEventHandler(SaveCustomerName)
SaveCustomerName (object sender, CommandEventArgs e)
RunSql("update customername set name=" + SomeField.Text)