Hi,
I am developing some modules with ClientAPI and encountered that when I have 2 modules with ControlMethod callbacks on a single page it doesn't work. There is no problem with the modules when used individually, anyone have any idea? the below are my code snippts:
///////////////// Module 1 - ViewMapClient.ascx.cs /////////////////////
[ControlMethodClass("MapLingo.MapClient")]
partial class ViewMapClient : PortalModuleBase, IActionable
{
protected void Page_Init(object sender, System.EventArgs e)
{
ClientAPI.HandleClientAPICallbackEvent(this.Page);
ClientAPI.RegisterControlMethods(this, this.ID);
}
[ControlMethod()]
public string Validate(string address)
{
//do some stuff
return "somestring";
}
}
///////////////// Module 1 - ViewMapClient.ascx/////////////////////
<%@ Control Language="C#" Inherits="MapLingo.MapClient.ViewMapClient"
AutoEventWireup="true" CodeBehind="ViewMapClient.ascx.cs" %>
<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
TagPrefix="asp" %>
<script type="text/javascript">
function validate() {
dnn.xmlhttp.callControlMethod('MapLingo.MapClient.ViewMapClient', 'Validate', { address: 'Somestring' }, validateResultSuccess, validateResultFail);
}
function validateResultFail(payload, ctx, req) {
error: ' + payload);
}
function validateResultSuccess(payload, ctx, req) {
oken: ' + payload);
}
</script>
<a href="#" onclick="validate()">test</a>
///////////////// Module 2 - ViewMapSearch.ascx.cs /////////////////////
[ControlMethodClass("MapLingo.MapMapSearchResult")]
partial class MapMapSearchResult: PortalModuleBase, IActionable
{
protected void Page_Init(object sender, System.EventArgs e)
{
ClientAPI.HandleClientAPICallbackEvent(this.Page);
ClientAPI.RegisterControlMethods(this, this.ID);
}
protected void Page_Load(object sender, System.EventArgs e)
{
ClientScriptManager script = Page.ClientScript;
StringBuilder scriptToInject = new StringBuilder();
scriptToInject.AppendLine("<script type=\"text/javascript\">");
scriptToInject.AppendLine("function mapSearchResultSuccess(payload, ctx, req) {");
scriptToInject.AppendLine("var ctx = { ns: '"+this.ClientID+"_' };");
scriptToInject.AppendLine("$get(ctx.ns + 'divResults').innerHTML = payload;}");
scriptToInject.AppendLine("</script>");
script.RegisterStartupScript(this.GetType(), "CallingScript", scriptToInject.ToString());
}
[ControlMethod()]
public string Search(string address)
{
//do some stuff
return "somestring";
}
}
///////////////// Module 2 - ViewMapSearch.ascx /////////////////////
<%@ Control Language="C#" Inherits="Maplingo.MapSearchResult.ViewMapSearchResult"
AutoEventWireup="true" CodeBehind="ViewMapSearchResult.ascx.cs" %>
<script type="text/javascript">
function mapSearchResultFail(payload, ctx, req) {
error: ' + payload);
}
function mapSearchResultUpdate()
{
dnn.xmlhttp.callControlMethod('MapLingo.MapSearchResult.ViewMapSearchResult', 'Search', { address: 'SomeString' }, mapSearchResultSuccess, mapSearchResultFail);
}
</script>
<div id="divResults" runat="server">
</div>