Hi.
Calling a public method of a UserControl that takes care of changing some
property of some control (label or something) is ok, but ugly and not
manageable. The normal and most elegant approach would be to use events. For
instance:
your page gets loaded;
grid (or other control on the page itself) gets bound to some data sourse;
UserControl gets loaded, too;
initially that label (or whatever) of UserControl gets its Text property set
to something;
user clicks Delete link or button on your grid;
DeleteCommand event (or whatever you have attached to this action) gets
fired;
you do your magic to get rid of that record and re-bind the grid;
in the same event handler (DeleteCommand of the grid) you fire your own
event that you declared inside of the page's class or outside;
you can declare your event parameters class inherited from EventArgs class
which will be "used" by your event and instantiate it with your own
properties when you fire your custom event;
your UserControl will subscribe to that page's event and will "listen" to it
(look inside of InitializeComponent() method that VS created in your page's
class - that's how it's done);
if it "hears" event, it gets the total records from your custom
EventArgs-based class or (ugly way) goes to db again and finds out that
total number again.
Sounds awfully complicated but in a real life it's just several lines of
code. That way your page lives completely separate life as well as your
UserControl; they don't care about each other unless that event gets fired.
That's how it should be done.
You can start reading more about events and how to work with them here:
http://www.codeproject.com/csharp/eventdelegates.asp or check MSDN and
framework documentation. It's a great stuff, soon you'll be wandering how
you've managed to live without them :)
Regards,
Kikoz
"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I drop on
every page in my application. The application is an eCommerce application
and I have a total for items in the cart on the header. To keep this total
in sync, I count the items in the cart and refresh the label text in the
load event of my header control. This all works well, except for one
scenario. When the user is on the "Show Cart" page, they can delete items
from the cart. I implemented this using the DeleteCommand of a datagrid.
When this is done, the total does not reflect the item being deleted until
I manually refresh the page.
So I'd like to be able to refresh the header control or even the whole
page if an item is deleted. How can I do that? Thanks!
Matt