title: How to call a method from user control to aspx page?
body: <p>I want to call a method from user control to aspx page</p>
  
  <p>I'm trying but I am not able to call that method in aspx page</p>
  
  <p>Code:</p>
  
  <p>AddVisaUserControl.ascx.cs</p>
  
  <pre><code>public event EventHandler UserControlButtonClicked;
  
      public void OnUserControlButtonClick()
      {
          if (UserControlButtonClicked != null)
          {
              UserControlButtonClicked(this,EventArgs.Empty);
          }
      }
  
  protected void btnRemove_Click(object sender, EventArgs e)
      {
          OnUserControlButtonClick();
      }
  </code></pre>
  
  <p>.aspx</p>
  
  <p><strong>Edit</strong></p>
  
  <p>In the below code when the page load I am getting "null reference error"</p>
  
  <pre><code>AddVisaControl av; 
  protected void Page_Load(object sender, EventArgs e)
      {
          av.UserControlButtonClicked  += new
                  EventHandler(AddVisaUserControl_UserControlButtonClicked);
      } 
  
    private void AddVisaControl_UserControlButtonClicked(object sender, EventArgs e)
      {
          var ctrl = (AddVisaControl)LoadControl(@"AddVisaControl.ascx");
          //ctrl.ID = i;
          this.rpt1.Controls.Remove(ctrl);
      }
  </code></pre>
  
  <p>Any ideas? Thanks in advance</p>