Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 7th, 2004, 08:53 AM
Friend of Wrox
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing parent control functions from child

VB.NET app question

I have created myself a simple user control ( consisting of a few
edit boxes etc ). I use this user control on several different
forms within my application. I simply create instances of my
user control and assign them as children of my various parent

My question - what is the best way to call a user defined
function/sub in the parent form from my child user control ?

I do not always need to do this - it depends on the type of
parent form in which I have embedded my child control. But sometimes
I need to tell my parent form that there has been a status
change within its child control.

Any ideas on best practice?
Old January 7th, 2004, 11:54 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Instead of thinking of this as "How do I call a method in my parent?" think of it as "How do I TELL my parent something happened?".

The child control should offer an event for the status change you speak of. Create a public event in the control and then the containing parent form (or control) can handle that event as it wants (or not at all). This way, if the control is on a form/control that doesn't care about that event, the child control won't break because instead of calling a function that doesn't exist, it's just raising the event.

This technique follows the event driven model that all the .net controls follow.

Work smarter, not harder.
Old January 9th, 2004, 07:49 AM
Friend of Wrox
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Peter - I understand the event raising/handling now.

Similar Threads
Thread Thread Starter Forum Replies Last Post
parent child connect s2mo SQL Server 2005 1 February 20th, 2007 07:16 AM
Accessing a element of parent window in child wind livehed BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 June 28th, 2005 10:26 AM
Parent - Child Combo babloo81 BOOK: Professional Jakarta Struts 0 April 27th, 2005 01:54 PM
Parent - Child Combo babloo81 JSP Basics 0 April 27th, 2005 01:46 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.