• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

circular reference

I have two different user controls.  Each control must reference the other.  The <% reference tags are generating a compiler error for a circular reference.  How can I get around this?
0
ARACK04
Asked:
ARACK04
  • 4
  • 4
  • 3
  • +2
3 Solutions
 
kmaicorpCommented:
Not sure about ASP.NET but in C#, if you put them in the same namespace, this appears to resolve the problem. I've come across something like this in WinForms.
0
 
aaronfengCommented:
You can get around this by having a 3rd project.  

For example, using project A, B, and C.  Put all the common code that your two projects needs to reference in the 3rd project.  In this case will be C.  So A will reference C, and B will reference C.  No more circular reference problem.

Cheers,

Aaron
http://aaronfeng.blogspot.com/
0
 
ThogekCommented:
How are they referencing each other?  Do they each contain instances of the other (which would be a true circular reference problem), or...?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ARACK04Author Commented:
>>Do they each contain instances of the other (which would be a true circular reference problem)

YES
0
 
ThogekCommented:
Uh... if A contains an instance of B which contains an instance of A...  How did you expect that to compile?

(The run-time instantiates an A object, which includes instantiation of a contained B object, which includes instantiation of a contained A object, which includes instantiation of a contained B object, which...)

Depending on what it is you're trying to accomplish (perhaps you can explain more why these two controls are including instances of each other?), aaronfeng might have the right idea above...
0
 
ARACK04Author Commented:
Well by your logic, how could you ever get a linked list to compile?  Shouldn't an instance of A should contain an instance of B, which is set to NULL until I give it a value, and vice versa fpr B.
0
 
aaronfengCommented:
The only way you can get around circular reference is do what I said above, or put everything in one project.

Cheers,

Aaron
0
 
ARACK04Author Commented:
When you say a third project, are you talking about a third user control?
0
 
aaronfengCommented:
You are getting circular reference error because you have two projects are referencing each other right?  When I said a third project, I don't mean a user control, it's a project the keeps all your common code that both of your projects need to access.

Cheers,

Aaron
0
 
ARACK04Author Commented:
I only have one project (or website, I'm using vis web developer).  I have two user controls which each have references to each other.
0
 
aaronfengCommented:
I think we are not talking about the same thing, can you paste some code?

Cheers,

Aaron
0
 
ThogekCommented:
Elements in linked lists do not automatically contain instances of each other; if they did, they'd experience the same errors.  Such elements contain field variables of each other's types (i.e., A would contain a field variable of type B), which can then be set by outside code sometime after instantiation.

I agree with aaronfeng that there appears to be some terminology confusion here, and that some sample code would be extremely illustrative...
0
 
gregoryyoungCommented:
I think he is trying to say that he has ...

a web user control A that references a web user control B

i.e. in A

<%@ Register TagPrefix="uc1" TagName="B" Src="B.ascx" %>
then
<uc1:B id="B1" runat="server">

and then in B

<%@ Register TagPrefix="uc1" TagName="A" Src="A.ascx" %>
then
<uc1:A id="A1" runat="server">

Which if allowed would cause infinite recursion if you tried to load either control. This is as such not allowed. You need to better abstract your controls by making a 3rd control (or even a fourth control) that contains the shared behaviors.

Cheers,

Greg Young
http://geekswithblogs.net/gyoung
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now