call a method on a parent form
-
Members, I have a user control embedded on a single form. The form has a pubic method that I created. I want this child control to notify the parent page when new data is entered in to a text field on the user control. I want to keep the user control responsible for only the information that it is gathering. However, I want this parent page notified when new records are created. How do I pass the record id as a string from the embedded control to the public function on the parent page? Thanks for the thought... SD
-
Members, I have a user control embedded on a single form. The form has a pubic method that I created. I want this child control to notify the parent page when new data is entered in to a text field on the user control. I want to keep the user control responsible for only the information that it is gathering. However, I want this parent page notified when new records are created. How do I pass the record id as a string from the embedded control to the public function on the parent page? Thanks for the thought... SD
Raise a message in the control that the parent form handles.
-
Members, I have a user control embedded on a single form. The form has a pubic method that I created. I want this child control to notify the parent page when new data is entered in to a text field on the user control. I want to keep the user control responsible for only the information that it is gathering. However, I want this parent page notified when new records are created. How do I pass the record id as a string from the embedded control to the public function on the parent page? Thanks for the thought... SD
You may ( for further use ) create an event on the usercontrol itself which may be
this_DataChanged
and it tracks all the changes that may have been done , and then in every parent you add this control in you just handle it. ex:////UserControl public class MyControl : UserControl { public MyControl() { } public event EventHandler DataAdded; ////All the properties that you want to track must be like this. public DataType PropertyName { get { return dataField; } set { this.dataField = value; this.OnDataAdded(); } } ////And this is the method taht will fire the event. private void OnDataAdded(object sender, EventArgs e) { if (this.DataAdded != null) { this.DataAdded(this.DataAdded, e); } } } ////ParentForm public class MyForm : Form { ////Regular Methods and Fields. ////In the Init Method : this.MyInheritedUserControl.DataAdded+=new EventHandler(this.MyEventHandler); }
hope this helps.
"I am a liar." Is this statement true or false ?
-
You may ( for further use ) create an event on the usercontrol itself which may be
this_DataChanged
and it tracks all the changes that may have been done , and then in every parent you add this control in you just handle it. ex:////UserControl public class MyControl : UserControl { public MyControl() { } public event EventHandler DataAdded; ////All the properties that you want to track must be like this. public DataType PropertyName { get { return dataField; } set { this.dataField = value; this.OnDataAdded(); } } ////And this is the method taht will fire the event. private void OnDataAdded(object sender, EventArgs e) { if (this.DataAdded != null) { this.DataAdded(this.DataAdded, e); } } } ////ParentForm public class MyForm : Form { ////Regular Methods and Fields. ////In the Init Method : this.MyInheritedUserControl.DataAdded+=new EventHandler(this.MyEventHandler); }
hope this helps.
"I am a liar." Is this statement true or false ?
LongHC, Thank you very much for the solution. Per you comment, it depends...In the land of Knights and Knaves, where Knights always tell the truth and Knaves always lie, you could not be a Knight and a Knave would never offer the truth--therefore, you must be a Paradox. William