I followed this example: http://blogs.msdn.com/delay/archive/2006/09/19/762609.aspx and it works perfectly.
If recreate the page as a Web User Control and use it on another page, the webservice failed to execute.
Page:
<%@ Page Language="C#" MasterPageFile="~/Loggen.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" Title="Untitled Page" %>
<%@ Register TagPrefix="test" src="~/WebUserControl.ascx" TagName="WebUserControl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentMainWindow" runat="Server">
<test:WebUserControl runat="server" ID="aa" />
</asp:Content>
Web User Control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<%-- A very simple data source to drive the demonstration --%>
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<items>
<item style='font-weight:bold' />
<item style='font-style:italic' />
<item style='text-decoration:underline' />
</items>
</Data>
</asp:XmlDataSource>
<%-- A simple list of all the data items available --%>
<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1">
<HeaderTemplate>
How would you like your dynamic content styled?
</HeaderTemplate>
<ItemTemplate>
• <asp:LinkButton ID="LinkButton" runat="server" Text='<%# Eval("style") %>' />
<%-- The ModalPopupExtender, popping up Panel1 and dynamically populating Panel2 --%>
<atk:ModalPopupExtender ID="ModalPopupExtender" runat="server">
<atk:ModalPopupProperties
TargetControlID="LinkButton" PopupControlID="Panel1" OkControlID="Button1"
BackgroundCssClass="modalBackground" DynamicControlID="Panel2"
DynamicContextKey='<%# Eval("style") %>' DynamicServiceMethod="GetContent" />
</atk:ModalPopupExtender>
</ItemTemplate>
</asp:DataList>
<%-- All ModalPopups share the same popup --%>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" style='display:none;'>
<p>This popup popped at <asp:Label ID="Panel2" runat="server" /> and all was well.</p>
<p><asp:Button ID="Button1" runat="server" Text="OK" /></p>
</asp:Panel>
And codefile:
ublic partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public 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> ';
}
}
How to make it execute in a user control? The error is: WebService call failed: 500
Cheers