As easy as it may be, the extensive use of the alert() status message though out a website calls for a unified and simple implementation in order to avoid duplicate code – a centralized method.
Such a thing doesn’t exist so we have to create it our selves.
I’ve written a static class called Alert with one public method called Show. The implementation is as simple as can be. Just put the .cs file in the App_Code folder on your website and you instantly have access to the method from all pages and user controls.
/// <param name="message">The message to appear in the alert.</param>
publicstaticvoid Show(string message)
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\\'");
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page !=null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
void btnSave_Click(object sender, EventArgs e)
Alert.Show("You document has been saved");
Alert.Show("You do not have write permission to this file");