Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. call a method on a parent form

call a method on a parent form

Scheduled Pinned Locked Moved C#
questionhardware
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sled Dog
    wrote on last edited by
    #1

    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

    R M 2 Replies Last reply
    0
    • S Sled Dog

      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

      R Offline
      R Offline
      Rick Beideman
      wrote on last edited by
      #2

      Raise a message in the control that the parent form handles.

      1 Reply Last reply
      0
      • S Sled Dog

        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

        M Offline
        M Offline
        MoustafaS
        wrote on last edited by
        #3

        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 ?

        S 1 Reply Last reply
        0
        • M MoustafaS

          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 ?

          S Offline
          S Offline
          Sled Dog
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups