Ext.net使用组合框中的select Handler调用DirectMethod

时间:2011-11-18 06:06:48

标签: asp.net ext.net

外部标记

  <Listeners>
     <Select Handler="Ext.net.DirectMethods.loadcombo2();" />
    </Listeners>

C#

[DirectMethod]
protected void loadcombo2() 
{
    this.ComboBox2.AddItem("List1", "L1");
    this.ComboBox2.AddItem("List2", "L2");

}

如何使用组合框单元格更改调用直接方法?

我为此

收到错误
Uncaught TypeError: Object #<Object> has no method 'loadcombo2'

2 个答案:

答案 0 :(得分:2)

我认为这里的最佳做法是使用Select direct event。

将现有的直接方法替换为:

protected void LoadCombo2(object sender, DirectEventArgs e) {
    this.ComboBox1.AddItem("List1", "L1");
    this.ComboBox1.AddItem("List2", "L2");
}

用以下内容替换监听器:

<DirectEvents>
    <Select OnEvent="LoadCombo2" />
</DirectEvents>

答案 1 :(得分:1)

尝试为loadcombo2

设置public而不是protected

您可以尝试使用此代码,它适用于我:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest) {
            this.Store1.DataSource = new object[] {
                new object[] {"AL", "Alabama", "The Heart of Dixie"},

            };

            this.Store1.DataBind();
        }

    }

    [DirectMethod]
    public void LoadCombo2() {
        this.ComboBox1.AddItem("List1", "L1");
        this.ComboBox1.AddItem("List2", "L2");
    }

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Comboboxes - Ext.NET Examples</title>
</head>
<body>
    <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />

        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="abbr" />
                        <ext:RecordField Name="state" />
                        <ext:RecordField Name="nick" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>            
        </ext:Store>

        <h2>Not Editable:</h2>

        <ext:ComboBox 
            ID="ComboBox1" 
            runat="server" 
            StoreID="Store1" 
            Editable="false"
            DisplayField="state"
            ValueField="abbr"
            TypeAhead="true" 
            Mode="Local"
            ForceSelection="true"
            EmptyText="Select a state..."
            Resizable="true"
            SelectOnFocus="true"
            >
            <Listeners>
                <Select Handler="DT.Everest.DocFlow.LoadCombo2();" />
            </Listeners>

            </ext:ComboBox>
    </form>
</body>
</html>