ModalPopupExtender in a repeater RRS feed

  • Question

  • User-2113474059 posted

    I have a repeater within which each row contains a button to a modalpopupextender, I am using this to produce an "edit" window, so I would like to input text dynamically depending on which button is clicked into textboxes contained within the panel connected to the modalpopupextender.

     The problem I am having is that I can't find an appropriate place to do this, if i put it in the method for getting this data for the button click that is connected to the modalpopupextenders TargetControlID then the popup will appear before the data is loaded.

    If its not possible to use a ModalPopupExtender in this way or I am missing something obvious just randomly flame me :D


    Thursday, September 21, 2006 12:28 PM

All replies

  • User220125910 posted
    Hi Martin,

    David blogged about a way to do this in the newest version of the Toolkit.

    Friday, September 22, 2006 3:48 PM
  • User-1429816726 posted
    Tried the new DynamicPopulate support yet?
    Friday, September 22, 2006 3:48 PM
  • User-2113474059 posted

    Thanks very much for your replies, the dynamic populate method you suggested while very useful. As far as I can tell this method only allows you to set one control's text component per ModalPopUp. So for 3 dynamic textboxes/labels in your ModalPopUp this would be an impractical method. When using the dynamic populate and returning the string for a label in my modal pop up, I get "[object XMLDocument]" returned to the page. I thought this must be an error with my logic, so I tried using the code provided in the blog and this also gave me "[object XMLDocument]" where the time should have been.

     Any ideas why this is occuring?

    Ill just explain what I am trying to do with my Modal Popup abit more, I have a panel that contains 1 label and 2 textboxes, that I want to be dynamically populated when the ModalPopup is selected depending on which row in the Repeater is selected. The textboxes can then be edited and are updated to the database when the Ok button is pressed, and any changes are ignored when Cancel button is pressed.

    I thought the modalpopup would be a good way to do this, maybe there is a better way.

    Tuesday, September 26, 2006 6:01 AM
  • User220125910 posted
    Hi Martiin,

    I'm not sure about that error from the description you provided.  The other day I posted another example of using ModalPopup in databound controls that doesn't use the DynamicPopulate functionality.  It may be more useful to you.

    Tuesday, September 26, 2006 6:41 PM
  • User-916962509 posted

    After a few hours of Googling around, I found that the answer was hidden away in the description of the ModalPopup on the ASP.NET Ajax control toolkit page for the ModalPopup:

    The popup can be shown via server in code behind.

    The answer is therefore to do this. In the codebehind file, setup everything in the panel and THEN show the modal box. The way to do this is as follows:

    You need to create a "fake" button because the ModalPopupExtender requires a TargetControlID. So, create a button, make it invisible, and use this as the TargetControlID:


    <cc1:ModalPopupExtender ID="pop" runat="server" TargetControlID="btnFAKE" BackgroundCssClass="modalBackground" PopupControlID="pnlSupplierDetails" CancelControlID="btnClose"  />
    <!-- This will be the button I really use to show the popup, wired in code-behind -->
    <asp:Button ID="btnShowDetails" runat="server" Text="Details..." CommandName="ShowSupplierDetails" CommandArgument='<%#Eval("Supplier")%>' />
    <!-- This is the fake button, which is invisible -->
    <asp:Button ID="btnFAKE" runat="server" Text="Fake Button" style="display: none;" /> 


    In the ItemCommand of the repeater, do this:

    Protected Sub rptCosting_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptCosting.ItemCommand
            If e.CommandName = "DeleteRow" Then
                ' Do something, when handing one button press
            End If
            If e.CommandName = "ShowSupplierDetails" Then
               ' Write code here to set up the controls in the panel. You can use e.CommandArgument to get hold of the ID and do whatever you need as normal here.
               ' Using the code-behind, make the modal popup appear
               CType(e.Item.FindControl("pop"), AjaxControlToolkit.ModalPopupExtender).Show()
            End If
    End Sub


    Hope this helps,


    Friday, August 31, 2007 8:28 AM
  • User1850688405 posted

    Thank you Ben, Gave me new inspirations because I was puzzling some time to find a way to let it work..

    The only problem which will occur with your example is that the  RepeaterCommandEventArgs will only contain the controls in the ItemTemplate of the repeater.

    My solution to this was to put everything outside the repeater and in the ItemCommand event method put the following code :

    foreach (Control rootControl in Controls)


    if (rootControl.ID == "pop")


    ModalPopupExtender pop = (AjaxControlToolkit.ModalPopupExtender)rootControl;




    maybe your code works as well, but gave very strange effects in the project I am working on...




    Wednesday, November 28, 2007 7:56 AM
  • User-916962509 posted


    I have a ModalPopupExtender within the item template of the repeater, so it worked OK. What scope was your ModalPopupExtender, and what odd effects were you seeing? I am curios as to what went wrong.

    I have employed my solution (above) numerous times now, each time it works perfectly.

    You may also like to try Controls.FindControl("pop") instead of iterating around the control collection as you are doing.



    Thursday, December 6, 2007 9:20 AM
  • User1850688405 posted


    My experience was that the popup would be shown as many times as there are records in the dataset which is bound to the repeater's datasource. The background would get 'darker' with each record the repeater contains.

    Controls.FindControl("pop") is indeed a nicer way of syntax, and I have changed that thank you.





    Monday, December 10, 2007 7:33 AM
  • User-916962509 posted

    Ah - Yes.

    If you have multiple ModalPopups that you are using (so for each RepeaterItem, you have three buttons which you wish to each spawn its own ModalPopUp) then this will happen if each ModalPopupExtender is pointing to the same btnFAKE as the TargetControlID.

    The solution is to have three buttons: btnFAKE1, btnFAKE2, btnFAKE3 and wire each ModalPopupExtender to a different button.

    The "darker" phenomenon you were experiencing is because of the transparancy filters applied in CSS - each time it darkened the screen relative to how it appeared.

    Let me know if this helps,


    Tuesday, December 11, 2007 5:09 AM
  • User1850688405 posted

    Hi Ben,

    Then I don't understand why you would define the panel in the repeaters ContentItems, when fake buttons have to be generated?

    Isn't it just easier to define the panel, modal popup and fake button outside of the repeaters 'body'?

    All works fine allready, thanks to your information ;)

     Greetings, Mathijs

     ps. Controls.FindControl(string) doesn't exist in my environment (?)... Reversed the code back to the iterating mechanism



    Tuesday, December 11, 2007 5:34 AM