private string GetInlineScript(eOutputMode outputMode, string key, string message, string title) { // -------------------------------------------------- // 這是錯誤的,應該要等待所有Script載入完成才執行。(Sys.Application.add_load) // -------------------------------------------------- //StringBuilder scripts = new StringBuilder(); //scripts.Append("<script type='text/javascript'>"); //scripts.Append(GetAlertScript(message, title)); //scripts.Append("</script>"); //return scripts.ToString(); StringBuilder scripts = new StringBuilder(); string funcName = key; scripts.Append("Sys.Application.add_load(" + funcName + ");"); scripts.Append("function " + funcName + "(){"); scripts.Append(GetAlertScript(outputMode, message, title)); scripts.Append("Sys.Application.remove_load(" + funcName + ");"); scripts.Append("}"); return scripts.ToString(); }
private void Output(eOutputMode outputMode, string text, string caption) { string key = GetScriptKey(); string script = GetInlineScript(outputMode, key, text, caption); RegisterStartupScript(CurPage, key, script); }
private string GetAlertScript(eOutputMode outputMode, string message, string title) { string funcName = string.Empty; switch (outputMode) { case eOutputMode.Error: { funcName = "jError"; } break; case eOutputMode.Info: { funcName = "jAlert"; } break; } message = message.Replace("'", ""); title = title.Replace("'", ""); string script = string.Format("{0}('{1}', '{2}');", funcName, message, title); return script; }