/// <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)); } } } }
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 }
internal override string GetColumnValue(GridRow row) { HtmlNodeBuilder nb = new HtmlNodeBuilder("a"); #region DataTextField if (!String.IsNullOrEmpty(DataTextField)) { object value = row.GetPropertyValue(DataTextField); //if (!String.IsNullOrEmpty(DataTextFormatString)) //{ // nb.InnerProperty = String.Format(DataTextFormatString, value); //} //else //{ // nb.InnerProperty = value.ToString(); //} string text = String.Empty; if (!String.IsNullOrEmpty(DataTextFormatString)) { text = String.Format(DataTextFormatString, value); if (HtmlEncodeFormatString) { text = HttpUtility.HtmlEncode(text); } } else { text = value.ToString(); if (HtmlEncode) { text = HttpUtility.HtmlEncode(text); } } nb.InnerProperty = text; } else { nb.InnerProperty = Text; } #endregion if (Enabled) { string url = "#"; #region DataIFrameUrlFields string hrefOriginal = String.Empty; if (!String.IsNullOrEmpty(DataIFrameUrlFields)) { string[] fields = DataIFrameUrlFields.Trim().TrimEnd(',').Split(','); List <object> fieldValues = new List <object>(); foreach (string field in fields) { if (!String.IsNullOrEmpty(field)) { //fieldValues.Add(row.GetPropertyValue(field)); string fieldValue = row.GetPropertyValue(field).ToString(); if (UrlEncode) { fieldValue = HttpUtility.UrlEncode(fieldValue); } fieldValues.Add(fieldValue); } } if (!String.IsNullOrEmpty(DataIFrameUrlFormatString)) { hrefOriginal = String.Format(DataIFrameUrlFormatString, fieldValues.ToArray()); } else { if (fieldValues.Count > 0) { hrefOriginal = fieldValues[0].ToString(); } } } else { hrefOriginal = IFrameUrl; } url = Grid.ResolveUrl(hrefOriginal); #endregion string title = String.Empty; #region DataTextField if (!String.IsNullOrEmpty(DataWindowTitleField)) { object value = row.GetPropertyValue(DataWindowTitleField); if (!String.IsNullOrEmpty(DataWindowTitleFormatString)) { title = String.Format(DataWindowTitleFormatString, value); } else { title = value.ToString(); } } else { title = Title; } #endregion #region WindowID if (!String.IsNullOrEmpty(WindowID)) { Window window = ControlUtil.FindControl(Grid.Page, WindowID) as Window; if (window != null) { nb.SetProperty("href", "javascript:;"); nb.SetProperty("onclick", String.Format("javascript:{0}", window.GetShowReference(url, title))); //nb.SetProperty("href", String.Format("javascript:X.{0}_show('{1}','{2}');", window.ClientID, url, title.Replace("'", "\""))); } } #endregion } else { nb.SetProperty("class", "x-item-disabled"); nb.SetProperty("disabled", "disabled"); } string tooltip = GetTooltipString(row); #region Icon IconUrl string resolvedIconUrl = IconHelper.GetResolvedIconUrl(Icon, IconUrl); if (!String.IsNullOrEmpty(resolvedIconUrl)) { nb.InnerProperty = String.Format("<img src=\"{0}\" {1} />", resolvedIconUrl, tooltip) + nb.InnerProperty; } #endregion //string result2 = nb.ToString(); //#region Tooltip //if (!String.IsNullOrEmpty(tooltip)) //{ // result2 = result2.ToString().Insert(2, tooltip); //} //#endregion //return result2; string result = nb.ToString(); if (!String.IsNullOrEmpty(tooltip)) { result = result.ToString().Insert("<a".Length, tooltip); } return(result); }
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("X.util.hideScrollbar();"); } #endregion #region PageLoading if (!PageLoadingControlExist) { string jsContent = String.Empty; if (EnablePageLoading) { jsContent += "X.util.removePageLoading(false);"; } AddStartupAbsoluteScript(jsContent); } #endregion //#region EnableAjax //if (!EnableAjax) //{ // AddStartupAbsoluteScript("X.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}=new Ext.ux.FormViewport({1});", XID, OB.ToString()); AddStartupAbsoluteScript(jsContent); } } #endregion //if (EnableBigFont) //{ // AddStartupAbsoluteScript("Ext.getBody().addClass('bigfont');"); //} #region oldcode // Move to X.util.init // Asp.Net Buttons(type="submit") // AddStartupAbsoluteScript("X.util.makeAspnetSubmitButtonAjax();"); #endregion }
/// <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); }
protected override void OnFirstPreRender() { base.OnFirstPreRender(); if (EnableFrame) { OB.AddProperty("frame", true); } #region Items if (!RenderChildrenAsContent) { if (Items.Count > 0) { JsArrayBuilder ab = new JsArrayBuilder(); foreach (ControlBase item in Items) { if (item.Visible) { ab.AddProperty(String.Format("{0}", item.XID), true); } } OB.AddProperty("items", ab.ToString(), true); } } #endregion #region Toolbars foreach (Toolbar bar in Toolbars) { string toolbarID = String.Format("{0}", bar.XID); if (bar.Position == ToolbarPosition.Top) { OB.AddProperty("tbar", toolbarID, true); } else if (bar.Position == ToolbarPosition.Bottom) { OB.AddProperty("bbar", toolbarID, true); } } #endregion #region BodyStyle/ShowBorder string bodyStyleStr = BodyStyle; if (!bodyStyleStr.Contains("padding")) { if (!String.IsNullOrEmpty(BodyPadding)) { bodyStyleStr += String.Format("padding:{0};", BodyPadding); } } if (EnableBackgroundColor) { if (!bodyStyleStr.Contains("background-color")) { string backgroundColorStyleStr = GlobalConfig.GetDefaultBackgroundColor(); if (!String.IsNullOrEmpty(backgroundColorStyleStr)) { bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); } } } //else if (EnableLightBackgroundColor) //{ // if (!bodyStyleStr.Contains("background-color")) // { // string backgroundColorStyleStr = GlobalConfig.GetLightBackgroundColor(PageManager.Instance.Theme.ToString()); // bodyStyleStr += String.Format("background-color:{0};", backgroundColorStyleStr); // } //} OB.AddProperty("bodyStyle", bodyStyleStr); OB.AddProperty("border", ShowBorder); #endregion #region IconUrl if (!String.IsNullOrEmpty(IconUrl)) { // Window控件的特殊处理在Window控件中 // 添加CSS样式 string className = String.Format("extaspnet_{0}_panelbase_icon", XID); AddStartupCSS(className, StyleUtil.GetNoRepeatBackgroundStyle("." + className, ResolveUrl(IconUrl))); OB.AddProperty("iconCls", className); //// 下面这种方式不行,这个样式是要添加到Head中的,而不是最外层的DIV //AddExtraStyle("background", StyleUtil.GetNoRepeatBackgroundStyleValue(ResolveUrl(IconUrl))); } #endregion #region Width/Height // 对于Panel,如果宽度/高度没有定义 if (Width == Unit.Empty && AutoWidth) { OB.AddProperty("autoWidth", true); } if (Height == Unit.Empty && AutoHeight) { OB.AddProperty("autoHeight", true); } // 如果父控件是容器控件(不是ContentPanel),并且Layout != LayoutType.Container, // 则设置AutoWidth/AutoHeight都为false if (Parent is PanelBase) { PanelBase parent = Parent as PanelBase; if (!(parent is ContentPanel) && parent.Layout != Layout.Container) { OB.RemoveProperty("autoHeight"); OB.RemoveProperty("autoWidth"); } } if (AutoScroll) { OB.AddProperty("autoScroll", true); } #region old code //// 如果是 PageLayout 中的Panel,不能设置AutoWidth //if (Parent is PageLayout) //{ // // region // if (Region != Region_Default) OB.AddProperty(OptionName.Region, RegionTypeName.GetName(Region.Value)); //} //else //{ // // 对于Panel,如果宽度/高度没有定义,则使用自动宽度和高度 // if (Width == Unit.Empty) // { // OB.AddProperty(OptionName.AutoWidth, true); // } // if (Height == Unit.Empty) // { // OB.AddProperty(OptionName.AutoHeight, true); // } //} //// 如果父控件是容器控件,并且Layout=Fit,则设置AutoWidth/AutoHeight都为false //if (Parent is PanelBase) //{ // PanelBase parentPanel = Parent as PanelBase; // if (parentPanel.Layout == LayoutType.Fit // || parentPanel.Layout == LayoutType.Anchor // || parentPanel.Layout == LayoutType.Border) // { // OB.RemoveProperty(OptionName.AutoHeight); // OB.RemoveProperty(OptionName.AutoWidth); // } //} #endregion #endregion #region EnableIFrame if (EnableIFrame) { #region old code //string iframeJsContent = String.Empty; //string frameUrl = ResolveUrl(IFrameUrl); //JsObjectBuilder iframeBuilder = new JsObjectBuilder(); //if (IFrameDelayLoad) //{ // iframeBuilder.AddProperty(OptionName.Src, "#"); //} //else //{ // iframeBuilder.AddProperty(OptionName.Src, frameUrl); //} //iframeBuilder.AddProperty(OptionName.LoadMask, false); //iframeJsContent += String.Format("var {0}=new Ext.ux.ManagedIFrame('{0}',{1});", IFrameID, iframeBuilder.ToString()); //if (IFrameDelayLoad) //{ // iframeJsContent += String.Format("{0}_url='{1}';", IFrameID, frameUrl); //} //iframeJsContent += "\r\n"; //AddStartupScript(this, iframeJsContent); #endregion // 注意: // 如下依附于现有对象的属性名称的定义规则:x_property1 // 存储于当前对象实例中 OB.AddProperty("x_iframe", true); OB.AddProperty("x_iframe_url", IFrameUrl); OB.AddProperty("x_iframe_name", IFrameName); // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 if (!String.IsNullOrEmpty(IFrameUrl)) { //_writeIframeToHtmlDocument = true; OB.AddProperty("x_iframe_loaded", true); // 直接添加iframe属性 OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); } else { //_writeIframeToHtmlDocument = false; OB.AddProperty("x_iframe_loaded", false); } #region old code //// If current panel is Tab, then process the IFrameDelayLoad property. //Tab tab = this as Tab; //if (tab != null && tab.IFrameDelayLoad) //{ // // 如果是Tab,并且此Tab不是激活的,则不添加iframe // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); //} //else //{ // // 如果定义了IFrameUrl,则直接写到页面中,否则先缓存到此对象中 // if (!String.IsNullOrEmpty(IFrameUrl)) // { // //_writeIframeToHtmlDocument = true; // OB.AddProperty("box_property_iframe_loaded", true); // // 直接添加iframe属性 // OB.AddProperty("html", String.Format("<iframe src=\"{0}\" name=\"{1}\" frameborder=\"0\" style=\"height:100%;width:100%;overflow:auto;\"></iframe>", IFrameUrl, IFrameName)); // } // else // { // //_writeIframeToHtmlDocument = false; // OB.AddProperty("box_property_iframe_loaded", false); // } //} #endregion } #endregion #region RoundBorder //if (RoundBorder) OB.AddProperty(OptionName.Frame, true); #endregion #region EnableLargeHeader if (EnableLargeHeader) { OB.AddProperty("cls", "box-panel-big-header"); } #endregion #region remove fx // 关闭折叠时特效 OB.AddProperty("animCollapse", false); #endregion #region ContentEl //string finallyScript = String.Empty; if (RenderChildrenAsContent) { OB.AddProperty("contentEl", ContentID); // 在页面元素渲染完成后,才显示容器控件的内容 string renderScript = String.Format("Ext.get('{0}').show();", ContentID); OB.Listeners.AddProperty("render", "function(component){" + renderScript + "}", true); //string beforerenderScript = String.Format("Ext.get('{0}').setStyle('display','');", ChildrenContentID); //OB.Listeners.AddProperty("beforerender", "function(component){" + beforerenderScript + "}", true); // 这一段的逻辑(2008-9-1): // 如果是页面第一次加载 + 此Panel在Tab中 + 此Tab不是当前激活Tab + 此Tab的TabStrip启用了延迟加载 // 那么在页面加载完毕后,把此Panel给隐藏掉,等此Panel渲染到页面中时再显示出来 Tab tab = ControlUtil.FindParentControl(this, typeof(Tab)) as Tab; if (tab != null) { TabStrip tabStrip = tab.Parent as TabStrip; if (tabStrip.EnableDeferredRender && tabStrip.Tabs[tabStrip.ActiveTabIndex] != tab) { // 页面第一次加载时,在显示(控件的render事件)之前要先隐藏 AddStartupAbsoluteScript(String.Format("Ext.get('{0}').setStyle('display','none');", ContentID)); } } } #endregion }