/// <summary>
/// 支援Page與UpdatePanel 的alert message
/// </summary>
/// <param name="infomation"></param>
/// <param name="control"></param>
public static void Show(string infomation, Control control)
{
bool isPage = (control is Page);
bool isUpdatePanel = (control is UpdatePanel);
if (!isPage && !isUpdatePanel)
{
throw new ArgumentException("訊息只能輸出到Page或者UpdatePanel中");
}
bool addScriptTags = true;
string script = string.Format("window.alert('{0}');", infomation);
string key = string.Format("WebMessageBox{0}", DateTime.Now.ToString());
Type registerType = typeof(WebMessageBox);
if (isPage)
{
Page page = control as Page;
page.ClientScript.RegisterClientScriptBlock(registerType, key, script, addScriptTags);
}
if (isUpdatePanel)
{
UpdatePanel updatePanel = control as UpdatePanel;
ScriptManager.RegisterClientScriptBlock(updatePanel, registerType, key, script, addScriptTags);
}
}
留言列表