using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2.UserControls
{
public partial class InsidePanel : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region Public Properties
//This property allows for a way to add child controls to the user control on the page
//Any controls added to it are added to the place holder in the OnInit method below
public Control ContentTemplate { get; set; }
#endregion
#region Public Events and Delegate
//the public events must conform to this format
public delegate void Button_Click(object sender, EventArgs e);
//these two public events are to be customized as need on the page and will be called
//by the private events of the buttons in the user control
public event Button_Click OkClick;
public event Button_Click CancelClick;
#endregion
#region Private Events
//These events call the public events assigned to the user control on the page
protected void btnOk_Click(object sender, EventArgs e)
{
this.OkClick(sender, e);
}
protected void btnCancel_Click(object sender, EventArgs e)
{
this.CancelClick(sender, e);
}
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//add the child controls from the public property to the place holder in the panel
this.phMain.Controls.Add(this.ContentTemplate);
}
}
}
qysan
Member
9 Points
8 Posts
Re: ModelPopupExtender does not work inside Usercontrol when using Masterpages.
May 10, 2012 06:57 AM|LINK
Thanks for the Response but again no help in my scenario.
Please find my code below.
1. Default.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %> <%@ Register Src="~/UserControls/ModelPopup.ascx" TagName="ModelPopup" TagPrefix="mp1" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <div> <mp1:ModelPopup ID="modelPopup" runat="server" /> </div> </asp:Content>2. User Control .ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ModelPopup.ascx.cs" Inherits="WebApplication2.UserControls.ModelPopup" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <%@ Register Src="~/UserControls/InsidePanel.ascx" TagName="PopupPanel" TagPrefix="ta1" %> <div> <table width="100%"> <tr> <td> <asp:Label runat="server" ID="lblCommentsTitle"></asp:Label> </td> <td align="right"> <asp:ImageButton ID="btnOptions" runat="server" ImageUrl="~/Images/plus-8.png" AlternateText="Click to expand comment area." /> </td> </tr> <tr> <td colspan="2"> <asp:TextBox runat="server" ID="txtBxComments" TextMode="MultiLine" Rows="4" Width="100%" CssClass="Text"></asp:TextBox> </td> </tr> </table> <asp:ModalPopupExtender ID="mpeOptions" runat="server" DropShadow="true" OkControlID="ppTextArea_btnOk" CancelControlID="ppTextArea_btnCancel" TargetControlID="btnOptions" PopupControlID="ppTextArea_pnlMain" BackgroundCssClass="modalBackground" /> <ta1:PopupPanel runat="server" ID="ppTextArea" > <contenttemplate> <asp:TextBox runat="server" ID="txtBxTextArea" TextMode="MultiLine" Width="100%" Rows="15" CssClass="Text"></asp:TextBox> </contenttemplate> </ta1:PopupPanel> </div>3. User control .ascx InsidePanel
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="InsidePanel.ascx.cs" Inherits="WebApplication2.UserControls.InsidePanel" %> <asp:Panel runat="server" ID="pnlMain" CssClass="modalPopup"> <asp:PlaceHolder runat="server" ID="phMain" /> <br /> <asp:Button runat="server" ID="btnOk" Text="OK" OnClick="btnOk_Click" /> <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClick="btnCancel_Click" /> </asp:Panel>4. Code Behind InsidePanel
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication2.UserControls { public partial class InsidePanel : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } #region Public Properties //This property allows for a way to add child controls to the user control on the page //Any controls added to it are added to the place holder in the OnInit method below public Control ContentTemplate { get; set; } #endregion #region Public Events and Delegate //the public events must conform to this format public delegate void Button_Click(object sender, EventArgs e); //these two public events are to be customized as need on the page and will be called //by the private events of the buttons in the user control public event Button_Click OkClick; public event Button_Click CancelClick; #endregion #region Private Events //These events call the public events assigned to the user control on the page protected void btnOk_Click(object sender, EventArgs e) { this.OkClick(sender, e); } protected void btnCancel_Click(object sender, EventArgs e) { this.CancelClick(sender, e); } #endregion protected override void OnInit(EventArgs e) { base.OnInit(e); //add the child controls from the public property to the place holder in the panel this.phMain.Controls.Add(this.ContentTemplate); } } }Thanks
Theo