I'm using some user controls in a web app with some custom security designed around different product offerings. Each product offering is defined as a user control which inherits from a custom <MyUserControl> : UserControlBase : UserControl. As each user control is loaded I'm calling a recursive method to check the parent tree to find the PanelBarItem and disable it if the user control is disabled.
So far I haven't gotten this to work as defined in the above sample. Any ideas on how to traverse up and get the telerik RadPanelItem?
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using System.Text; |
| /// <summary> |
| /// Summary description for UserControlBase |
| /// </summary> |
| public class UserControlBase : UserControl |
| { |
| public UserControlBase() : base() |
| { |
| Log("UserBase Constructor"); |
| base.Load += new EventHandler(UserControlBase_Load); |
| } |
| void UserControlBase_Load(object sender, EventArgs e) |
| { |
| Log("UserBase Load"); |
| bool renderable = false; // || false; |
| SetParentPanel(Parent, renderable); |
| } |
| public void SetParentPanel(Control parent, bool enabled) |
| { |
| string key = "TestEnabled"; |
| Log(enabled.ToString()); |
| if (parent == null) |
| return; |
| Log(parent.GetType().ToString()); |
| if (parent is Telerik.Web.UI.RadPanelItem) |
| { |
| Telerik.Web.UI.RadPanelItem panel = parent as Telerik.Web.UI.RadPanelItem; |
| if (string.IsNullOrEmpty(panel.Attributes[key])) |
| panel.Attributes.Add(key, enabled.ToString()); |
| if (enabled) |
| panel.Attributes[key] = "true"; |
| if (Convert.ToBoolean(panel.Attributes[key])) |
| { |
| Log("Enabling"); |
| panel.Enabled = true; |
| return; |
| } |
| else |
| { |
| Log("Disabling"); |
| panel.Enabled = false; |
| return; |
| } |
| } |
| SetParentPanel(parent.Parent, enabled); |
| } |
| public static void Log(string log) |
| { |
| const int LOGSIZE = 150; |
| const int KBYTESIZE = 1024; |
| const string FILELOC = @"c:\logfiles\testlog.log"; |
| using (System.IO.FileStream fs = new System.IO.FileStream(FILELOC, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite)) |
| { |
| System.IO.StreamReader reader = new System.IO.StreamReader(fs); |
| log += "\n" + reader.ReadToEnd(); |
| int max = LOGSIZE * KBYTESIZE; |
| byte[] bytes = Encoding.UTF8.GetBytes(log); |
| if (bytes.Length < max) |
| { |
| fs.SetLength(0); |
| fs.Write(bytes, 0, bytes.Length); |
| } |
| else |
| { |
| fs.SetLength(0); |
| fs.Write(bytes, 0, max); |
| } |
| fs.Flush(); |
| fs.Close(); |
| } |
| } |
| } |
| <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" |
| CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %> |
| <%@ Register Src="~/WebControl1.ascx" TagName="TestControl" TagPrefix="my" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> |
| <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Default2006" Width="100%"> |
| <Items> |
| <telerik:RadPanelItem runat="server" Text="Control1"> |
| <Items> |
| <telerik:RadPanelItem> |
| <ItemTemplate> |
| <my:TestControl runat="server" ID="TestControl1" /> |
| </ItemTemplate> |
| </telerik:RadPanelItem> |
| </Items> |
| </telerik:RadPanelItem> |
| </Items> |
| <CollapseAnimation Duration="100" Type="None" /> |
| <ExpandAnimation Duration="100" Type="None" /> |
| </telerik:RadPanelBar> |
| </asp:Content> |
So far I haven't gotten this to work as defined in the above sample. Any ideas on how to traverse up and get the telerik RadPanelItem?