Для использования в файле класса:
public static void SendAlert(string sMessage)
{
sMessage = "alert('" + sMessage.Replace("'", @"\'").Replace("\n", @"\n") + "');";
if (HttpContext.Current.CurrentHandler is Page)
{
Page p = (Page)HttpContext.Current.CurrentHandler;
if (ScriptManager.GetCurrent(p) != null)
{
ScriptManager.RegisterStartupScript(p, typeof(Page), "Message", sMessage, true);
}
else
{
p.ClientScript.RegisterStartupScript(typeof(Page), "Message", sMessage, true);
}
}
}
Это может быть расширено, чтобы включить другие возможные обработчики, но на данный момент я так решил проблему.