title: OnChange Events for Dynamically rendered User Controls in ASP.NET
body: <p>I have a set of User controls shown in a Page (ABC.aspx) in 5 to 6 tabs. Each of the User control has many Textboxes, Drop Downs etc.. I need to detect any user changes on any of the fields in those user controls and do some processing on Parent page (ABC.aspx) on which these user controls reside.</p>
  
  <p>The User Controls are implemented as follows.
  There is an XMl file for each of User controls which is read and creates controls accordingly.</p>
  
  <p>The render method in ascx.cs reads this xml file and renders the UI Acordingly for that User Control.</p>
  
  <p>Lets say that sample XMl for a User control is </p>
  
  <pre><code> &lt;uigroup groupname ="Schematic(Logical) Symbol Request"&gt;
  &lt;uirow&gt;
    &lt;uicontrol displayname="Request Type" datatype="DropDown" isrequired="false" domainname="RequestType" dropdownEventHandler="OnScenarioChange(this)" key="Schematic Scenario" defaultValue="New"&gt;&lt;/uicontrol&gt;
  &lt;/uirow&gt;
  &lt;uirow&gt;
    &lt;uicontrol displayname="Logical Name" datatype="TextBox" isrequired="false" supportedscenarios="New,Use Existing,Update Existing" key="Schematic Symbol Name"&gt;&lt;/uicontrol&gt;
    &lt;uicontrol displayname="Similar Symbol" datatype="TextBox" isrequired="false" supportedscenarios="New" key="Similar Schematic Symbol"&gt;&lt;/uicontrol&gt;
  &lt;/uirow&gt;
  &lt;uirow&gt;
    &lt;uicontrol displayname="Type of Change" datatype="DropDown" isrequired="false" domainname="Type of Schematic Change" supportedscenarios="Update Existing" key="Type of Schematic Change"&gt;&lt;/uicontrol&gt;
    &lt;uicontrol displayname="Layout Preference" datatype="DropDown" isrequired="false" domainname="Schematic Layout Preference" supportedscenarios="New,Update Existing" key="Schematic Layout Preference"&gt;&lt;/uicontrol&gt;
  &lt;/uirow&gt;
  &lt;uirow&gt;
    &lt;uicontrol displayname="Justification" datatype="DropDown" isrequired="false" domainname="Schematic Justification" supportedscenarios="Update Existing" key="Schematic Justification"&gt;&lt;/uicontrol&gt;
    &lt;uicontrol displayname="Logical Directory" datatype="DropDown" isrequired="false"   domainname="ICL Logical Directory" supportedscenarios="New" key="ICL Logical Directory"&gt;&lt;/uicontrol&gt;
  &lt;/uirow&gt;
  </code></pre>
  
  <p></p>
  
  <p>Usercontrol.ascx.cs has </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
      }
  
  
      protected void Page_Init(object sender, EventArgs e)
      {
          this.Render();
      }
  
      public void Render()
      {
          this.Render(this.XmlPath);
      }
  </code></pre>
  
  <p>and my render function does the following</p>
  
  <pre><code>public void Render(string _filePath)
      {
  
  
          UITab tab = this.GetDataFromXML(_filePath);
          foreach (UIGroup g in tab.Groups)
          {
              //Add a panel
              Panel groupPanel = this.AddPanel(g);
              foreach (UIRow r in g.Rows)
              {
                  Table table = new Table();
                  groupPanel.Controls.Add(table);
  
                  TableRow tableRow = new TableRow();
                  table.Rows.Add(tableRow);
  
                  foreach (UIControl c in r.Controls)
                  {
                      switch (c.DataType)
                      {
                          case UIDataType.Textbox:
                              this.AddTextBox(groupPanel, c, tableRow);
                              break;
                          case UIDataType.Dropdown:
                              this.AddDropdown(groupPanel, c, tableRow);
                              break;
                          case UIDataType.LabelInfo:
                              this.AddLabelInfo(groupPanel, c,tableRow);
                              break;
                          case UIDataType.Label:
                              this.AddLabel(groupPanel, c,tableRow);
                              break;
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>We are rendering other user controls similar way. we need to find a way to detect user changes on any of these user controls (like a text box changed or dropdown changed etc..) and do process the Parent page.</p>
  
  <p>I am not sure if Delegates and Events might be a good fit and if yes, how would they fit in this architecture are my biggest questions here. Any constructive inputs would really help.</p>
  
  <p>Thanks,</p>