Royi Namir
Royi Namir

Reputation: 148524

Access user control type from a dll?

I have a user control (under a website project)

UcArticle.ascx

<%@ Control Language="C#" 
            AutoEventWireup="true"
            CodeFile="UcArticle.ascx.cs" 
            Inherits="Uc_UcArticle" 
            ViewStateMode="Disabled" %>
...

And the code Behind is :

UcArticle.ascx.cs

public partial class Uc_UcArticle : System.Web.UI.UserControl
{
   ...
}

However , I have a DLL project and a method inside it which should use the type UcArticle :

  public void AddMethod(UcArticle uc ) //error here
        {
         //do something with uc...

        }

But the dll doesn't know UcArticle ( Cannot resolve symbol)

p.s. I could use dynamic to access the properties of uc , but I don't want to do that.

How can I make the dll know the type UcArticle ?

Upvotes: 0

Views: 228

Answers (2)

Ethan Wang
Ethan Wang

Reputation: 98

Well, i think this is a bad design.

In you AddMethod function, do you really need your customized user control type? why not declare an interface, make your customized user control implements the interface, also change the AddMethod function to carry the interface type as parameter. just expose whatever operation you want to outside.

what do you think?

updated(i just type directly here, so, sorry for the format):

//well then you can declare the interface as:
public interface ITextControl{
 string TextValue{get;set}
}
//and in your code:
public partical class whateveryourcontrolname:UserControl,ITextControl
{
/..../
public string TextValue{
 get{
  return this.Text;
 }
set{
 this.Text=value;
 }
}
}
//and your method:
void AddMethod(ITextControl txtCtrl){
 txtCtrl.TextValue="Yes";
}

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273244

When you have a project that contains a UC and the project depends on an assembly that needs the UC, then you have a circular dependency.

The best way to break this is to put the UC in yet another, separate, assembly.

But it remains a smell that any part of your business logic should need to know about a piece of the UI. So do rethink the design that leads you here. Something's rotten.

Upvotes: 2

Related Questions