1

Ext.net v2.2 .Net Framework v4.5
我的直接方法

[DirectMethod]  
   public static Panel AddTab(int postId)  
   {  
       var pnlEditPost = new Panel  
       {  
           ID = postId.ToString(),  
           Icon = Icon.BookEdit,  
           Title = "Edit",  
           Layout = "Fit",  
           Closable = true,  
           AutoDoLayout = true  
       };  
       return pnlEditPost;  
   }  

我需要在 javascript 中获取 pnlEditPost 并将其添加到我的 TabPanel

4

1 回答 1

0

确切的答案是无法返回 Panel 实例。

但是您可以返回一个带有面板配置的字符串。

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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    [DirectMethod]
    public static string AddTab(int count)
    {
        return ComponentLoader.ToConfig(new Ext.Net.Panel
        {
            Title = "Tab " + count,
            Html = "Server time: " + DateTime.Now.ToLongTimeString()
        });
    }
</script>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>

    <script>
        var addTab = function () {
            var tabPanel = App.TabPanel1;

            App.direct.AddTab(tabPanel.items.getCount(), {
                success: function (result) {
                    var tabs = tabPanel.add(eval(result));

                    tabPanel.setActiveTab(tabs[0]);
                }
            });
        };
    </script>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />

        <ext:Button runat="server" Text="Add tab" Handler="addTab" />

        <ext:TabPanel ID="TabPanel1" runat="server" />
    </form>
</body>
</html>

此外,您可能有兴趣查看此示例

于 2013-06-26T06:00:24.047 回答