Why can't i put two controls in the same directory*?

G

Gregory A. Beamer

According to the link below, it's not allowed to
place two user controls in the same directory if
one of the controls will contain the other.

http://msdn.microsoft.com/en- us/library/system.web.configuration.tagpre
fixinfo.aspx

While i see it is true, i can't find much info
explaining WHY it is so. My guesses are:
- performance issues
Unlikely

- bad design

Possibly, but only by proxy
- some secret reason
- miscellaneous stuff

(see below for above 2)

I have not experimented with it to confirm what I believe, but I think
it has more to do with prefixing the tag. When you include a control in
a control, the contained controlled is given a prefix of say "uc1".

If you put the containing control on the ASPX page, it should recieve
"uc2" so as not to confuse the JIT compiler.

If I am correct, putting both in the same directory can end up with the
IDE assigning the containing control "uc1" and the contained control
will also have "uc1", confusing the JIT compiler on the site and
breaking the page.

Just a thought.

If I am correct, why has this not been solved? Most likely because there
are bigger fish to fry.

Peace and Grace,
 
P

Patrice

Hello


Do you mean ?

"When a source is specified, the user control itself must not be in the same
directory as the page. If it is, you get a run-time error when you attempt
to load the page."

To me it doesn't look they are talking about nested user controls. They are
talking about a user control and its page container (and only when the
Source attribute is used). So it seems much more specific than what you
said...

You could try and see what is the runtime error you get. It could give a
clue about what is the reason behind this (could be perhaps a compilation
issue, depending on the model the whole code in a directory is compiled but
here it could perhaps cause an issue regarding the compilation order i.e.
the control needs to be compiled before the page).
 
K

K Viltersten

Do you mean ?
"When a source is specified, the user control
itself must not be in the same directory as
the page. If it is, you get a run-time error
when you attempt to load the page."

To me it doesn't look they are talking about
nested user controls. They are talking about
a user control and its page container (and
only when the Source attribute is used). So
it seems much more specific than what you
said...

You could try and see what is the runtime error
you get. It could give a clue about what is the
reason behind this (could be perhaps a compilation
issue, depending on the model the whole code in a
directory is compiled but here it could perhaps
cause an issue regarding the compilation order i.e.
the control needs to be compiled before the page).

Hmmm... I'm rather convienced that i was specific
enough. If you place a user control in an other
user control, you'll get an exception during run-time
given that the source for both is in the same
directory.

It can be resolved by re-registering the inner
control but i was wondering WHY it was that way.
 
K

K Viltersten

While i see it is true, i can't find much info
Possibly, but only by proxy


(see below for above 2)

...I think it has more to do with prefixing the
tag. When you include a control in a control,
the contained controlled is given a prefix of
say "uc1". If you put the containing control on
the ASPX page, it should recieve "uc2" so as
not to confuse the JIT compiler.

If I am correct, putting both in the same
directory can end up with the IDE assigning the
containing control "uc1" and the contained
control will also have "uc1", confusing the JIT
compiler on the site and breaking the page.

My collegaue provided me with the work-around,
re-registering the control directly in the
affected document. It works but is ugly. I guess,
by using different tagPrefix's, we can avoid the
problem you've discussed.
If I am correct, why has this not been solved?
Most likely because there are bigger fish to fry.

I'm leaning towards the same explaination. Thanks.
 
P

Patrice

And the error is ?

IMO it could be that depending on the compilation model the source code
contains in the whole directory is compiled in multiple assemblies (for
example we could have an assembly per page/control AFAIK). It could perhaps
cause a problem when a page or a control references another control as the
later should be then compiled before...

If the source points to another directory then the compiler knows that what
is in this other directory should be compiled first (and if it points to the
same directory then you are caugth in a circle)...
 
K

K Viltersten

And the error is?

Something about the control being declared
in web.config and living in the same area
or directory as the containing control.
IMO it could be that depending on the
compilation model the source code
contains in the whole directory is
compiled in multiple assemblies (for
example we could have an assembly per
page/control AFAIK). It could perhaps
cause a problem when a page or a control
references another control as the later
should be then compiled before...

Don't know. It sounds a bit vague and
speculative to me. However, i don't have
any great suggestions myself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top