Hi!
This is my ascx file (popup.ascx):
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Popup.ascx.cs" Inherits="LCTools.App.Web.CMS_2017.Secure.Control.Popup" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<asp:LinkButton ID="LinkButtonPopupDummy" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="LinkButtonPopupDummy_ModalPopupExtender" runat="server" BehaviorID="LinkButtonPopupDummy_ModalPopupExtender" TargetControlID="LinkButtonPopupDummy" PopupControlID="PanelMain" CancelControlID="LinkButtonClose" BackgroundCssClass="popup_background">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelMain" runat="server">
<div class="popup">
<div>
<div class="popup_header">
<table style="width:100%;">
<tr>
<td style="text-align:center;">
<asp:UpdatePanel ID="UpdatePanelHeader" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="LiteralHeader" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:8px;text-align:right;">
<asp:LinkButton ID="LinkButtonClose" runat="server" Text="[X]" />
</td>
</tr>
</table>
</div>
</div>
<div class="popup_content">
<asp:UpdatePanel ID="UpdatePanelContent" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolderContent" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</asp:Panel>
This is the code behind:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.ComponentModel;
using System.Security.Permissions;
namespace LCTools.App.Web.CMS_2017.Secure.Control
{
[
AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Inner"),
ParseChildren(true, "Inner"),
ToolboxData(
"<{0}:Popup runat=\"server\"> </{0}:Popup>")
]
public partial class Popup : Lib.baseControl
{
private List<System.Web.UI.Control> _content;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack && !this.Loaded)
{
foreach(System.Web.UI.Control c in this.Inner) { PlaceHolderContent.Controls.Add(c); }
}
}
public void Show(CommandButton.Types type)
{
string header = string.Empty;
switch (type)
{
case CommandButton.Types.CreateItem:
header = "Legg til ny vare";
break;
case CommandButton.Types.CreateGroup:
header = "Legg til ny gruppe";
break;
}
LiteralHeader.Text = header;
UpdatePanelHeader.Update();
LinkButtonPopupDummy_ModalPopupExtender.Show();
}
private bool Loaded { get { return ViewState["PopupLoaded"] != null ? (bool)ViewState["PopupLoaded"] : false; } set { ViewState["PopupLoaded"] = value; } }
[Category("Behavior"), DefaultValue(""), Description("Inner controls"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public List<System.Web.UI.Control> Inner
{
get
{
if (_content == null) { _content = new List<System.Web.UI.Control>(); }
return _content;
}
}
}
}
What Im trying to do is to avoid writing the same code everytime I need a popup dialog. I use ModalPopupExtender from Ajax Control Toolkit.
And this is how I want to use the user control:
<uc1:Popup runat="server" ID="PopupExample"><asp:Image ID="ImageNoContent" runat="server" ImageURL="some_picture.jpg" /></uc1:Popup>
When I need the dialog I call Show, and the idea is to add all the controls between the start and end tag to a ContentPlaceHolder (ID: PlaceHolderContent).
Is this possible, or am I way off??
Thanks for replying!