Question

I have created a custom web control that I must embed in a page layout inside SharePoint. Basically, the page layout will be used only by pages with a webforms inside and the control act as a kind of navigation menu to keep track of form page progression.

Now, I know that the control will always be declared only once and it must be accessible by the form pages. Instead of looking up the control collection of the parent from within the form page I've done this.

    public static QuickNavigation Self
    {
        get
        {
            return System.Web.HttpContext.Current.Items["QuickNavigation"] as QuickNavigation;
        }
        private set
        {
            System.Web.HttpContext.Current.Items["QuickNavigation"] = value;
        }
    }

    public QuickNavigation()
    {
        Self = this;
    }

To access the control instance from the form pages, I call the only static propriety of the class. What do you think of that, is there a better practice?

Was it helpful?

Solution

It works, but it seems odd to me to need a reference to a control to have some business logic in other controls.

Did you consider separating your code to some service like business controller and separate UI views. In that case, you plug all your UI views to your business controller, and you do not need any control to control reference. The best place to share your state is the Items collection in this case, so that practice you can keep.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top