各位大神们,小弟跪求实现点击顶部菜单,在窗体左边动态读取xml文件添加手风琴+树菜单,手风琴面板的内容是读取xml文件动态添加, 我在每个按钮的点击事件里写动态添加代码。为什么页面显示不出来,怎么将动态添加的内容显示出来呢 JObject ids;
protected void Page_Init(object sender, EventArgs e)
{
// 注册客户端脚本,服务器端控件ID和客户端ID的映射关系
ids = GetClientIDS(btnExpandAll, btnCollapseAll, mainTabStrip, leftRegion, menuSettings);
// 只在页面第一次加载时注册客户端用到的脚本
if (!Page.IsPostBack)
{
string idsScriptStr = String.Format("window.IDS={0};", ids.ToString(Newtonsoft.Json.Formatting.None));
PageContext.RegisterStartupScript(idsScriptStr);
}
}
private void BindLeftTree(string menuType)
{
if (menuType == "JC")
{
XmlDataSource1.DataFile = "./common/XML/jichu.xml";
}
else if (menuType == "JH")
{
XmlDataSource1.DataFile = "./common/XML/jinhuo.xml";
}
BindLeftTree();
}
private void BindLeftTree()
{
Accordion accordionMenu = new Accordion();
accordionMenu.ID = "accordionMenu";
accordionMenu.EnableFill = true;
accordionMenu.ShowBorder = false;
accordionMenu.ShowHeader = false;
leftRegion.Items.Add(accordionMenu);
XmlDocument xmlDoc = XmlDataSource1.GetXmlDocument();
XmlNodeList xmlNodes = xmlDoc.SelectNodes("/Tree/TreeNode");
foreach (XmlNode xmlNode in xmlNodes)
{
if (xmlNode.HasChildNodes)
{
AccordionPane accordionPane = new AccordionPane();
accordionPane.Title = xmlNode.Attributes["Text"].Value;
Tree innerTree = new Tree();
innerTree.EnableArrows = true;
innerTree.ShowBorder = false;
innerTree.ShowHeader = false;
innerTree.EnableIcons = false;
innerTree.AutoScroll = true;
innerTree.EnableSingleClickExpand = true;
accordionPane.Items.Add(innerTree);
XmlDocument innerXmlDoc = new XmlDocument();
innerXmlDoc.LoadXml(String.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Tree>{0}</Tree>", xmlNode.InnerXml));
// 绑定AccordionPane内部的树控件
innerTree.DataSource = innerXmlDoc;
innerTree.DataBind();
// 重新设置每个节点的图标
ResolveTreeNode(innerTree.Nodes);
}
}
ids.Add("mainMenu", accordionMenu.ClientID);
ids.Add("menuType", "accordion");
}
js文件:
F.ready(function () {
// IDS:default.aspx.cs 中向页面输出的控件客户端ID集合
var btnExpandAll = F(IDS.btnExpandAll);
var btnCollapseAll = F(IDS.btnCollapseAll);
var mainMenu = F(IDS.mainMenu);
var mainTabStrip = F(IDS.mainTabStrip);
var windowSourceCode = F(IDS.windowSourceCode);
var leftRegion = F(IDS.leftRegion);
var menuSettings = F(IDS.menuSettings);
。。。。。
});
这里怎么将这个 添加的ID--mainMenu返回给js呢。拜托大神们给点建议吧
|