Problem with UserControl

A

Abhishek

Hi,

We are facing problem with usercontrol in windows application. We have a
usercontrol that is placed on a window form. User control contains some code
that interact with the oracle database on Load event. But it seems like the
code contained inside the usercontrol load event is executed, whenever the
window form is opened into the design mode. We found that it is a known issue
as discussed in below link.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1527615&SiteID=1

But we haven't find any verified resolution of this problem. Please help us
to resolve this issue. It would be keen help if we get any suggestion or
hotfix of this problem.

Thanks,
Abhishek
 
C

Cowboy \(Gregory A. Beamer\)

Design your controls as a black box.

Make sure you feed it info on the data it has to gather and when that feed
information is missing (in Design, for example), do not load real data. One
easy way to do this, in code, is to create both a default constructor and
one that is fed a value from the loading application. If the default
constructor is hit, the LoadData() method is never called from the _Load
event.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
P

PvdG42

Abhishek said:
Hi,

We are facing problem with usercontrol in windows application. We have a
usercontrol that is placed on a window form. User control contains some
code
that interact with the oracle database on Load event. But it seems like
the
code contained inside the usercontrol load event is executed, whenever the
window form is opened into the design mode. We found that it is a known
issue
as discussed in below link.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1527615&SiteID=1

But we haven't find any verified resolution of this problem. Please help
us
to resolve this issue. It would be keen help if we get any suggestion or
hotfix of this problem.

Thanks,
Abhishek

I'm not sure why you think this is a problem, except within your control.
The fact that controls are in run mode while the form, itself, is in design
mode is by design of the IDE. All controls act this way, and have since long
before .NET. You need to redesign your control to not execute the connection
code until the form on which the control resides is activated.
Looking at your cited thread, I see several workarounds offered. Did none of
these work for you?
 
A

Abhishek

Thanks for your help.

It means, whether it is usercontrol or inbuild controls all the controls are
in run mode. When we open a form that contain these controls in design mode,
it executes InitializeComponent method, under this method design time
properties of these controls are intialized and all controls _Load event is
initiated when they are added into the container, for them it is Form self
"Me.Controls.Add(MyControl)".

Yes, there are few methods are available but my only concern was which one
is best to use. Basically, we have to migrate code from 2003 to 2005.

Regards,
Abhishek
 
A

Abhishek

Thanks Gregory,


Cowboy (Gregory A. Beamer) said:
Design your controls as a black box.

Make sure you feed it info on the data it has to gather and when that feed
information is missing (in Design, for example), do not load real data. One
easy way to do this, in code, is to create both a default constructor and
one that is fed a value from the loading application. If the default
constructor is hit, the LoadData() method is never called from the _Load
event.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
A

Alex Taylor

Hi!

I'm not a heavy .Net programmer (I use Delphi), but in Delphi there is a
csDesigning constant that can determine the control's state.

This code in the Constructor (or any EventHandler)

If csDesigning in ComponentState then ...
Else ...

perfectly separates the two behaviour. What is the situation in .Net?
Does it supports a technique like the above?!
 
A

Alvin Bruney [ASP.NET MVP]

I think (not sure) the property is called DesignMode

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
 

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