/// <summary> /// 添加属性 /// </summary> /// <param name="propertyValue">属性值</param> /// <param name="persistOriginal">是否保持原样</param> public void AddProperty(object propertyValue, bool persistOriginal) { if (persistOriginal) { _properties.Add(propertyValue.ToString()); } else { if (propertyValue is string) { _properties.Add(JsHelper.Enquote(propertyValue.ToString())); } else if (propertyValue is bool) { _properties.Add(propertyValue.ToString().ToLower()); } else if (propertyValue is float || propertyValue is double) { _properties.Add(JsHelper.NumberToString(propertyValue)); } else { _properties.Add(propertyValue.ToString()); } } }
//[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 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的setXState函数中处理的 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> /// 更新ASP.NET控件 /// </summary> /// <param name="writer"></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("X.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("X.util.makeAspnetSubmitButtonAjax('{0}');", control.ClientID)); } } } }
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)); }
protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("Enabled", "Text", "ConfirmText", "ConfirmTitle", "ConfirmIcon", "ConfirmTarget", "OnClientClick", "ToolTip", "ToolTipTitle", "ToolTipAutoHide")) { sb.AppendFormat("{0}.setValue({1});", XID, JsHelper.Enquote(GetInnerHtml())); } AddAjaxScript(sb); }
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); }
protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("Text")) { sb.AppendFormat("{0}.setText({1});", XID, JsHelper.Enquote(Text)); } AddAjaxScript(sb); }
protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (EnableIFrame) { if (PropertyModified("IFrameUrl")) { sb.AppendFormat("X.wnd.updateIFrameNode({0},{1});", XID, JsHelper.Enquote(IFrameUrl)); } } AddAjaxScript(sb); }
protected override void OnAjaxPreRender() { base.OnAjaxPreRender(); StringBuilder sb = new StringBuilder(); if (PropertyModified("Text")) { sb.AppendFormat("{0}.x_setText();", XID); } if (EnablePress) { if (PropertyModified("Pressed")) { //if (ClientPropertyModifiedInServer("Pressed")) sb.AppendFormat("{0}.x_toggle();", XID); } } if (PropertyModified("Icon", "IconUrl")) { string resolvedIconUrl = GetResolvedIconUrl(this.Icon, IconUrl); if (!String.IsNullOrEmpty(resolvedIconUrl)) { sb.AppendFormat("{0}.setIcon({1});", XID, JsHelper.Enquote(resolvedIconUrl)); } } if (PropertyModified("ToolTip")) { sb.AppendFormat("{0}.x_setTooltip();", XID); } if (PropertyModified("OnClientClick", "ConfirmTitle", "ConfirmText", "ConfirmTarget", "ConfirmIcon")) { //sb.AppendFormat("{0}.un('click', {0}.initialConfig.listeners.click);", XID); //sb.AppendFormat("{0}.on('click',{1});", XID, GetClickScriptFunction()); sb.AppendFormat("{0}.setHandler({1});", XID, JsHelper.GetFunction(GetClickScript())); } AddAjaxScript(sb); }
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)) { OB.AddProperty("regex", String.Format("new RegExp({0})", JsHelper.Enquote(regexStr)), true); if (!String.IsNullOrEmpty(RegexMessage)) { OB.AddProperty("regexText", RegexMessage); } } #endregion #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; // If CompareControl and CompareValue both exist, then CompareControl has higher priority. if (!String.IsNullOrEmpty(CompareControl)) { Control compareControl = ControlUtil.FindControl(Page, CompareControl); if (compareControl != null && compareControl is ControlBase) { compareValue = String.Format("X.util.getFormFieldValue(Ext.getCmp({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); } //else if (CompareType == CompareType.Date) //{ // compareExpressionScript = String.Format("Date.parse(value){0}Date.parse({1})", compareOperatorJs, compareValueJs); //} string compareScript = String.Format("if({0}){{return true;}}else{{return {1};}}", compareExpressionScript, JsHelper.Enquote(CompareMessage)); OB.AddProperty("validator", String.Format("function(value){{if(this.getXType()==='combo'){{value=this.getValue();}}{0}}}", compareScript), true); } #endregion }