我正在尝试使用点击处理程序。我的功能如此(这些都属于同一类):
[DirectMethod]
protected bool Save()
{
//do work
}
我尝试用:
来调用它using (Ext.Net.Button yes = new Ext.Net.Button())
{
// random set up for button
// failed because it couldn't find namespace
yes.Listeners.Click.Handler = "Namespace.Class.Save();";
// attempt 2: removed the first one and assumed that the [DirectMethod] sets
// it to be Ext.net.DirectMethods.Save();
yes.Listeners.Click.Handler = "Ext.net.DirectMethods.Save();"
}
首先无法找到命名空间,第二次失败,因为“对象不支持此属性或方法。”
我用什么字符串来渲染它?如果不是Listeners.Click.Handler
方式,我还能怎么做呢?
该函数位于扩展Ext.Net.Window
的自定义控件中,而using项位于一个名为Display()
的函数中,用于呈现控件。
根据vladsch的回应,我已将其更改为:
[DirectMethod(Namespace="MyMethods")]
public bool Save()
{
//do work
}
,处理程序字符串现在是:
yes.Listeners.Click.Handler = "MyMethods.Save();"
这样做时,我得到“'MyMethods'未定义。”
答案 0 :(得分:3)
DirectMethod必须是公开的 您也可以定义自己的命名空间(而不是Ext.net.DirectMethods) [DirectMethod(命名空间= “MyDirectMethods”)]
答案 1 :(得分:0)
使用X.GetCmp我能够检索数据。它可能不是最好的方式(可能是没有回发的方式),但它至少可以获得我需要的结果。