Search code examples
asp.netdynamicmodalpopupextender

In server side, how to determine ModalPopupExtender is currently hidden?


I have a page like that and the control structure is like that.

  • UpdatePanel
    • Button
    • ModalPopupExtender
    • ModalPopup Content Container

Initially, ModalPopup Content Container is an empty control.

After user clicks on the Button, a async postback will be triggered. During the postback, the server generates the content and appends to ModalPopup Content Container. Also sets the properties of ModalPopupExtender. Finally, calls ModalPopupExtender.Show() method and UpdatePanel.Update() method to show the modal popup.

This method works fine if all controls in ModalPopup Content Container contains simple control. If a control is a button that needs to postback to server side, that is a problem.

Since the controls in ModalPopup Content Container is dynamically created. If a control in ModalPopup Content Container triggers a postback event, the control must be created before RaisePostBackEvent is called in server side.

My idea is to determine whether the ModalPopupExtender is hidden or shown in client side in order to re-generate the dynamic control in ModalPopup Content Container.

So my question is how to determine a ModalPopupExtender is hidden or shown.

Of coz, if you think my method does not work at all, please give me some suggestions. Thanks!


Solution

  • One way is using a boolean property in ViewState to keep track of the popup condition i.e. before or after you call .Show method set it to true. Then upon closing dialog you set it to false.

    You can use HiddenField as well if you want to do something on client-side.