Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 26-Nov-12 8:56am
tee.ice252
Edited 27-Nov-12 8:57am
v2
Comments
richcb at 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 at 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 at 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();
}
richcb at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
    }
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,108
1 OriginalGriff 8,186
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100