usercontrol and modalPopupExtender

G

Guest

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?
 
J

JB

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top