I was wondering how to go about calling a VOID method; located in my Default code behind, from a web user control?
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.
The problem is that I've tried keeping it in the Default's public partial class
and I've attempted to create a separate class but I cant figure out how to call it when I need to use it.
The class from within Default.aspx.cs:
// 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;
}
}
The statement within a user control that needs to use the method:
// 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.");
}
I would think calling the method like this from within the user control:
Namespace.Default.AddStatusMessage("error", "You must confirm the provider before proceeding.");
..but this does not seem to work.
Update 3/24: 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 Unknown method 'AddStatusMessage()' of Default. It's as if the new instance does not recognize my original method within the Default page class.
public static void PublicStatusMessage()
{
Default Status = new Default().AddStatusMessage();
Status.AddStatusMessage();
}