usercontrol and modalPopupExtender

Discussion in 'ASP .Net' started by =?Utf-8?B?S3lsZSBNLiBCdXJucw==?=, Aug 14, 2007.

  1. I have a set of controls and logic that must be invoked from several pages
    within a web application as a popup dialog, so I intend to use a userControl
    contained in a panel extended with the modalPopupExtender to get this
    behavior. I want to deal with showing and hiding the popup in server-side
    code, so I've set the TargetControlID to a hidden (style=display:none;)
    button and not set the OkButton or CancelButton. The userControl has several
    events designed to signal the disposition of the user's interaction with the
    control. The problem that I am having is that whenever an action is taken on
    the control that causes an interaction with the server side code, the popup
    is closed and my events are never fired in the containing page. Has anyone
    successfully used the modalPopupExtender in this manner?
    =?Utf-8?B?S3lsZSBNLiBCdXJucw==?=, Aug 14, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?S3lsZSBNLiBCdXJucw==?=

    JB Guest

    Just had the same issue as you Kyle. I had a user control that creates
    new customer accounts. On my asp.net page I had a ModalPopupExtender
    with a link button "Add Account". Clicking Add Account launches the
    modal popup to the screen so the user can create a new account.

    Problems I encountered were:
    1. How to close of the modal popup when user clicked the cancel button
    (The cancel button is part of the CreateAccount usercontrol)
    2. How to close of the modal popup when the user clicked the OK
    button. (The OK button is also part of the CreateAccount usercontrol).

    Note: I added an update panel inside the panel control (that hosts my
    usercontrol) in my asp.net page. This was to have ajax (partial)
    postbacks when the user interacted with the modal dialog.

    I added two public events to my usercontrol ItemCreated and
    ItemCancelled. These events were raised when the cancel and OK buttons
    get clicked. I then handle these events in the asp.net page and call
    the Hide() method on the ModalPopupExtender to close the modal popup.


    // Events in my CreateAccount user control

    public event EventHandler ItemCreated;
    public event EventHandler ItemCancelled;

    protected void btnCancel_Click(object sender, EventArgs e)
    {
    lblStatus.Text = "Cancelling...";

    if (ItemCancelled != null)
    {
    this.ItemCancelled(this, new EventArgs());
    }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    lblStatus.Text = "Creating...";

    if (ItemCreated != null)
    {
    this.ItemCreated(this, new EventArgs());
    }
    }

    // MyAspxPage.aspx

    <asp:LinkButton ID="LinkButton1" runat="server" Text="add account"></
    asp:LinkButton>

    <asp:panel ID="Panel1" runat="server">
    <asp:UpdatePanel ID="pnlUpdate" runat="server">
    <ContentTemplate>
    <uc1:CreateAccount ID="CreateAccount "
    runat="server" />
    </ContentTemplate>
    </asp:UpdatePanel>
    </asp:panel>

    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"
    runat="server"
    PopupDragHandleControlID="Panel1"
    TargetControlID="LinkButton1"
    PopupControlID="Panel1"
    BackgroundCssClass="modalBackground"
    DropShadow="false" />

    // MyAspxPage.cs

    protected void Page_Load(object sender, EventArgs e)
    {
    this.CreateAccount1.ItemCancelled += new
    EventHandler(CreateAccount1_ItemCancelled);
    this.CreateAccount1.ItemCreated += new
    EventHandler(CreateAccount1_ItemCreated);

    }

    void CreateAccount1_ItemCreated(object sender, EventArgs e)
    {
    this.ModalPopupExtender1.Hide();
    }

    void CreateAccount1_ItemCancelled(object sender, EventArgs e)
    {
    this.ModalPopupExtender1.Hide();
    }


    Cheers,
    John

    Kyle M. Burns wrote:
    > I have a set of controls and logic that must be invoked from several pages
    > within a web application as a popup dialog, so I intend to use a userControl
    > contained in a panel extended with the modalPopupExtender to get this
    > behavior. I want to deal with showing and hiding the popup in server-side
    > code, so I've set the TargetControlID to a hidden (style=display:none;)
    > button and not set the OkButton or CancelButton. The userControl has several
    > events designed to signal the disposition of the user's interaction with the
    > control. The problem that I am having is that whenever an action is taken on
    > the control that causes an interaction with the server side code, the popup
    > is closed and my events are never fired in the containing page. Has anyone
    > successfully used the modalPopupExtender in this manner?
    JB, Sep 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SGFyZHkgV2FuZw==?=

    ModalPopupExtender and DOCTYPE problem

    =?Utf-8?B?SGFyZHkgV2FuZw==?=, Apr 23, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    2,716
    =?Utf-8?B?SGFyZHkgV2FuZw==?=
    Apr 23, 2007
  2. ujjc001
    Replies:
    0
    Views:
    671
    ujjc001
    Jul 25, 2007
  3. Melina

    ModalPopupExtender and Event

    Melina, Dec 9, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    418
    Melina
    Dec 9, 2007
  4. Replies:
    0
    Views:
    605
  5. Replies:
    1
    Views:
    2,116
    4wardlight
    Jul 14, 2011
Loading...

Share This Page