Hi
I have below code and i want ShowMessage to be definedonce only in the project. Currently i am defining in every form
public void ShowMessage(String Title, String Text, String Type)
{
Text = Text.Replace("'", "").Replace("/", " ").Replace(";", " ").Replace(":", " ").Replace(",", " ");
Text = System.Text.RegularExpressions.Regex.Replace(Text, @"\t|\n|\r", " ");
if (Common.CommonFunction.IE(Request.Browser.Browser))
{
Common.MessageBox.Show(Text);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + Title + "', '" + Text + "','" + Type + "');", true);
}
}
Thanks
Cr BhargaviPosted Aug 20, 2024, 3:10 AM
To define
ShowMessageonly once in your project, you can either create a base class that all your forms inherit from or place the method in a utility class.Base Class Approach: Create a base class (e.g.,
BaseForm) containing theShowMessagemethod, and have all your forms inherit from this class. This way, every form can useShowMessagewithout needing to redefine it.Utility Class Approach: Place the
ShowMessagemethod in a static utility class (e.g.,MessageUtil) and call this method from any form. This allows you to keep the method in one place while making it accessible throughout your project.Please let me know if this answered your query or you need an example to make it clear, I would be happy to help with the sample code