Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

using user control in form & using design time question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TS - 09 Feb 2005 16:01 GMT
Im used to using web forms and adding user control info at design time in
html. The example i have for a win form is that the user control must be
compiled then you add it to the toolbox then add it to the form to put it
on.

How do i add the control without having to compile it first and also access
its properties/methods at design time?

thank you
TS - 09 Feb 2005 17:24 GMT
If the solution is you have to build the user control, then every time you
want to make a change you have to open up the project containing the control
& rebuild it, etc? Seems very cumbersome. It seems that it is much easier
using controls for web forms

> Im used to using web forms and adding user control info at design time in
> html. The example i have for a win form is that the user control must be
[quoted text clipped - 5 lines]
>
> thank you
TS - 09 Feb 2005 18:07 GMT
my question still exists for user controls in one project, but I don't think
this is a big problem with user controls that are going to be used in other
projects within my solution.

What is better if i make a project in my solution for the user controls:
Have a separate project for each user control, or a project that has all my
user controls in it and it builds all of them at the same time.

The only reason i would say to separate them out is that some projects may
want to use only one control and if theres 30 controls, it would add a small
data size increase for the project for the controls that aren't used.

I would probably go with the single project though.

thanks

> If the solution is you have to build the user control, then every time you
> want to make a change you have to open up the project containing the control
[quoted text clipped - 11 lines]
> >
> > thank you
"Jeffrey Tan[MSFT]" - 10 Feb 2005 02:49 GMT
Hi TS,

Thanks for your posting!!

For your original issue, I think you must change your usercontrol's server
side code in the .aspx file, not the code behind file, yes? Actually, in
webform, the .aspx file will be complied at run-time, and when compiling
the webform project, the compiler will not verify the C# code in .aspx
file, so when VS.net compiles the webform project, compiler will not know
if the used properties/methods in the .aspx exists in UserControl class.
However, when the web application is going to run, the Asp.net runtime will
dynamically parse .aspx page, generate a temp assembly for the entire
webform project, at this time, the asp.net runtime will COMPILE the .aspx
page and verify the C# code, and now the .aspx will associate with the
usercontrol code.

For winform application, the entire project will compile at once, without 2
times. But I am not sure what your meaning of "access its
properties/methods at design time", do you mean the intellisense support in
VS.net IDE for the usercontrol new added members? Actually, I think if we
have a usercontrol for a form, then we added a new "Test" public field to
the usercontrol, then explicitly use this field in the Form class without
compile the project, then we explicitly pressed ctrl+F5, the VS.net will
first re-compile the entire project, and the code can be used without any
problem. But there is no intellisense for "Test" property in the Form
class, because the Winform application is not compiled, and not metadata is
emitted into the assembly, so there is not metadata information for VS.net
to know this change and display the "Test" property in the intellisense
dropdownlist.

For the later issue, I agree with you that whether to place several
usercontrols in single project or separate project is determined by several
assemblies or a single assembly. Also, there is an extra little difference,
that is the "internal" key word in C#, please refer this extra information
in MSDN.

Hope this helps
======================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

TS - 10 Feb 2005 21:50 GMT
if i have the user control as a dll and add it to the toolbox, when i update
the dll, i delete it from the toolbox, then add it back, but it is still the
old version. What do i have to do to get the new version as the one that is
dragged from the toolbox

> Hi TS,
>
[quoted text clipped - 43 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 11 Feb 2005 03:09 GMT
Hi TS,

Thanks for your feedback!!

I am not totally agree with your statement. Let's us do some test:

1. Create a Winform application. Then add another Windows Control library
in the same solution with the winform application.
2. In the control project, add the following public field:
public string testprop;
3. Right click control project in "Solution Explorer", choose "rebuild"
option to build the control project.
4. In Winform application, add the usercontrol to the toolbox and drop it
to the form designer.
5. In Form_Load event, you can see this.userControl11.testprop field
without any problem, the intellisense will reflect this public field.

6. Now, we add a new public field to the control:
public string anotherprop;
7. Repeat the #3 step to rebuild the control project.
8. In winform application form, there is no need to remove the control from
toolbox, in the Form_Load event, we can now see that new added public field
"this.userControl11.anotherprop" without any problem. Because VS.net will
automatically detect the change to the control assembly, and automatically
use reflection to query the metadata of the control assembly and show out
the intellisense of the control class.

However, if the 2 projects are not in the same solution. If we repeat the
above steps, the situation is different, because VS.net IDE can not detect
another project and assembly's changes in another IDE instance. If we
modified the control project and re-build the project, we MUST remove the
original control from the toolbox and form designer in winform application.
Then re-add it into the form designer from the rebuilded assembly and at
last, rebuild the "winform applicaiton" again to reflect the changes. Then
the intellisense should work for you.

Hope this helps.
=================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

TS - 11 Feb 2005 15:30 GMT
thanks

> Hi TS,
>
[quoted text clipped - 43 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 14 Feb 2005 01:40 GMT
You are welcome!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.