"Losing" Controls on User Controls

G

Guest

Hi,

I have been developing with C# User Controls and occasionally have a problem
where I "lose" a control from the design surface of the User Control. The
controls that I am using to build my User Controls are themselves custom
controls.

Occasionally, when I change something in either the User Control and/or one
of the custom controls that are on it and recompile, when I go to the
"Visual" design surface of the User Control, the custom control that used to
be on it is no longer there. But if you look at the code for the User
Control, the custom control object is still declared, and any references to
it in code are still there. But apparently it's no longer added to the User
Control in code.

I have a workaround...
1) Remove declaration of the "lost" object from the User Control code.
2) Go into the toolbox and get the custom control and put it back on the
User Control
3) Set any custom control properties that were set before, and re-register
for custom control events (because the eventhandler methods are still there
all I have to do is select the right one thank goodness)

Still, this is an ENORMOUS PAIN IN THE BUTT when it happens. Can somebody
tell me how to avoid this situation (Please don't say don't use custom
controls on User Controls).

Thanks.

BBM
 
C

Champika Nirosh

Hi,

One guess.. are you sure that you don't edit the Initializer method of the
form or the user control manually??? if you do so that may cause the error
since you are not allow to do so but If you don't.. this is some what
strange and again i don't see a reason to say not to use custom control on
another user control it cannot be the error..

Nirosh.
 
M

mdb

=?Utf-8?B?QkJN?= said:
Occasionally, when I change something in either the User Control
and/or one of the custom controls that are on it and recompile, when I
go to the "Visual" design surface of the User Control, the custom
control that used to be on it is no longer there. But if you look at
the code for the User Control, the custom control object is still
declared, and any references to it in code are still there. But
apparently it's no longer added to the User Control in code.

Yeah this seems to be a problem in the design of VS.net - lots of other
people have seen similar behavior. I have noticed that it only happens
AFTER a compile (or more precisely, when the DLL has changed and thus
needs to be reloaded and the controls re-rendered to include any
changes), when you switch to the designer for that page. In other
words, if you have the designer and the code view open, and you are
looking at the code view when you compile, it MIGHT happen (and will
ONLY happen) when you switch to the design view.

What that means for me (and you, if you want to adopt this method) is
that when it happens, just exit the VS.net environment and restart it.
Everything should come back just the way it was, as long as you have
VS.net configured to automatically save the files before a compile (is
that even an option? i can't remember.) I have a fairly large and
complex project that I use this method on and its not too bad - as long
as you notice when it happens.

Obviously, this is still a pain-in-the-butt... but not as much as
having to reset the properties of the control.

The other thing that I do is that I've stopped setting the properties
that I want to change in the designer. Instead, I set them manually in
the Form_Load.

One more thing that might help but which I can't confirm (it seemed to
help for a while but then I found instances where it didn't help) is to
make sure that things like enums are defined at the namespace level, and
not inside of classes. I know it doesn't make any sense, and like I
said I've found instances where I still lost my controls, but it sure
seemed to alleviate the problem for a time.

And finally, keep the number of VS.net tabs (especially designers) that
you have open to a minimum. I personally think it has something to do
with VS.net not performing things in the right order, or not waiting for
A to finish before it tries to do B. Keeping the number of tabs open
seems to help for me - that is, it reduces how often the problem occurs.

-mdb
 
L

Lateralus [MCAD]

I've run into this problem when designing winforms. All of my "usercontrols"
are in a seperate assembly. If I have a form open in design view, and I'm
editing a usercontrol, then attempt to compile the usercontrol and it fails,
the control is removed from the form, but is still declared. Essentially my
workaround is to "NEVER" have a form open in design view that is using a
usercontrol when I'm making changes to my usercontrols. This works for me.
 
K

Kevin Yu [MSFT]

Hi BBM,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you are developing a Microsoft
Windows Forms application in Microsoft Visual Studio .NET 2003, instances
of custom user controls or of derived Windows Forms controls may disappear
from the Windows Forms Designer. If there is any misunderstanding, please
feel free to let me know.

Based on my research, this is a known issue. Here is a KB article which
talk about this issue and provides a fix.

http://support.microsoft.com/default.aspx?scid=KB;EN-US;842706

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

Your reference didn't exactly address my problem, but I've gotten enough
responses from others to know that I'm not imagining this, and I have some
suggestions on how to avoid it. Do you know if this was fixed in VS.Net 2005?
 
K

Kevin Yu [MSFT]

Hi BBM,

As a support engineer, I'm not quite sure whether there will be fixes in
VS.NET 2005. However, you can send mails directly to (e-mail address removed)
to report your ideas and your wishes. Your suggestions will be highly
appreciated.

Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Hi Kevin,

It seems that the solution you refer to is the one I need for my problems
with user controls. On every change in my user control (which is in the same
solution as the Forms project I use the control on), the control will
disappear from my form. This is a very anoying problem, which I really want
to get solved. Now I've tried to contact the dutch MSDN support service by
telephone, but do not seem to be able to help me out with this problem. So,
my question is, can you help me out here? What I want is to get the fix for
the problem described in this article
(http://support.microsoft.com/default.aspx?scid=KB;EN-US;842706). I've got an
MSDN license from which I've installed the Visual Studio .NET 2003 Enterprise
Architect, but don't understand why I cann't get to the solution of my
problem....

Thanks,
Christ
 
K

Kevin Yu [MSFT]

Hi Christ,

I'm not quite sure why Dutch MSDN support didn't give you the hotfix. Could
you try Microsoft PSS in other contries? For example United State?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

Is the only way in which MSDN Subcribers can receive these "hot fixes"
calling MSDN Support and using up one of our technical issue "incedents"?
 
K

Kevin Yu [MSFT]

Hi,

Calling Microsoft PSS for hotfix is free of charge which will not use up
one of your incidents.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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

Top