Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,in a simple aspx page I have two buttons (Btn1 & Btn2) with two panels (Panel1 & Panel2) and a modalpopextender (mpe1).Each button is directly beneath each panel.
Then I have the mpe at the bottom. Question, Is it possible that the mpe is shared between these buttons and their panels (Y/N), If Yes how do i code the targetcontrolid and the popupcontrolid for the mpe instead of having 2 mpe's for each of the controls above.
Posted
Updated 27-Nov-12 8:57am
v2
Comments
Richard C Bishop 26-Nov-12 15:33pm    
Yes, it is possible. My idea would be to set the targetcontrolid and popupcontrolid to hidden fields in the markup and then on either button_click event set those same properties to the panel you want and call the .Show() method on each of the button clicks. Does that make sense?
tee.ice 26-Nov-12 17:35pm    
Thank you very much richcb, yes that makes perfect sense i shall give it a try and will keep you posted.
tee.ice 26-Nov-12 20:32pm    
It worked!!! Thanks alot richcb.

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalBackground
{
background-color: #161616;
filter: alpha(opacity=80);
opacity: 0.8;
}
.modalPopup
{
background-color: #FFFFFF;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 300px;
height: 170px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" />
<asp:Panel ID="Panel1" runat="server" style="display:none">
This is Panel 1

<asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" />
<asp:Panel ID="Panel2" runat="server" style="display:none">
This is Panel 2

<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:HiddenField ID="HiddenField2" runat="server" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="HiddenField1" TargetControlID="HiddenField2" BackgroundCssClass="modalBackground" >

</div>
</form>
</body>
</html>

Default.aspx.cs:

protected void Button1_Click(object sender, EventArgs e)
{
ModalPopupExtender1.TargetControlID = Button1.ID;
ModalPopupExtender1.PopupControlID = Panel1.ID;
ModalPopupExtender1.Show();
}

protected void Button2_Click(object sender, EventArgs e)
{
ModalPopupExtender1.TargetControlID = Button2.ID;
ModalPopupExtender1.PopupControlID = Panel2.ID;
ModalPopupExtender1.Show();
}
Richard C Bishop 27-Nov-12 12:09pm    
You are welcome. I had to do the same thing one time, so I knew exactly what you wanted.

1 solution

XML
It worked!!! Thanks alot richcb.

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <style type="text/css">
    .modalBackground
    {
        background-color: #161616;
        filter: alpha(opacity=80);
        opacity: 0.8;
    }
    .modalPopup
    {
        background-color: #FFFFFF;
        border-width: 3px;
        border-style: solid;
        border-color: black;
        padding-top: 10px;
        padding-left: 10px;
        width: 300px;
        height: 170px;
    }
    </style>
</head>
<body>
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" />
        <asp:Panel ID="Panel1" runat="server" style="display:none">
        This is Panel 1

        <asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" />
        <asp:Panel ID="Panel2" runat="server" style="display:none">
        This is Panel 2

        <asp:HiddenField ID="HiddenField1" runat="server" />
        <asp:HiddenField ID="HiddenField2" runat="server" />
        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="HiddenField1" TargetControlID="HiddenField2" BackgroundCssClass="modalBackground" >

    </div>
    </form>
</body>
</html>

Default.aspx.cs:

 protected void Button1_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.TargetControlID = Button1.ID;
        ModalPopupExtender1.PopupControlID = Panel1.ID;
        ModalPopupExtender1.Show();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.TargetControlID = Button2.ID;
        ModalPopupExtender1.PopupControlID = Panel2.ID;
        ModalPopupExtender1.Show();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900