469,602 Members | 2,012 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

usercontrol and modalPopupExtender

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?
Aug 14 '07 #1
1 18167
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

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?
Sep 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by suzi167 | last post: by
reply views Thread by =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post: by
1 post views Thread by Victor | last post: by
reply views Thread by SD | last post: by
2 posts views Thread by Peter | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.