/// <summary> /// 获取显示确认对话框的客户端脚本 /// </summary> /// <param name="message">对话框消息</param> /// <param name="title">对话框标题</param> /// <param name="icon">对话框图标</param> /// <param name="okScriptstring">点击确定按钮执行的客户端脚本</param> /// <param name="cancelScript">点击取消按钮执行的客户端脚本</param> /// <param name="target">弹出对话框的目标页面</param> /// <returns>客户端脚本</returns> public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScriptstring, string cancelScript, Target target) { //string msgBoxScript = "var msgBox=Ext.MessageBox;"; //msgBoxScript += "if(parent!=window){msgBox=parent.window.Ext.MessageBox;}"; if (String.IsNullOrEmpty(title)) { title = "X.util.confirmTitle"; } else { title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>")); } message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); JsObjectBuilder ob = new JsObjectBuilder(); ob.AddProperty("title", title, true); ob.AddProperty("msg", JsHelper.GetJsStringWithScriptTag(message), true); ob.AddProperty("buttons", "Ext.MessageBox.OKCANCEL", true); ob.AddProperty("icon", String.Format("{0}", MessageBoxIconHelper.GetName(icon)), true); ob.AddProperty("fn", String.Format("function(btn){{if(btn=='cancel'){{{0}}}else{{{1}}}}}", cancelScript, okScriptstring), true); string targetName = "window"; if (target != Target.Self) { targetName = TargetHelper.GetScriptName(target); } return(String.Format("{0}.Ext.MessageBox.show({1});", targetName, ob.ToString())); }
/// <summary> /// 获取显示对话框的客户端脚本 /// </summary> /// <returns>客户端脚本</returns> public string GetShowReference() { string message = ""; string title = ""; if (!String.IsNullOrEmpty(Message)) { message = Message; } if (!String.IsNullOrEmpty(Title)) { title = Title; } JsObjectBuilder jsOB = new JsObjectBuilder(); if (!String.IsNullOrEmpty(CancelScript)) { jsOB.AddProperty("cancel", CancelScript); } if (!String.IsNullOrEmpty(OkScript)) { jsOB.AddProperty("ok", OkScript); } if (Target != Target.Self) { jsOB.AddProperty("target", TargetHelper.GetName(Target)); } if (MessageBoxIcon != MessageBoxIcon.Warning) { jsOB.AddProperty("messageIcon", MessageBoxIconHelper.GetShortName(MessageBoxIcon)); } if (!String.IsNullOrEmpty(title)) { jsOB.AddProperty("title", title.Replace("\r\n", "\n").Replace("\n", "<br/>")); } if (!String.IsNullOrEmpty(message)) { jsOB.AddProperty("message", JsHelper.EnquoteWithScriptTag(message.Replace("\r\n", "\n").Replace("\n", "<br/>")), true); } return(String.Format("F.confirm({0});", jsOB.ToString())); }
/// <summary> /// 获取显示对话框的客户端脚本 /// </summary> /// <returns>客户端脚本</returns> public string GetShowReference() { string message = ""; string title = ""; if (!String.IsNullOrEmpty(Message)) { message = Message; } if (!String.IsNullOrEmpty(Title)) { title = Title; } JsObjectBuilder jsOB = new JsObjectBuilder(); if (Target != Target.Self) { jsOB.AddProperty("target", TargetHelper.GetName(Target)); } if (NotifyIcon != NotifyIcon.Info) { jsOB.AddProperty("notifyIcon", NotifyIconHelper.GetName(NotifyIcon)); } if (!String.IsNullOrEmpty(title)) { jsOB.AddProperty("title", title.Replace("\r\n", "\n").Replace("\n", "<br/>")); } if (!String.IsNullOrEmpty(message)) { jsOB.AddProperty("message", JsHelper.EnquoteWithScriptTag(message.Replace("\r\n", "\n").Replace("\n", "<br/>")), true); } return(String.Format("F.notify({0});", jsOB.ToString())); }
/// <summary> /// 获取显示对话框的客户端脚本 /// </summary> /// <param name="message">对话框消息</param> /// <param name="title">对话框标题</param> /// <param name="messageBoxIcon"></param> /// <param name="okScript">点击确定按钮执行的客户端脚本</param> /// <param name="target">显示对话框的目标页面</param> /// <param name="icon"></param> /// <param name="iconUrl">自定义对话框图标地址</param> /// <returns>客户端脚本</returns> public static string GetShowReference(string message, string title, MessageBoxIcon messageBoxIcon, string okScript, Target target, Icon icon, string iconUrl) { if (message == null) { message = String.Empty; } if (title == null) { title = String.Empty; } string addCSSScript = String.Empty; string iconScriptFragment = String.Empty; string resolvedIconUrl = IconHelper.GetResolvedIconUrl(icon, iconUrl); Page page = HttpContext.Current.CurrentHandler as Page; if (page != null) { resolvedIconUrl = page.ResolveUrl(resolvedIconUrl); } // Icon 或者 IconUrl 不为空 if (!String.IsNullOrEmpty(resolvedIconUrl)) { string className = String.Format("box-{0}-alert-icon", System.Guid.NewGuid().ToString("N")); var addCSSPrefix = String.Empty; if (target == Target.Parent) { addCSSPrefix = "parent."; } else if (target == Target.Top) { addCSSPrefix = "top."; } addCSSScript = String.Format("{0}X.util.addCSS('{1}','{2}');", addCSSPrefix, className, StyleUtil.GetNoRepeatBackgroundStyle("." + className, resolvedIconUrl)); iconScriptFragment = String.Format("'{0}'", className); } else { iconScriptFragment = MessageBoxIconHelper.GetName(messageBoxIcon); } message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); title = title.Replace("\r\n", "\n").Replace("\n", "<br/>"); string targetScript = "window"; if (target != Target.Self) { targetScript = TargetHelper.GetScriptName(target); } if (String.IsNullOrEmpty(title) && messageBoxIcon == DefaultMessageBoxIcon && String.IsNullOrEmpty(okScript) && String.IsNullOrEmpty(resolvedIconUrl)) { return(addCSSScript + String.Format("{0}.X.alert({1});", targetScript, JsHelper.GetJsString(message))); } else { return(addCSSScript + String.Format("{0}.X.alert({1},{2},{3},{4});", targetScript, JsHelper.GetJsStringWithScriptTag(message), JsHelper.GetJsString(title), iconScriptFragment, String.IsNullOrEmpty(okScript) ? "''" : JsHelper.GetFunction(okScript))); } }
/// <summary> /// 获取显示对话框的客户端脚本 /// </summary> /// <returns>客户端脚本</returns> public string GetShowReference() { //return GetShowReference(Message, Title, MessageBoxIcon, OkScript, Target, Icon, IconUrl); //if (message == null) //{ // message = String.Empty; //} //if (title == null) //{ // title = String.Empty; //} string message = ""; string title = ""; if (!String.IsNullOrEmpty(Message)) { message = Message; } if (!String.IsNullOrEmpty(Title)) { title = Title; } string addCSSScript = String.Empty; string iconScriptFragment = String.Empty; string resolvedIconUrl = IconHelper.GetResolvedIconUrl(Icon, IconUrl); Page page = HttpContext.Current.CurrentHandler as Page; if (page != null) { resolvedIconUrl = page.ResolveUrl(resolvedIconUrl); } Target target = Target; // Icon 或者 IconUrl 不为空 if (!String.IsNullOrEmpty(resolvedIconUrl)) { string className = String.Format("f-{0}-alert-icon", System.Guid.NewGuid().ToString("N")); var addCSSPrefix = String.Empty; if (target == Target.Parent) { addCSSPrefix = "parent."; } else if (target == Target.Top) { addCSSPrefix = "top."; } addCSSScript = String.Format("{0}F.addCSS('{1}','{2}');", addCSSPrefix, className, StyleUtil.GetNoRepeatBackgroundStyle("." + className, resolvedIconUrl)); iconScriptFragment = String.Format("'{0}'", className); } else { iconScriptFragment = MessageBoxIconHelper.GetName(MessageBoxIcon); } message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); title = title.Replace("\r\n", "\n").Replace("\n", "<br/>"); string targetScript = "window"; if (target != Target.Self) { targetScript = TargetHelper.GetScriptName(target); } JsObjectBuilder jsob = new JsObjectBuilder(); if (!String.IsNullOrEmpty(CssClass)) { jsob.AddProperty("cls", CssClass); } if (!String.IsNullOrEmpty(title)) { jsob.AddProperty("title", title); } if (!String.IsNullOrEmpty(OkScript)) { jsob.AddProperty("ok", JsHelper.GetFunction(OkScript), true); } if (!String.IsNullOrEmpty(message)) { jsob.AddProperty("message", JsHelper.EnquoteWithScriptTag(message), true); } if (!String.IsNullOrEmpty(iconScriptFragment)) { jsob.AddProperty("messageIcon", iconScriptFragment, true); } return(addCSSScript + String.Format("{0}.F.alert({1});", targetScript, jsob)); }
/// <summary> /// 获取按钮客户端点击事件的脚本 /// </summary> /// <param name="validateForms">验证表单列表</param> /// <param name="validateTarget">表单验证提示消息目标页面</param> /// <param name="validateMessageBox">是否显示表单验证提示对话框</param> /// <param name="enablePostBack">启用回发</param> /// <param name="postBackEventReference">回发脚本</param> /// <param name="confirmText">确认对话框消息</param> /// <param name="confirmTitle">确认对话框标题</param> /// <param name="confirmIcon">确认对话框图标</param> /// <param name="confirmTarget">确认对话框目标页面</param> /// <param name="onClientClick">自定义客户端点击脚本</param> /// <param name="disableControlJavascriptID">需要禁用的控件客户端ID</param> /// <returns>客户端脚本</returns> internal static string ResolveClientScript(string[] validateForms, Target validateTarget, bool validateMessageBox, bool enablePostBack, string postBackEventReference, string confirmText, string confirmTitle, MessageBoxIcon confirmIcon, Target confirmTarget, string onClientClick, string disableControlJavascriptID) { // 1. 表单验证 string validateScript = String.Empty; if (validateForms != null && validateForms.Length > 0) { JsArrayBuilder array = new JsArrayBuilder(); foreach (string formID in validateForms) { Control control = ControlUtil.FindControl(formID); if (control != null && control is ControlBase) { array.AddProperty((control as ControlBase).ClientID); } } validateScript = String.Format("if(!X.util.validForms({0},'{1}',{2})){{return false;}}", array.ToString(), TargetHelper.GetName(validateTarget), validateMessageBox.ToString().ToLower()); } // 2. 用户自定义脚本 string clientClickScript = onClientClick; if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";")) { clientClickScript += ";"; } // 3. 回发脚本 string postBackScript = String.Empty; if (enablePostBack) { if (!String.IsNullOrEmpty(disableControlJavascriptID)) { postBackScript += String.Format("X.disable('{0}');", disableControlJavascriptID); } postBackScript += postBackEventReference; } // 确认对话框 if (!String.IsNullOrEmpty(confirmText)) { postBackScript = Confirm.GetShowReference(confirmText, confirmTitle, confirmIcon, postBackScript, "", confirmTarget); } return(validateScript + clientClickScript + postBackScript); }
/// <summary> /// 生成按钮客户端点击事件的脚本 /// </summary> /// <param name="validateForms"></param> /// <param name="validateTarget"></param> /// <param name="enablePostBack"></param> /// <param name="postBackEventReference"></param> /// <param name="confirmText"></param> /// <param name="confirmTitle"></param> /// <param name="confirmIcon"></param> /// <param name="confirmTarget"></param> /// <param name="onClientClick"></param> /// <param name="disableControlJavascriptID"></param> /// <returns></returns> internal static string ResolveClientScript(string[] validateForms, Target validateTarget, bool validateMessageBox, bool enablePostBack, string postBackEventReference, string confirmText, string confirmTitle, MessageBoxIcon confirmIcon, Target confirmTarget, string onClientClick, string disableControlJavascriptID) { // 1. validateScript string validateScript = String.Empty; if (validateForms != null && validateForms.Length > 0) { #region old code //StringBuilder sb = new StringBuilder(); //sb.Append("var forms=[];"); //foreach (string formId in validateForms) //{ // Control control = ControlUtil.FindControl(formId); // if (control != null && control is ControlBase) // { // sb.AppendFormat("forms.push(X.{0});", (control as ControlBase).ClientJavascriptID); // } //} ////sb.Append("if(!box_validForms(forms,'表单不完整','请为 “{0}” 提供有效值!')){return false;}"); //sb.AppendFormat("var validResult=X.util.validForms(forms);if(!validResult[0]){{{0}return false;}}", // Alert.GetShowReference("请为 “'+validResult[1].fieldLabel+'” 提供有效值!", "表单不完整")); #endregion JsArrayBuilder array = new JsArrayBuilder(); foreach (string formID in validateForms) { Control control = ControlUtil.FindControl(formID); if (control != null && control is ControlBase) { array.AddProperty((control as ControlBase).ClientID); } } validateScript = String.Format("if(!X.util.validForms({0},'{1}',{2})){{return false;}}", array.ToString(), TargetHelper.GetName(validateTarget), validateMessageBox.ToString().ToLower()); } // 2. 用户自定义脚本 string clientClickScript = onClientClick; if (!String.IsNullOrEmpty(clientClickScript) && !clientClickScript.EndsWith(";")) { clientClickScript += ";"; } // 3. 回发脚本 string postBackScript = String.Empty; if (enablePostBack) { if (!String.IsNullOrEmpty(disableControlJavascriptID)) { postBackScript += String.Format("X.disable('{0}');", disableControlJavascriptID); //postBackScript += String.Format("X.util.setHiddenFieldValue('{0}','{1}');", ResourceManager.DISABLED_CONTROL_BEFORE_POSTBACK, disableControlClientId); //postBackScript += String.Format("X.util.setDisabledControlBeforePostBack('{0}');", disableControlJavascriptID); } postBackScript += postBackEventReference; } if (!String.IsNullOrEmpty(confirmText)) { #region old code // 对confirm进行处理,对<script></script>包含的内容做js代码处理 //string confirmText = ConfirmText.Replace("'", "\""); //if (confirmText.Contains("<script>")) //{ // confirmText = confirmText.Replace("<script>", "'+"); // confirmText = confirmText.Replace("</script>", "+'"); //} //confirmText = String.Format("'{0}'", confirmText); //JsObjectBuilder ob = new JsObjectBuilder(); //ob.AddProperty(OptionName.Title, String.Format("'{0}'", confirmTitle), true); //ob.AddProperty(OptionName.Msg, String.Format("'{0}'", JsHelper.GetStringWithJsBlock(confirmText)), true); //ob.AddProperty(OptionName.Buttons, "Ext.MessageBox.OKCANCEL", true); //ob.AddProperty(OptionName.Icon, String.Format("'{0}'", MessageBoxIconName.GetName(confirmIcon)), true); //ob.AddProperty(OptionName.Fn, String.Format("function(btn){{if(btn=='cancel'){{return false;}}else{{{0}}}}}", postBackScript), true); //postBackScript = String.Format("Ext.MessageBox.show({0});", ob.ToString()); #endregion postBackScript = Confirm.GetShowReference(confirmText, confirmTitle, confirmIcon, postBackScript, "return false;", confirmTarget); } return(validateScript + clientClickScript + postBackScript); }
/// <summary> /// 获取显示确认对话框的客户端脚本 /// </summary> /// <param name="message">对话框消息</param> /// <param name="title">对话框标题</param> /// <param name="icon">对话框图标</param> /// <param name="okScript">点击确定按钮执行的客户端脚本</param> /// <param name="cancelScript">点击取消按钮执行的客户端脚本</param> /// <param name="target">弹出对话框的目标页面</param> /// <returns>客户端脚本</returns> public static string GetShowReference(string message, string title, MessageBoxIcon icon, string okScript, string cancelScript, Target target) { /* * if (String.IsNullOrEmpty(title)) * { * title = "X.util.confirmTitle"; * } * else * { * title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>")); * } * message = message.Replace("\r\n", "\n").Replace("\n", "<br/>"); * * * JsObjectBuilder ob = new JsObjectBuilder(); * ob.AddProperty("title", title, true); * ob.AddProperty("msg", JsHelper.GetJsStringWithScriptTag(message), true); * ob.AddProperty("buttons", "Ext.MessageBox.OKCANCEL", true); * ob.AddProperty("icon", String.Format("{0}", MessageBoxIconHelper.GetName(icon)), true); * ob.AddProperty("fn", String.Format("function(btn){{if(btn=='cancel'){{{0}}}else{{{1}}}}}", cancelScript, okScriptstring), true); * * string targetName = "window"; * if (target != Target.Self) * { * targetName = TargetHelper.GetScriptName(target); * } * return String.Format("{0}.Ext.MessageBox.show({1});", targetName, ob.ToString()); */ string scriptTitle = "''"; if (!String.IsNullOrEmpty(title)) { title = JsHelper.GetJsString(title.Replace("\r\n", "\n").Replace("\n", "<br/>")); } string scriptMessage = JsHelper.GetJsStringWithScriptTag(message.Replace("\r\n", "\n").Replace("\n", "<br/>")); string scriptIconName = "''"; if (icon != MessageBoxIcon.Warning) { scriptIconName = String.Format("'{0}'", MessageBoxIconHelper.GetShortName(icon)); } string scriptTargetName = "''"; if (target != Target.Self) { scriptTargetName = String.Format("'{0}'", TargetHelper.GetName(target)); } string scriptCancel = JsHelper.GetJsString(cancelScript); string scriptOK = JsHelper.GetJsString(okScript); if (scriptIconName == "''") { if (scriptCancel == "''") { return(String.Format("X.confirm({0},{1},{2},{3});", scriptTargetName, scriptTitle, scriptMessage, scriptOK)); } else { return(String.Format("X.confirm({0},{1},{2},{3},{4});", scriptTargetName, scriptTitle, scriptMessage, scriptOK, scriptCancel)); } } else { return(String.Format("X.confirm({0},{1},{2},{3},{4},{5});", scriptTargetName, scriptTitle, scriptMessage, scriptOK, scriptCancel, scriptIconName)); } }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); // 不渲染 RenderWrapperNode = false; // 这个是必须的,2009-08-04 // 因为每个页面都会有 PageManager 控件,每个页面要至少调用 GetPostBackEventReference 一次,以在页面产生 __doPostBack 函数。 Page.ClientScript.GetPostBackEventReference(this, ""); // Move it to ResourceManager.cs // 为页面的 Form 添加 autocomplete="off" 属性 // 参考http://www.cnblogs.com/sanshi/archive/2009/09/04/1560146.html#1635830 // Page.Form.Attributes["autocomplete"] = "off"; #region HideScrollbars if (HideScrollbars) { //if (Page.Request.UserAgent.ToLower().Contains("msie")) //{ // //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "noscroll", String.Format("window.document.body.scroll='no';"), true); // AddStartupAbsoluteScript("window.document.body.scroll='no';"); //} //else //{ // //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "noscroll", String.Format("window.document.body.style.overflow='hidden';"), true); // AddStartupAbsoluteScript("window.document.body.style.overflow='hidden';"); //} AddStartupAbsoluteScript("F.util.hideScrollbar();"); } #endregion #region PageLoading if (!PageLoadingControlExist) { string jsContent = String.Empty; if (EnablePageLoading) { jsContent += "F.util.removePageLoading(false);"; } AddStartupAbsoluteScript(jsContent); } #endregion //#region EnableAjax //if (!EnableAjax) //{ // AddStartupAbsoluteScript("F.global_disable_ajax=true;"); //} //#endregion #region AutoSizePanelID if (!String.IsNullOrEmpty(AutoSizePanelID)) { PanelBase autosizePanel = ControlUtil.FindControl(Page.Form, AutoSizePanelID) as PanelBase; if (autosizePanel != null) { #region oldcode //string resizePanelScript = String.Empty; //resizePanelScript += String.Format("{0}_resize_outerpanel=function(){{var panel=Ext.getCmp('{1}');panel.setSize(Ext.getBody().getSize());panel.doLayout();}};", ClientJavascriptID, panel.ClientID); //resizePanelScript += String.Format("{0}_resize_outerpanel();", ClientJavascriptID); //resizePanelScript += String.Format("if(Ext.isIE){{X.{0}_resize_outerpanel.defer(60);}}", ClientJavascriptID); //resizePanelScript += String.Format("Ext.EventManager.onWindowResize(function(){{X.{0}_resize_outerpanel();}},box);", ClientJavascriptID); //AddAbsoluteStartupScript(resizePanelScript); // X._3=new Ext.FormViewport({renderTo:"RegionPanel1_wrapper",id:"RegionPanel1",layout:"border",items:[X._1,X._2],bodyStyle:"",border:false,animCollapse:false}); #endregion // 子节点不向页面输出HTML,此PageManager向页面输出HTML autosizePanel.RenderWrapperNode = false; RenderWrapperNode = true; OB.AddProperty("layout", "fit"); OB.AddProperty("border", false); OB.AddProperty("items", String.Format("{0}", autosizePanel.XID), true); string jsContent = String.Format("var {0}=Ext.create('Ext.ux.FormViewport',{1});", XID, OB.ToString()); AddStartupAbsoluteScript(jsContent); } } #endregion //if (EnableBigFont) //{ // AddStartupAbsoluteScript("Ext.getBody().addClass('bigfont');"); //} #region oldcode // Move to F.util.init // Asp.Net Buttons(type="submit") // AddStartupAbsoluteScript("F.util.makeAspnetSubmitButtonAjax();"); #endregion JsObjectBuilder job = new JsObjectBuilder(); job.AddProperty("name", UniqueID); if (ValidateForms != null && ValidateForms.Length > 0) { JsObjectBuilder validate = new JsObjectBuilder(); validate.AddProperty("forms", ControlUtil.GetControlClientIDs(ValidateForms)); validate.AddProperty("target", TargetHelper.GetName(ValidateTarget)); validate.AddProperty("messagebox", ValidateMessageBox.ToString().ToLower()); job.AddProperty("validate", validate); } string createScript = String.Format("F.pagemanager={1};", XID, job); AddStartupScript(createScript); }