如何从javascript中的DirectMethod中获得返回值(值类型是Ext.Net.Panel)并将其添加到Ex
本文关键字:Panel Net Ext Ex 添加 类型 中的 javascript DirectMethod 返回值 | 更新日期: 2023-09-27 18:18:57
Ext.net v2.2.Net Framework v4.5
My Direct Method
[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
确切的答案是没有办法返回Panel实例。
但是你可以返回一个带有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>
你也可能有兴趣看看这个例子