I
Iain
I've built a control whose purpose is to render a shopping cart based on
templates and an Order object which gets passed to it.
I'm keeping the order object in the Session object and therefore have no
need to use ViewState for this control. Instead I create the ChildControls
based on what is in the Order (passed in during initialisation) and
databinding with the various templates in the page.
This seems to work fine (though there has been a certain amount of
frustration in the learning curve!).
What I want to do now is to add buttons into the templates which will cause
(say) an order line to be deleted. I want to take care of this in the
rendering control - I see no need to pass this up to the page it sits in.
So I've added the buttons into the template and caught the bubble as it
comes up. Then I make the changes (E.g. delete a line item) on the order
object.
This seemed to work the NEXT time I did something.
It turns out the issue (sorry about dribbling on here, but it is quite
complex!) is when things are made.
The CreateChildControls is called BEFORE the event handling / bubbling
happens. So in this instance I create my UI with the original order and
then modify the order to remove a line item. Of course the UI (in terms of
the control hierarchy) is already there so the removal has no effect until
the NEXT event.
I tried moving the creation of the control hierarchy (into render), but then
there were no controls to raise the event against.
Finally, I did both. I created the control hiearchy in CreateChildControls
and then deleted it and recreated it in Render.
This seems to work, but I can't help thinking, a) it's a horrid way to do
this and b) surely something will go wrong.
Can anyone suggest a better way of doing this (parsing the control tree to
remove the specific elements that are implicitly deleted is not really an
option. I don't think ... hmmm.)?
Or confirm that this is safe?
Thanks
Iain
templates and an Order object which gets passed to it.
I'm keeping the order object in the Session object and therefore have no
need to use ViewState for this control. Instead I create the ChildControls
based on what is in the Order (passed in during initialisation) and
databinding with the various templates in the page.
This seems to work fine (though there has been a certain amount of
frustration in the learning curve!).
What I want to do now is to add buttons into the templates which will cause
(say) an order line to be deleted. I want to take care of this in the
rendering control - I see no need to pass this up to the page it sits in.
So I've added the buttons into the template and caught the bubble as it
comes up. Then I make the changes (E.g. delete a line item) on the order
object.
This seemed to work the NEXT time I did something.
It turns out the issue (sorry about dribbling on here, but it is quite
complex!) is when things are made.
The CreateChildControls is called BEFORE the event handling / bubbling
happens. So in this instance I create my UI with the original order and
then modify the order to remove a line item. Of course the UI (in terms of
the control hierarchy) is already there so the removal has no effect until
the NEXT event.
I tried moving the creation of the control hierarchy (into render), but then
there were no controls to raise the event against.
Finally, I did both. I created the control hiearchy in CreateChildControls
and then deleted it and recreated it in Render.
This seems to work, but I can't help thinking, a) it's a horrid way to do
this and b) surely something will go wrong.
Can anyone suggest a better way of doing this (parsing the control tree to
remove the specific elements that are implicitly deleted is not really an
option. I don't think ... hmmm.)?
Or confirm that this is safe?
Thanks
Iain