tags:

views:

355

answers:

3

I'm creating a custom web user control in c#. It is intended to interact with a permission hierarchy. We have different "sites" and each site has many "apps" and each app has many "permissions"

So, We have a TabPanel that loads a tab for each site. Then in each tab we have a TreeView where the parent nodes are the apps and the inner nodes are the permissions.

The Permissions show check boxes based on some criteria and are checked based on whether or not the HasPermission function returns true.

All of this code works...but only for the first user selected. For any subsequent user chosen, a step through the debugger shows all the correct logic being executed, but the page displays the same information as that of the first user selected.

So basically, it's saving the display somewhere...and I'm at a loss to find out where.

public partial class Permissions : System.Web.UI.UserControl
{
    string _NTLogin;
    CoreUser _User;
    bool _IsAdmin;
    public string NTLogin
    {
        get
        {
            return _NTLogin;
        }
        set
        {
            ViewState["NTLogin"] = value;
            _NTLogin = value;
        }
    }
    public bool IsAdmin
    {
        get
        {
            return _IsAdmin;
        }
        set
        {
            ViewState["IsAdmin"] = value;
            _IsAdmin = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void LoadTabs()
    {
        string [] sites = MISCore.BusinessLayer.CorePermission.GetSites();
        foreach (string site in sites)
        {
            TabPanel tp = new TabPanel();
            tp.HeaderText = site;
            TabContainer1.Tabs.Add(tp);
        }
    }
    public void LoadTrees()
    {
        if(_User == null)
            return;
        TabPanelCollection tabs = TabContainer1.Tabs;
        foreach (TabPanel tab in tabs)
        {
            string site = tab.HeaderText;
            string[] apps = MISCore.BusinessLayer.CorePermission.GetApplications(site);
            TreeView tv1 = new TreeView();
            tv1.EnableViewState = false;
            foreach (string app in apps)
            {
                TreeNode tn1 = new TreeNode(app);
                tn1.SelectAction = TreeNodeSelectAction.None;
                string[] perms = MISCore.BusinessLayer.CorePermission.GetPermissions(site, app);
                foreach (string perm in perms)
                {
                    TreeNode tcn1 = new TreeNode(perm);
                    tcn1.SelectAction = TreeNodeSelectAction.None;
                    if (IsAdmin || _User.Manager.HasPermission(site, app, perm))
                    {
                        tcn1.ShowCheckBox = true;
                        if (_User.HasPermission(site, app, perm))
                        {
                            tcn1.Checked = true;
                        }
                        else
                        {
                            tcn1.Checked = false;
                        }
                    }
                    else
                    {
                        tcn1.ShowCheckBox = false;
                    }
                    tn1.ChildNodes.Add(tcn1);
                }
                tv1.Nodes.Add(tn1);
            }
            tab.Controls.Add(tv1);
        }

    }
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        _NTLogin = (string)ViewState["NTLogin"];
        _IsAdmin = (bool)ViewState["IsAdmin"];
        if(_NTLogin != null)
            _User = new CoreUser(_NTLogin);
        TabContainer1.Tabs.Clear();
        LoadTabs();
        LoadTrees();
    }
}

[UPDATE] I iterate through the treeview after all the above code, it correctly stores their correct status. This is an issue with displaying. I can successfully change any other property, tooltip, text, etc to display their state, but the checkboxes are not updating...

A: 

I would use Fiddler to see who is caching the results. By looking at the requests you'll be able to tell if it's the browser or the server causing the problem.

David
A: 

Or if its okay with your client, you can put in a small link button that says refresh, and either you or the user can force this refresh treeview method, whenever required.

Nidhi
A: 

Should be pretty simple, in the paramters for the tab just add EnableViewState = false. Let me know if this works for you.