| re: dynamically adding controls, saving, viewing change on page??
Ok, I fugred this out...
First of all, it *is* possible to load controls and event handlers after you
fire an event (sorry, I misspoke earlier, it's been a long day). Due to
some other complexities of the UI I was working with, I basically had to add
some better checking on when to load up the controls. I ended up needing to
determine which control was causing the postback, firing off the save event,
and then loading the other controls programatically as normal. Example:
if (Request.Form["__EVENTTARGET"] != "lbSave")
{
LoadCustomers();
}
"Greg" <na> wrote in message news:OANRK1wIEHA.2544@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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[/color]
same[color=blue]
> 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[/color]
loaded.[color=blue]
> 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[/color]
DB[color=blue]
> *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)
>
>
>
>[/color] |