From the above code one can see I have a
ScriptManager, an asp:Button control, an asp:Panel control, some
contents inside the panel control and then we have the
ModalPopupExtender control. Normally when you attach an ASP.NET panel
control to a ModalPopupExtender control it will become invisible in the
HTML rendered to the browser and if due to some reason if the panel
control is being displayed in the page then just set the "Style"
property' “display” attribute to “none” as in the above e.g. Now when
you click the button you will see a popup as shown below.
| http://lh6.ggpht.com/_QY7fSC4VqiA/Sk3Hv8q91bI/AAAAAAAAC5E/jRVw6idcvn0/s1600-h/image4.png |
Now
lets see how to configure the ModalPopupExtender control. The
configuration is pretty simple, you need to set some properties and and
you will have your Modal popup. The properties are as follows
TargetControlID:
This property is the one which tells, on click of which control the
popup should be displayed. In our e.g. we have given the TargetControlID
as our button control. You can assign the ID of any ASP.NET controls
like LinkButton, ImageButton, HyperLink, DropDownList, CheckBox,
RadioButton etc. Even you can give a label’ id as the TargetControlID.
PopupControlID: The
ID of the control to be displayed as a modal popup. In our e.g. we have
given ASP.NET panel control’ ID. You can give any ASP.NET control’ ID.
If for e.g if you give the ID of a textbox then the textbox alone will
be popped up. Its not compulsory that you should provide a ASP.NET panel
control.
OkControlID: The ID of the control which should act as an Ok button. Clicking of this control will dismiss the popup.
BackgroundCssClass: The
name of the CSS class which needs to be applied to the background of
the popup. One thing to note here is that if you don’t provide a CSS
class then the modal popup will not function like a modal dialog i.e.
One will be able to interact with the controls in the back of the popup
control, so its imperative to provide a valid CSS class name value to
the BackgroundCssClass property. In the above e.g. we have defined a CSS
class called “backgroundColor” in the header section of the aspx page.
Please note in the CSS class definition we have applied “filter”
property to make the background transparent.
DropShadow: Accepts
a boolean value which specifies whether the popup should have shadow.
True will give a shadow and false will disable the shadow.
PopupDragHandleControlID: The
ID of the control clicking on which the ModalPopupExtender can be
dragged. The control should be enclosed in the control specified using
PopupControlID i.e. in our case inside the ASP.NET panel control. If a
particular control ID is set as the PopupDragHandlerControlID then one
can click on that control and drag the ModalPopupExtender control. In
the above e.g. we have set the ID of the “h3” control as
PopupDragHandleControlID, clicking which the popup can be dragged.
CancelControlID: If you want a button to behave as a Cancel button provide the ID of the button. This button will cancel the popup.
Drag: This
property takes a boolean value which when set decides whether the popup
control can have the drag feature. A value of true means the popup
extender control can be dragged around the screen whereas false will
disable the drag.
RepositionMode: This
property accepts four values. They are “None”,
“RepositionOnWindowResize”, “RepositionOnWindowResizeAndScroll” and
“RepositionOnWindowScroll”. The default value is
“RepositionOnWindowResizeAndScroll”. Explanation of each values is given
below.
RepositionOnWindowResize: Will reposition the popup when the window is resized.
RepositionOnWindowScroll: Will reposition the popup when the scroll bar is moved.
RepositionOnWindowResizeAndScroll:
Will reposition the popup when you resize or when you move the scroll
bar. Its a combination of both “RepositionOnWindowResize” and
“RepositionOnWindowScroll”.
None: The popup will
not be tinkered with. It will be shown in its original position
irrespective of window resizing or scroll bar being moved.
DynamicServicePath: Link to a webservice/aspx page from where data or content needs to be retrieved and displayed in the popup extender control.
DynamicServiceMethod: The
method name from which content needs to be retrieved. The method can be
a webservice method or a method in your code behind file of your aspx
file. If you leave the “DynamicServicePath” empty and provide
DynamicServiceMethod name then the system will try to ping the same
page’ and try to find a method. We will see an e.g. with web service
shortly.
DynamicContextKey: The
string value which will be passed as the parameter to the method
specified in DynamicServiceMethod. One thing to note here is that the
parameter should be named contextKey in the webservice/code behind.
X: The X coordinates for the popup control.
Y: The Y coordinates for the popup control.
http://www.eggheadcafe.com/forumpostsubmission.aspx?topicid=2&forumpostid=10341423