/// <summary> /// 更新ASP.NET控件 /// </summary> /// <param name="sb"></param> /// <param name="doc"></param> private void UpdateASPNETControls(StringBuilder sb, HtmlDocument doc) { if (PageManager.Instance.AjaxAspnetControls == null) { return; } foreach (string controlId in PageManager.Instance.AjaxAspnetControls) { string controlClientID = controlId; Control control = ControlUtil.FindControl(controlId); if (control != null) { controlClientID = control.ClientID; } string updateHtml = JsHelper.Enquote(GetHtmlNodeOuterHTML(controlClientID, doc)); if (updateHtml != null) { sb.Append(String.Format("F.util.replace('{0}', {1});", controlClientID, updateHtml)); /* * // 如果是Asp.net按钮或者ImageButton,需要重新注册点击时AJAX回发页面,而不是调用Button(type=submit)的默认行为 * if (control != null && (control is System.Web.UI.WebControls.Button || control is System.Web.UI.WebControls.ImageButton)) ||{ || sb.Append(String.Format("F.util.makeAspnetSubmitButtonAjax('{0}');", control.ClientID)); ||} * */ } } }
//[Category(CategoryName.OPTIONS)] //[DefaultValue("")] //[Description("控件容器样式类")] //public string ContainerClassName //{ // get // { // object obj = BoxState["ExtendContainerClassName"]; // return obj == null ? "" : (string)obj; // } // set // { // BoxState["ExtendContainerClassName"] = value; // } //} //[Browsable(false)] //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] //[Description("extjs控件类型")] //public string Xtype //{ // get // { // object[] xtypeAttributes = GetType().GetCustomAttributes(typeof(XTypeAttribute), true); // if (xtypeAttributes != null && xtypeAttributes.Length == 1) // { // return (xtypeAttributes[0] as XTypeAttribute).Name; // } // return String.Empty; // } //} //public override string AccessKey //{ // get // { // return base.AccessKey; // } // set // { // base.AccessKey = value; // } //} #endregion #endregion #region OnPreRender /// <summary> /// 渲染 HTML 之前调用(AJAX回发) /// </summary> protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("CssStyle")) { sb.AppendFormat("{0}.el.applyStyles({1});", XID, JsHelper.Enquote(CssStyle)); } // 老的 CssClass 会在 X.state(x0,{"CssClass":"green"}) 时自动删除,并自动添加新的 CssClass。 // 为什么不在这里先removeClass,再addClass?因为此时我们已经不知道之前的CssClass是什么了,这里取得的是已经修改过的。 // 在X.util的setFState函数中处理的 if (PropertyModified("CssClass")) { //sb.AppendFormat("{0}.el.addClass({1});", XID, JsHelper.Enquote(CssClass)); } //if (PropertyModified("FormItemClass")) //{ // sb.AppendFormat("{0}.el.addClass({1});", XID, JsHelper.Enquote(FormItemClass)); //} AddAjaxScript(sb); }
/// <summary> /// 添加属性 /// </summary> /// <param name="propertyName">属性名</param> /// <param name="propertyValue">属性值</param> /// <param name="persistOriginal">是否保持原样</param> public void AddProperty(string propertyName, object propertyValue, bool persistOriginal) { if (persistOriginal) { _properties.Add(propertyName, propertyValue.ToString()); } else { if (propertyValue is string) { _properties.Add(propertyName, JsHelper.Enquote(propertyValue.ToString())); } else if (propertyValue is bool) { _properties.Add(propertyName, propertyValue.ToString().ToLower()); } else if (propertyValue is float || propertyValue is double) { _properties.Add(propertyName, JsHelper.NumberToString(propertyValue)); } else { _properties.Add(propertyName, propertyValue.ToString()); } } }
private string GetGridTpls(HtmlDocument doc, string controlId) { string tpls = GetHtmlNodeInnerHTML(controlId + "_tpls", doc); tpls = Regex.Replace(tpls, "\r?\n\\s*", ""); // 删除生成HTML中的 "\r\n " return(JsHelper.Enquote(tpls)); }
/// <summary> /// 获取关闭当前激活窗体并回发父页面的客户端脚本 /// </summary> /// <param name="argument">回发参数</param> /// <returns>客户端脚本</returns> public static string GetHidePostBackReference(string argument) { //return ACTIVE_WINDOW_SCRIPT + "if(aw){eval('aw[1].X.'+aw[0].id+'_hide_postback(\"" + argument + "\");');}"; //return ACTIVE_WINDOW_SCRIPT + "if(aw){aw[0].box_hide_postback('" + argument + "');}"; //return "(function(){var aw=F.wnd.getActiveWindow(); if(aw){ aw[0].box_hide_postback('" + argument + "'); }})();"; //return "(function(){var aw=F.wnd.getActiveWindow();if(aw){aw.f_hide_postback(" + JsHelper.Enquote(argument) + ");}})();"; return("F.activeWnd.hidePostBack(" + JsHelper.Enquote(argument) + ");"); }
/// <summary> /// 获取字符串数组的脚本字符串形式 /// </summary> /// <param name="values">字符串数组</param> /// <returns>字符串数组的脚本字符串</returns> public static string EnquoteStringArray(string[] values) { StringBuilder sb = new StringBuilder(); foreach (string value in values) { sb.AppendFormat("{0},", JsHelper.Enquote(value)); } return(String.Format("[{0}]", sb.ToString().TrimEnd(','))); }
/// <summary> /// 获取回发的客户端脚本(触发PageManager的CustomEvent事件) /// </summary> /// <param name="enableAjax">当前请求是否启用AJAX</param> /// <param name="eventArgument">事件参数</param> /// <param name="validateForms">是否在回发前验证表单(在PageManager上进行表单配置)</param> /// <param name="persistOriginal">保持eventArgument参数原样输出</param> /// <returns>客户端脚本</returns> public string GetCustomEventReference(bool enableAjax, string eventArgument, bool validateForms, bool persistOriginal) { string arg = eventArgument; if (!persistOriginal) { arg = JsHelper.Enquote(arg); } return(String.Format("F.f_customEvent({0},{1},{2});", enableAjax.ToString().ToLower(), arg, validateForms.ToString().ToLower())); }
/// <summary> /// 渲染 HTML 之前调用(AJAX回发) /// </summary> protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("ImageUrl", "ImageWidth", "ImageHeight", "ImageCssClass", "ImageCssStyle", "ImageAlt", "ToolTip", "ToolTipTitle", "ToolTipAutoHide", "Icon")) { sb.AppendFormat("{0}.setValue({1});", XID, JsHelper.Enquote(GetInnerHtml())); } AddAjaxScript(sb); }
private string GetGridTpls(HtmlDocument doc, string controlId) { string html = String.Empty; string tpls = GetHtmlNodeInnerHTML(controlId + "_tpls", doc); if (!String.IsNullOrEmpty(tpls)) { // 删除生成HTML中的 "\r\n " html = Regex.Replace(tpls, "\r?\n\\s*", ""); } return(JsHelper.Enquote(html)); }
/// <summary> /// 渲染 HTML 之前调用(AJAX回发) /// </summary> protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("Text")) { sb.AppendFormat("{0}.setText({1});", XID, JsHelper.Enquote(Text)); } AddAjaxScript(sb); }
/// <summary> /// 添加属性 /// </summary> /// <param name="propertyName">属性名</param> /// <param name="propertyValue">属性值</param> /// <param name="persistOriginal">是否保持原样</param> public void AddProperty(string propertyName, object propertyValue, bool persistOriginal) { // 容错处理(如果 propertyValue 为空,则不添加) if (propertyValue == null) { return; } // 添加属性之前,要先删除之前已经添加的属性,否则会出粗 RemoveProperty(propertyName); if (persistOriginal) { _properties.Add(propertyName, propertyValue.ToString()); } else { if (propertyValue is string) { _properties.Add(propertyName, JsHelper.Enquote(propertyValue.ToString())); } else if (propertyValue is bool) { _properties.Add(propertyName, propertyValue.ToString().ToLower()); } else if (propertyValue is float || propertyValue is double) { _properties.Add(propertyName, JsHelper.NumberToString(propertyValue)); } else { _properties.Add(propertyName, propertyValue.ToString()); } } }
/// <summary> /// 获取字段验证失败提示信息的客户端脚本 /// </summary> /// <param name="message">提示信息</param> /// <returns>客户端脚本</returns> public string GetMarkInvalidReference(string message) { return(String.Format("{0}.markInvalid({1});", ScriptID, JsHelper.Enquote(message))); }
/// <summary> /// 渲染 HTML 之前调用(页面第一次加载或者普通回发) /// </summary> protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region validate properties if (Required) { OB.AddProperty("allowBlank", false); if (!String.IsNullOrEmpty(RequiredMessage)) { OB.AddProperty("blankText", RequiredMessage); } } if (MaxLength != null) { OB.AddProperty("maxLength", MaxLength.Value); if (!String.IsNullOrEmpty(MaxLengthMessage)) { OB.AddProperty("maxLengthText", MaxLengthMessage); } } if (MinLength != null) { OB.AddProperty("minLength", MinLength.Value); if (!String.IsNullOrEmpty(MinLengthMessage)) { OB.AddProperty("minLengthText", MinLengthMessage); } } // Calculate regex expression via RegexPattern and Regex string regexStr = String.Empty; if (RegexPattern != RegexPattern.None) { regexStr = RegexPatternHelper.GetRegexValue(RegexPattern); } else if (!String.IsNullOrEmpty(Regex)) { regexStr = Regex; } if (!String.IsNullOrEmpty(regexStr)) { string ignoreCaseStr = String.Empty; if (RegexIgnoreCase) { ignoreCaseStr = ",'i'"; } OB.AddProperty("regex", String.Format("new RegExp({0}{1})", JsHelper.Enquote(regexStr), ignoreCaseStr), true); if (!String.IsNullOrEmpty(RegexMessage)) { OB.AddProperty("regexText", RegexMessage); } } #endregion //OB.AddProperty("enableKeyEvents", true); #region NextFocusControl if (!String.IsNullOrEmpty(NextFocusControl)) { Control nextControl = ControlUtil.FindControl(Page, NextFocusControl); if (nextControl != null && nextControl is ControlBase) { //// true to enable the proxying of key events for the HTML input field (defaults to false) //OB.AddProperty("enableKeyEvents", true); // Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. OB.Listeners.AddProperty("specialkey", String.Format("function(field,e){{if(e.getKey()==e.ENTER){{{0}.focus(true,10);e.stopEvent();}}}}", (nextControl as ControlBase).XID), true); } } #endregion #region ControlToCompare string compareValue = String.Empty; // 如果CompareControl 和 CompareValue 同时存在,则 CompareControl 拥有更高的优先级 if (!String.IsNullOrEmpty(CompareControl)) { Control compareControl = ControlUtil.FindControl(Page, CompareControl); if (compareControl != null && compareControl is ControlBase) { compareValue = String.Format("F.fieldValue({0})", JsHelper.Enquote((compareControl as ControlBase).ClientID)); } } else if (!String.IsNullOrEmpty(CompareValue)) { compareValue = CompareValue; if (CompareType == CompareType.String) { compareValue = JsHelper.Enquote(compareValue); } } // Check whether compareValue exist, which may produced from CompareControl or CompareValue. if (!String.IsNullOrEmpty(compareValue)) { string compareOperatorJs = OperatorHelper.GetName(CompareOperator); string compareExpressionScript = String.Empty; if (CompareType == CompareType.String) { compareExpressionScript = String.Format("value{0}{1}", compareOperatorJs, compareValue); } else if (CompareType == CompareType.Int) { compareExpressionScript = String.Format("parseInt(value,10){0}parseInt({1},10)", compareOperatorJs, compareValue); } else if (CompareType == CompareType.Float) { compareExpressionScript = String.Format("parseFloat(value){0}parseFloat({1})", compareOperatorJs, compareValue); } string compareScript = String.Format("if({0}){{return true;}}else{{return {1};}}", compareExpressionScript, JsHelper.Enquote(CompareMessage)); OB.AddProperty("validator", String.Format("function(){{var value=F.fieldValue(this);{0}}}", compareScript), true); } #endregion }
/// <summary> /// 获取回发的客户端脚本(触发PageManager的CustomEvent事件) /// </summary> /// <param name="eventArgument">事件参数</param> /// <param name="validateForms">是否在回发前验证表单(在PageManager上进行表单配置)</param> /// <returns>客户端脚本</returns> public string GetCustomEventReference(string eventArgument, bool validateForms) { return(String.Format("F.customEvent({0}, {1});", JsHelper.Enquote(eventArgument), validateForms.ToString().ToLower())); }
/// <summary> /// 获取关闭当前激活窗体并执行脚本的客户端脚本 /// </summary> /// <param name="argument">回发参数</param> /// <returns>客户端脚本</returns> public static string GetHideExecuteScriptReference(string argument) { //return "(function(){var aw=F.wnd.getActiveWindow();if(aw){aw.f_hide_executescript(" + JsHelper.Enquote(argument) + ");}})();"; return("F.activeWnd.hideExecuteScript(" + JsHelper.Enquote(argument) + ");"); }