How to: Use the new dynamic population support for ModalPopupControl

For This we use DynamicControlID, DynamicContextKey, DynamicServicePath, and DynamicServiceMethod. These properties behave just like they do for the DynamicPopulate control (please follow that link for more details) and the existing controls have been modified to call the "populate" function as part of their popup actions.

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="atlasToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">

public static string GetContent(string contextKey)
// Create a random color
string color = (new Random()).Next(0xffffff).ToString("x6");
// Use the style specified by the page author
string style = contextKey;
// Display the current time
string time = DateTime.Now.ToLongTimeString();
// Compose the content to return
return "<span style='color:#" + color + "; " + style + "'>" + time + "</span> ";

<html xmlns="">
<head id="Head1" runat="server">
<title>Dynamic ModalPopup Demonstration</title>
<%-- Style the page so it looks pretty --%>
<style type="text/css">
body { font-family:Verdana; font-size:10pt; }
.background { background-color:Gray; }
.popup { width:200px;padding:10px;background-color:White;
vertical-align: middle;
<form id="form1" runat="server">
<%-- Atlas pages need a ScriptManager --%>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<%-- A very simple data source to drive the demonstration --%>
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<item style="font-weight:bold" />
<item style="font-style:italic" />
<item style="text-decoration:underline" />
<%-- A simple list of all the data items available --%>
<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1">
How would you like your dynamic content styled?
<asp:LinkButton ID="LinkButton" runat="server" Text='<%# Eval("style") %>' />
<%-- The ModalPopupExtender, popping up Panel1 and dynamically populating Panel2 --%>
<atlasToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="LinkButton"
PopupControlID="Panel1" OkControlID="Button1" BackgroundCssClass="background"
DynamicControlID="Panel2" DynamicContextKey='<%# Eval("style") %>' DynamicServiceMethod="GetContent" />
<%-- All ModalPopups share the same popup --%>
<asp:Panel ID="Panel1" runat="server" CssClass="popup" Style="display: none;">
This popup popped at
<asp:Label ID="Panel2" runat="server" />
and all was well.</p>
<asp:Button ID="Button1" runat="server" Text="OK" /></p>


Post a Comment


Close Menu