Jan 01, 2011, 4:43 PM
Call DirectMethod from a TreePanel
Happy New Year 2011.
I have a masterpage with a left navigation (Treepanel) in a usercontrol and a main content grid on a different usercontrol. I created the TreePanel from the codebehind which displays all the departments and the categories inside the departments. When I click on a department the categories are displayed but I cannot seem to understand how to call a DirectMethod on the main content usercontrol. I want to be able to pass the department or the category id to the DirectMethod that is on the main content usercontrol and refresh the grid.
Line 40 of MenuTree.ascx.cs is I think the start.
Here is the live start of the project without line 40:
http://asiancrafters.com/Catalog.aspx
This is what I have:
MasterPage Code:
I have a masterpage with a left navigation (Treepanel) in a usercontrol and a main content grid on a different usercontrol. I created the TreePanel from the codebehind which displays all the departments and the categories inside the departments. When I click on a department the categories are displayed but I cannot seem to understand how to call a DirectMethod on the main content usercontrol. I want to be able to pass the department or the category id to the DirectMethod that is on the main content usercontrol and refresh the grid.
Line 40 of MenuTree.ascx.cs is I think the start.
Here is the live start of the project without line 40:
http://asiancrafters.com/Catalog.aspx
This is what I have:
MasterPage Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="web.master.cs" Inherits="web1" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register src="UserControl/MenuTree.ascx" tagname="MenuTree" tagprefix="uc1" %>
<%@ Register src="UserControl/RightColumn.ascx" tagname="RightColumn" tagprefix="uc2" %>
<!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 runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<link href="Theme/Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<ext:ResourceManager runat="server" Theme="Gray" />
<form id="form1" runat="server">
<div class="page">
<div class="headerRow">
<img src="images/logo.jpg" alt="Go to the Homepage" />
</div>
<div class="mainContentRow">
<div class="leftColumn">
<uc1:MenuTree ID="leftNavigation" runat="server" />
</div>
<div class="centerColumn">
<asp:ContentPlaceHolder ID="body" runat="server" />
</div>
<div class="rightColumn">
<uc2:RightColumn ID="rightColumn" runat="server" />
</div>
</div>
</div>
</form>
</body>
</html>
MenuTree.ascx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
public partial class UserControl_MenuTree : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Ext.Net.TreePanel tree = new Ext.Net.TreePanel();
this.PlaceHolder1.Controls.Add(tree);
tree.ID = "TreePanel1";
tree.Width = Unit.Pixel(220);
tree.Height = Unit.Pixel(450);
tree.Icon = Icon.BookOpen;
tree.Title = "Catalog";
tree.AutoScroll = true;
Ext.Net.TreeNode root = new Ext.Net.TreeNode("Departments");
root.Expanded = true;
tree.Root.Add(root);
CatalogBLL catalogBLL = new CatalogBLL();
List<Department> dept = new List<Department>();
dept = catalogBLL.GetDepartmentTree();
if (dept != null && dept.Count > 0)
{
foreach (Department department in dept)
{
Ext.Net.TreeNode deptNodes = new Ext.Net.TreeNode(department.Name, Icon.ApplicationSideExpand);
deptNodes.NodeID = department.ID.ToString();
root.Nodes.Add(deptNodes);
deptNodes.Listeners.Click.Handler = "Ext.net.DirectMethods.department_click(deptNodes.NodeID);";
CatalogBLL categoryBLL = new CatalogBLL();
List<Category> cat = new List<Category>();
cat = categoryBLL.GetCategoriesBy(Convert.ToInt32(department.ID));
if (cat != null && cat.Count > 0)
{
foreach (Category category in cat)
{
Ext.Net.TreeNode catNodes = new Ext.Net.TreeNode(category.Name, Icon.Pencil);
catNodes.NodeID = category.ID.ToString();
deptNodes.Nodes.Add(catNodes);
}
}
}
}
}
}
CatalogList.ascx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
public partial class UserControl_CatalogList : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
CatalogBLL catalogBLL = new CatalogBLL();
List<Catalog> catalog = new List<Catalog>();
catalog = catalogBLL.GetAllProducts();
dlCatalog.DataSource = catalog;
dlCatalog.DataBind();
}
}
[DirectMethod]
protected void department_click(Int32 deptID)
{
if (deptID > 0)
{
CatalogBLL catalogBLL = new CatalogBLL();
List<Catalog> catalog = new List<Catalog>();
catalog = catalogBLL.GetAllProducts();
dlCatalog.DataSource = catalog;
dlCatalog.DataBind();
dlCatalog.Update();
}
}
[DirectMethod]
protected void category_click(object sender, DirectEventArgs e)
{
}
[DirectMethod]
protected void search_click(object sender, DirectEventArgs e)
{
if (txtSearch.Text.Trim() != "")
{
ImageChooserDialog.Title = "Search Results";
CatalogBLL catalogBLL = new CatalogBLL();
List<Catalog> catalog = new List<Catalog>();
catalog = catalogBLL.SearchProducts(txtSearch.Text.Trim(), 1);
dlCatalog.DataSource = catalog;
dlCatalog.DataBind();
dlCatalog.Update();
}
}
}
Any help would be really appreciated. Thank you.