I have a ListView on a page that displays a list of widgets. When a user clicks on one of the items in the list, I want to display a ModalPopup that contains controls allowing the user to operate on the item they selected.
I could easily accomplish this by placing a Panel and a ModalPopupExtender in the ListView's ItemTemplate, but this mean one set of hidden controls for each and every widget, which would massively bloat the page size. (There are going to be some rather heavyweight controls in there.) Instead I want to reuse a single ModalPopup for each of the widgets in the list.
I've done some searching but I haven't found anything that applies directly to my situation before. From what I've been able to figure out, however, I have to do something like this:
- Place a Panel and a ModalPopupExtender on the page inside an UpdatePanel.
- Build a custom
WidgetManipulator
user control that has aWidgetID
property. Put this in the Panel, along with a couple OK/Cancel buttons. - In Javascript on the page, attach a click handler to each widget in the ListView that triggers a postback on the UpdatePanel.
- On the
UpdatePanel_Load
event on the server, display the ModalPopup and then set theWidgetID
propety on theWidgetManipulator
to the ID of the clicked widget. - On the
OKButton_Click
event orCancelButton_Click
event on the server, hide the ModalPopup. If OKButton was clicked, callWidgetManipulator.SaveChanges()
first.
The part I haven't figured out is: How the heck do I know what widget was clicked on, and how do I pass that back to the server when I refresh the UpdatePanel? Is this even the right approach at all?