"Losing" Controls on User Controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BBM

    "Losing" Controls on User Controls

    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
  • Champika Nirosh

    #2
    Re: "Losing&qu ot; Controls on User Controls

    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.

    "BBM" <bbm@bbmcompany .com> wrote in message
    news:13E0EA62-705A-421F-AD27-E9095E16A8ED@mi crosoft.com...[color=blue]
    > Hi,
    >
    > I have been developing with C# User Controls and occasionally have a[/color]
    problem[color=blue]
    > 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[/color]
    one[color=blue]
    > 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[/color]
    to[color=blue]
    > 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[/color]
    to[color=blue]
    > it in code are still there. But apparently it's no longer added to the[/color]
    User[color=blue]
    > 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[/color]
    re-register[color=blue]
    > for custom control events (because the eventhandler methods are still[/color]
    there[color=blue]
    > 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[/color]


    Comment

    • mdb

      #3
      Re: &quot;Losing&qu ot; Controls on User Controls

      =?Utf-8?B?QkJN?= <bbm@bbmcompany .com> wrote in
      news:13E0EA62-705A-421F-AD27-E9095E16A8ED@mi crosoft.com:[color=blue]
      > 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.[/color]

      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

      Comment

      • Lateralus [MCAD]

        #4
        Re: &quot;Losing&qu ot; Controls on User Controls

        I've run into this problem when designing winforms. All of my "usercontro ls"
        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.

        --
        Lateralus [MCAD]


        "BBM" <bbm@bbmcompany .com> wrote in message
        news:E4FC3D3C-366D-4DB2-A6B3-3B0891AD40EC@mi crosoft.com...[color=blue]
        > mdb,
        >
        > Thanks for a very complete and helpful response.
        >
        > I'm guilty of some of the stuff you mention: declaring enums in classes,
        > and
        > tending to have way too many tabs open in the designer.
        >
        > I like your workaround a lot better than mine too.
        >
        > Do you think anybody at Microsoft is working on this?
        >
        > Thanks for your help.
        >
        > BBM
        >
        > "mdb" wrote:
        >[color=green]
        >> =?Utf-8?B?QkJN?= <bbm@bbmcompany .com> wrote in
        >> news:13E0EA62-705A-421F-AD27-E9095E16A8ED@mi crosoft.com:[color=darkred]
        >> > 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.[/color]
        >>
        >> 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
        >>[/color][/color]


        Comment

        • Kevin Yu [MSFT]

          #5
          Re: &quot;Losing&qu ot; Controls on User Controls

          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 misunderstandin g, 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.



          HTH.

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

          Comment

          • BBM

            #6
            Re: &quot;Losing&qu ot; Controls on User Controls

            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?

            "Kevin Yu [MSFT]" wrote:
            [color=blue]
            > 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 misunderstandin g, 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...B;EN-US;842706
            >
            > HTH.
            >
            > Kevin Yu
            > =======
            > "This posting is provided "AS IS" with no warranties, and confers no
            > rights."
            >
            >[/color]

            Comment

            • Kevin Yu [MSFT]

              #7
              Re: &quot;Losing&qu ot; Controls on User Controls

              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 mswish@microsof t.com
              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."

              Comment

              • ADLIB

                #8
                Re: &quot;Losing&qu ot; Controls on User Controls

                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...;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


                "Kevin Yu [MSFT]" wrote:
                [color=blue]
                > 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 misunderstandin g, 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...B;EN-US;842706
                >
                > HTH.
                >
                > Kevin Yu
                > =======
                > "This posting is provided "AS IS" with no warranties, and confers no
                > rights."
                >
                >[/color]

                Comment

                • Kevin Yu [MSFT]

                  #9
                  Re: &quot;Losing&qu ot; Controls on User Controls

                  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."

                  Comment

                  • Travis Vandersypen

                    #10
                    Re: &quot;Losing&qu ot; Controls on User Controls

                    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" ?

                    "Kevin Yu [MSFT]" wrote:
                    [color=blue]
                    > 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."
                    >
                    >[/color]

                    Comment

                    • Kevin Yu [MSFT]

                      #11
                      Re: &quot;Losing&qu ot; Controls on User Controls

                      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."

                      Comment

                      Working...