Some time ago I had a project in hand which needed so many popup windows here and there to enter and edit data, but I had to perform a postback in asp.net to register startup script for popup also I couldn't detect popup window close so had to use hovering divs or make user to refresh the window in order to see the changes s/he made.
This control will address these needs and I find it very simple to use.
Understanding the code
Also every time a property changes SetProps() method will be called to ensure the changes being displayed.
This control has an event PopupClose which triggers when user closes popup window.
- Displaying the popup window. I tried to include ways of displaying modal and modeless popups compatible with IE, Opera and FireFox.
IE supports window.showModalDialog() method which will be called in case browser supports it and this will be detected by this line of code
otherwise window.open() method will be called. Each method has it's own way of passing parameters and options so the option string will be prepared accordingly.
- Detecting popup close, causing a postback and triggering the event on server side.
SetCloseHandler() method will create a timer which checks the popup window on 100 ms intervals and when detects it's closure fires __doPostBack()
Using the code
It's quite easy to use the control:
- Copy "PopupCommand" folder into your project (preferably into a new assembly project named "Popup" otherwise change "Popup" namespace in PopupCommand.cs to your desired namespace [lines 12,13,14,53])
- Set BuildAction of "PopupHandler.js" to "Embedded Resource"and build the project
- Drag newly added item named PopupCommand from the toolbox wherever you need the popup control
- Set the parameters of control regarding to your need
You can also double click on inserted control and handle PopupClose
- Text: Text to be displayed
- EntityName: Name of entity being displayed in the popup (optional)
- EntityID: Unique identifier of entity being displayed in the popup (optional)
it will also replace @ID in url if present, this way dynamically generated url's can include ID of the entity
- Url: Url of the page being displayed in the popup window
- PopupWidth: Width of popup window
- PopupHeight: Height of popup window
- ImageUrl: Url of the image to be displayed next to control's text
- CommandName: The command name which will be passed to server side event handler of PopupClose event
- CommandArgument: The command argument which will be passed to server side event handler of PopupClose event
- PopupClose: Will be triggered when user closes popup window and will return command name and argument specified in properties