PDA

View Full Version : Triggering [DirectMethod] in a UserControl



geoffrey.mcgill
Dec 18, 2013, 3:55 AM
I don't know if this will be helpful to anyone, but I was just testing a sample with [DirectMethod]'s configured in the Child UserControls, and getting Buttons within those UserControls to fire instances of their own [DirectMethod].

The key to getting this working is using the #{DirectMethods} Token to namespace the DirectMethod calls.

Example (Parent.aspx)


<%@ Page Language="C#" %>

<%@ Register Src="Child.ascx" TagPrefix="uc1" TagName="Child" %>

<script runat="server">
[DirectMethod]
public void Ping()
{
X.Msg.Notify("Parent Message", this.Message.Text).Show();
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body style="padding:30px;">
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TextField ID="Message" runat="server" Text="Paris" FieldLabel="Parent Message" />

<ext:Button runat="server" Text="Submit Parent" OnClientClick="#{DirectMethods}.Ping()" />

<br />
<br />
<br />

<uc1:Child ID="Child1" runat="server" MessageText="London" />

<br />
<br />
<br />

<uc1:Child ID="Child2" runat="server" MessageText="New York" />
</form>
</body>
</html>

Example (Child.ascx)


<%@ Control Language="C#" %>

<script runat="server">
[DirectMethod]
public void Ping()
{
X.Msg.Notify("Child Message", this.Message.Text).Show();
}

public string MessageText { get; set; }
</script>

<ext:TextField
ID="Message"
runat="server"
Text='<%# this.MessageText %>'
FieldLabel="Child Message"
AutoDataBind="true"
/>

<ext:Button runat="server" Text="Child Submit" OnClientClick="#{DirectMethods}.Ping()" />

Hope this helps.