We’ve built a silverlight grid which allows for editing of sub entities from a primary entity form. Works like a champ. But we have to have a separate save button on the silverlight control to push the updates back to CRM. What we’d like to do is allow the CRM form to call a method on the silverlight control to alert us that the form is saving and then save the data in the silverlight form at the same time. But it’s just not working. What we’ve tried so far is this:
In the Silverlight control we’ve got a public class:
[ScriptableType] public class JSModel { [ScriptableMember] public void Save() { if (OnSave != null) { OnSave(this, new EventArgs()); } }public event EventHandler OnSave; public JSModel() { HtmlPage.RegisterScriptableObject("JSModel", this); HtmlPage.Window.Eval( @" function CallSLSave(){var sl = Xrm.Page.ui.controls.get('" + HtmlPage.Plugin.TagName + @"');
sl.content.JSModel.Save();} ");
ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm"); ScriptObject Page = (ScriptObject)xrm.GetProperty("Page"); ScriptObject data = (ScriptObject)Page.GetProperty("data"); ScriptObject entity = (ScriptObject)data.GetProperty("entity"); entity.Invoke("addOnSave", new object[] { "CallSLSave" }); } }
But it's not calling the javascript method . Anyone have any ideas what we're doing wrong?
Thanks to the magic of the HTML bridge, you can use a delegate as the parameter to the addOnSave method. There is no need for a Javascript bootstrap function, or a scriptable object on the page. This simplifies the solution to this:
Also, note: The function to call doesn’t need to be a scriptable member.