How to reference UserControl?

1.9k Views Asked by At

I work on an application that has a particular design flaw, where some content should be accessible in multiple areas of the application depending on what role(s) a user may have. In the past this has led developers to copy and paste pages into different places with slightly different names, which ultimately leads to bugs when things get out of sync and also just feels yucky.

I want to try to abstract out the (99%) common code into its own class, however the code behind each page references various controls on the page. I can't seem to figure out how to reference the UserControl classes.

For example a page might have

<%@ Register Src="~/uc/ResearchParamBar.ascx" TagName="ResearchParamBar" TagPrefix="uc1" %>
...
<uc1:ResearchParamBar ID="ResearchParamBar1" runat="server"/>

And the code behind would have

private void InitializeComponent()
{
    // wire the event to the destination user control handler
    ResearchParamBar1.SourcePageID = ObjectID;
    ...
 }

The user control is defined like

public partial class ResearchParamBar : BaseUserControl

I was trying to pass a ResearchParamBar in the constructor to the abstract class, but it's not clear to me how to reference that class.

The type or namespace name 'ResearchParamBar' could not be found (are you missing a using directive or an assembly reference?)

public abstract class SummaryBase : WRBasePage
{

    public abstract string ObjectID
    {
        get;
    }

    //Cannot figure out how to reference ResearchParamBar
    private ResearchParamBar ResearchParamBar1;

    public SummaryBase(ResearchParamBar researchParamBar)
    {
        ResearchParamBar1 = researchParamBar;
    }
0

There are 0 best solutions below