private void UpdateOnClientClick() { var sb = new StringBuilder(); //sb.AppendFormat("ID:'win{0}'", new Random((Int32)DateTime.Now.Ticks).Next(1, 1000)); sb.AppendFormat("ID:'win{0}'", this.ClientID); var title = Title; if (String.IsNullOrEmpty(title)) { title = Text; } sb.AppendFormat(", Title:'{0}'", title); String url = Url; if (!String.IsNullOrEmpty(url) && !url.StartsWithIgnoreCase("http://")) { url = ResolveUrl(url); } sb.AppendFormat(", URL:'{0}'", url); if (BoxWidth != Unit.Empty) { sb.AppendFormat(", Width:{0}", (Int32)BoxWidth.Value); } if (BoxHeight != Unit.Empty) { sb.AppendFormat(", Height:{0}", (Int32)BoxHeight.Value); } sb.AppendFormat(", ShowMessageRow:{0}", ShowMessageRow.ToString().ToLower()); sb.AppendFormat(", MessageTitle:'{0}'", MessageTitle); sb.AppendFormat(", Message:'{0}'", Message); sb.AppendFormat(", ShowButtonRow:{0}", ShowButtonRow.ToString().ToLower()); if (!string.IsNullOrEmpty(BeforeShow)) { sb.AppendFormat(", BeforeShow:{0}", BeforeShow); } if (!string.IsNullOrEmpty(InWindow)) { sb.AppendFormat(", InWindow:{0}", InWindow); } if (!string.IsNullOrEmpty(ParentWindow)) { sb.AppendFormat(", ParentWindow:{0}", ParentWindow); } OnClientClick = "ShowDialog({" + sb.ToString() + "}); return false;"; RegisterReloadFormJs(Page.ClientScript, Page.IsPostBack); }
private void UpdateOnClientClick(HyperLink link) { String url = Url; url = Control.ResolveUrl(url); // ResolveUrl会自行处理绝对路径的问题 string jsFuncName = "LinkBoxFieldShow" + GetHashCode(); #region 在页面注册脚本函数 if (!Control.Page.ClientScript.IsClientScriptBlockRegistered(GetType(), jsFuncName)) { var showJs = new StringBuilder(); var moreJs = new StringBuilder(); if (Width != Unit.Empty) { showJs.AppendFormat("Width:{0},", (Int32)Width.Value); } if (Height != Unit.Empty) { showJs.AppendFormat("Height:{0},", (Int32)Height.Value); } if (ClickedRowBackColor != Color.Empty) { string color = new WebColorConverter().ConvertToString(ClickedRowBackColor); showJs.AppendFormat(@" BeforeShow:function(){{GridViewExtender.HighlightRow(ele,'{0}',true);}}, AfterClose:function(){{GridViewExtender.HighlightRow(ele,'{0}',false);}}, ", color); // 使用到GridViewExtender的地方引入相关的js Control.Page.ClientScript.RegisterClientScriptResource(typeof(GridViewExtender), "XControl.View.GridViewExtender.js"); } if (!string.IsNullOrEmpty(InWindow)) { showJs.AppendFormat("InWindow:{0},", InWindow); } if (!string.IsNullOrEmpty(ParentWindow)) { showJs.AppendFormat("ParentWindow:{0},", ParentWindow); } if (this.Control is GridView) { moreJs.AppendFormat("stopEventPropagation(event);"); if (!Control.Page.ClientScript.IsClientScriptBlockRegistered(typeof(object), "stopEventPropagation")) { Control.Page.ClientScript.RegisterClientScriptBlock(typeof(object), "stopEventPropagation", Helper.JsMinSimple(!XControlConfig.Debug, @" ;function stopEventPropagation(e){ try{ if(typeof e != 'undefined'){ if(typeof e.stopPropagation != 'undefined'){ e.stopPropagation(); }else if(typeof e.cancelBubble != 'undefined'){ e.cancelBubble = true; } } }catch(ex){} } "), true); } } Control.Page.ClientScript.RegisterClientScriptBlock(GetType(), jsFuncName, Helper.JsMinSimple(!XControlConfig.Debug, @" ;function {0}(ele, event, title, url, msgRow, msgTitle, msg, btnRow){{ try{{ ShowDialog({{ ID:'win'+Math.random(), Title:title, URL:url, ShowMessageRow:msgRow, MessageTitle:msgTitle, Message:msg, {1} ShowButtonRow:btnRow }}); {2} }}catch(ex){{{3}}}; return false; }} ", jsFuncName, showJs, moreJs, XTrace.Debug ? "alert(ex);" : ""), true); LinkBox.RegisterReloadFormJs(Control.Page.ClientScript, Control.Page.IsPostBack); } #endregion var title = link.ToolTip; if (String.IsNullOrEmpty(title)) { title = Title; } OnClientClick = Helper.HTMLPropertyEscape(@"return {0}(this,event,'{1}','{2}',{3},'{4}','{5}',{6});", jsFuncName, Helper.JsStringEscape(title), Helper.JsStringEscape(url), ShowMessageRow.ToString().ToLower(), Helper.JsStringEscape(MessageTitle), Helper.JsStringEscape(Message), ShowButtonRow.ToString().ToLower() ); }