PDA

View Full Version : [CLOSED] Set Textfield from static DirectMethod



Manni
Nov 14, 2012, 8:11 PM
What is the best way to set a textfield from a static DirectMethod? I understand that the static Direct Method does not have access to the Page controls.

geoffrey.mcgill
Nov 14, 2012, 8:14 PM
Correct. During a Static [DirectMethod] you do not have access to the Page Controls Collection, so no direct access to a TextField. But, by using the X.GetCmp helper Method you can get an instance (more like a proxy instance) of the component.

The following sample demonstrates the complete scenario.

Example


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

<script runat="server">
[DirectMethod]
public static void DoSomething()
{
var textfield = X.GetCmp<TextField>("TextField1");


textfield.Text = "Testing";
}
</script>


<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />


<ext:TextField ID="TextField1" runat="server" />


<ext:Button runat="server" Text="Submit">
<Listeners>
<Click Handler="App.direct.DoSomething();" />
</Listeners>
</ext:Button>
</body>
</html>

Hope this helps.

Manni
Nov 14, 2012, 9:39 PM
Thanks Geoffrey, that works!