title: Can I call a public void method that is located in another class?
body: <p>I was wondering how to go about calling a VOID method; located in my Default code behind, from a web user control?</p>
  
  <p>The control contains a statement that needs to use the method that I have declared in my Default page code behind. I would just declare the method in the control's code behind but the method will be used multiple times so ideally, I would like to keep it in either the Default code behind or even put it in a class. </p>
  
  <p>The problem is that I've tried keeping it in the Default's <code>public partial class</code> and I've attempted to create a separate class but I cant figure out how to call it when I need to use it. </p>
  
  <p><strong>The class from within Default.aspx.cs:</strong></p>
  
  <pre><code>// This method adds a string to the status output area
  public void AddStatusMessage(string type, string message)
  {
      if (message == string.Empty || type == string.Empty) { return; }
  
      if (type == "success")
      {
          successMessageList.Add("SUCCESS: " + message);
          Session["SuccessMessageList"] = successMessageList;
      }
      else if (type == "error")
      {
          errorMessageList.Add(message);
          Session["ErrorMessageList"] = errorMessageList;
      }
  }
  </code></pre>
  
  <p><strong>The statement within a user control that needs to use the method:</strong></p>
  
  <pre><code>// did the user enter a provider code but not check the confirmation box?
  if (!ConfirmProviderCheckbox.Checked)
  {
      failed = true;
      AddStatusMessage("error", "You must confirm the provider before proceeding.");
  }
  </code></pre>
  
  <p><strong>I would think calling the method like this from within the user control:</strong></p>
  
  <pre><code>Namespace.Default.AddStatusMessage("error", "You must confirm the provider before proceeding.");
  </code></pre>
  
  <p>..but this does not seem to work.</p>
  
  <p><strong>Update 3/24:</strong>
  Well, I've tired to create an instance of that class within the static method to allow me to call it from my user control but I get <em>Unknown method 'AddStatusMessage()' of Default</em>. It's as if the new instance does not recognize my original method within the Default page class.</p>
  
  <pre><code>public static void PublicStatusMessage()
  {
      Default Status = new Default().AddStatusMessage();
      Status.AddStatusMessage();
  }
  </code></pre>