473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to call method in parent?

Hi

I'm trying to call a method in a parent control from the child control but
I get this error:

'System.Windows.Forms.Control' does not contain a definition for 'doSomething'

What am I doing wrong?
public partial class ParentControl : UserControl
{
private ChildControl childControl;

public ParentControl()
{
InitializeComponent();

childControl = new ChildControl();
childControl.Width = 32;
childControl.Height = 32;
childControl.Location = new Point(10, 10);
childControl.Parent = this;
Controls.Add(childControl);
}

public void doSomething()
{
...
}
}

---

public partial class ChildControl : UserControl
{
private void ChildControl_Click(object sender, EventArgs e)
{
this.Parent.doSomething();
}
}
Jun 22 '07 #1
3 2583
((ParentControl)Parent).doSomething();

Jun 22 '07 #2
Hello not_a_commie,
((ParentControl)Parent).doSomething();
Changes the error to:

'Project.ParentControl' does not contain a definition for 'doSomething'
Jun 22 '07 #3
Hello not_a_commie,
((ParentControl)Parent).doSomething();
Nevermind my previous reply. I made a typo. It worked, thanks!
Jun 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lkrubner | last post by:
My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed(); $this->arrayOfAllTheObjectsSoFarLoaded = &...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
4
by: ad | last post by:
base only can call the parent 's method The result of the example below is I am Parent I am Child How can we call the grandparent's method in a inhreited class, I want the result is I am...
13
by: Jason Shohet | last post by:
I have an ascx control, and it needs a value called 'orgID' which the parent page will have. I want to avoid the parent page setting values in fields on the ascx control since this violates...
2
by: jw56578 | last post by:
Is it possible to call a method from a parent object, but have the childs overriden method called instead of the base method? I want several children objects to all call a certain method when they...
2
by: engwar1 | last post by:
I have a page that my users will go to to upload files to my website. As I want to reuse the file upload code on multiple pages I put the file upload textbox/buttons on a user control which I plan...
1
by: Eric | last post by:
I want to call a method on the MDI parent from the child. Basically the method will set some text (message) on a status strip and show the appropriate icon (for the type of message). I'd also...
2
by: Jack | last post by:
Hello, I have a 3-level class hirarchy: 1=Grandparent 2=Parent 3=Child The Grandparent has a method called OnPaint which I want to override from the Child class. I can do this, but how...
6
by: howa | last post by:
Consider example: Animal = function(age) { this.age = age; }; Animal.prototype.sleep = function() { alert("Animal Sleeping..."); };
29
Frinavale
by: Frinavale | last post by:
I have 2 FireFox (version 2) browser windows opened. One is the child of the other. When the user is finished with the child window, a method in the parent window is called to refresh a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.