///// <summary> ///// Renders the container ///// </summary> ///// <param name="writer"></param> //protected override void Render(HtmlTextWriter writer) //{ // if (Text == "" && !DesignMode) // { // base.Render(writer); // return; // } // if (RenderMode == RenderModes.Text) // Text = HtmlUtils.DisplayMemo(Text); // string TStyle = Style["position"]; // bool IsAbsolute = false; // if (TStyle != null && TStyle.Trim() == "absolute") // IsAbsolute = true; // // <Center> is still the only reliable way to get block structures centered // if (!IsAbsolute && Center) // { // writer.AddStyleAttribute(HtmlTextWriterStyle.MarginLeft, "auto"); // writer.AddStyleAttribute(HtmlTextWriterStyle.MarginRight, "auto"); // // In designmode we want to write out a container so it // // so the designer properly shows the controls as block control // if (DesignMode) // writer.Write("<div style='width:100%'>"); // } // writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID); // writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClass); // writer.AddStyleAttribute(HtmlTextWriterStyle.Width, Width.ToString()); // foreach (string Key in Style.Keys) // { // writer.AddStyleAttribute(Key, Style[Key]); // } // writer.RenderBeginTag(HtmlTextWriterTag.Div); // writer.RenderBeginTag(HtmlTextWriterTag.Table); // writer.RenderBeginTag(HtmlTextWriterTag.Tr); // // Set up image <td> tag // writer.RenderBeginTag(HtmlTextWriterTag.Td); // if (ErrorImage != "") // { // string ImageUrl = ErrorImage.ToLower(); // if (ImageUrl == "warningresource") // ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), WebResources.WARNING_ICON_RESOURCE); // else if (ImageUrl == "inforesource") // ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), WebResources.INFO_ICON_RESOURCE); // else // ImageUrl = ResolveUrl(ErrorImage); // writer.AddAttribute(HtmlTextWriterAttribute.Src, ImageUrl); // writer.RenderBeginTag(HtmlTextWriterTag.Img); // writer.RenderEndTag(); // } // writer.RenderEndTag(); // image <td> // // Render content <td> tag // writer.RenderBeginTag(HtmlTextWriterTag.Td); // if (UserMessage != "") // writer.Write("<span style='font-weight:normal'>" + UserMessage + "</span><hr />"); // writer.Write(Text); // writer.RenderEndTag(); // Content <td> // writer.RenderEndTag(); // </tr> // writer.RenderEndTag(); // </table> // writer.RenderEndTag(); // </div> // if (!IsAbsolute) // { // if (Center) // { // if (DesignMode) // writer.Write("</div>"); // </div> // } // writer.WriteBreak(); // } //} protected override void OnPreRender(EventArgs e) { ClientScriptProxy = ClientScriptProxy.Current; if (Visible && !string.IsNullOrEmpty(Text) && DisplayTimeout > 0) { // Embed the client script library as Web Resource Link ScriptLoader.LoadjQuery(this); string Script = @"setTimeout(function() { $('#" + ClientID + @"').fadeOut('slow') }," + DisplayTimeout.ToString() + ");"; //@"window.setTimeout(""document.getElementById('" + ClientID + @"').style.display='none';""," + DisplayTimeout.ToString() + @");"; ClientScriptProxy.RegisterStartupScript(this, typeof(ErrorDisplay), "DisplayTimeout", Script, true); } base.OnPreRender(e); }
protected override void OnPreRender(EventArgs e) { Page.RegisterRequiresPostBack(this); if (string.IsNullOrEmpty(SelectedTab) && _Tabs.Count > 0) { SelectedTab = _Tabs[0].TabPageClientId; } // Persist our selection into a hidden var since it's all client side // Script updates this var ClientScriptProxy.RegisterHiddenField(this, HIDDEN_FORMVAR_PREFIX + ClientID, SelectedTab); string script = @" function ActivateTab(tabId, num) { var _Tabs = eval(tabId); if (_Tabs.onActivate && _Tabs.onActivate(num)) return; if (typeof(num)=='string') { for(var x=0; x< _Tabs.length; x++) { if (_Tabs[x].pageId == num) { num = x; break;} } } if (typeof(num)=='string') num=0; var Tab = _Tabs[num]; for(var i=0; i<_Tabs.length; i++) { var t = _Tabs[i]; document.getElementById(t.tabId).className = (t.enabled ? '" + TabCssClass + "' : '" + DisabledTabCssClass + @"'); if (t.pageId) document.getElementById(t.pageId).style.display = 'none'; } document.getElementById(Tab.tabId).className = '" + SelectedTabCssClass + @"'; document.getElementById(Tab.pageId).style.display = ''; document.getElementById('" + HIDDEN_FORMVAR_PREFIX + ClientID + @"').value=Tab.pageId; } "; // Register only once per page ClientScriptProxy.RegisterClientScriptBlock(this, typeof(WebResources), "ActivateTab", script, true); StringBuilder sb = new StringBuilder(2048); sb.AppendFormat("var {0} = [];\r\n", ClientID); for (int i = 0; i < TabPages.Count; i++) { string iStr = i.ToString(); TabPage tab = TabPages[i]; sb.Append(ClientID + "[" + iStr + "] = { id: " + iStr + "," + "tabId: '" + ClientID + "_" + iStr + "'," + "pageId: '" + tab.TabPageClientId + "'," + "enabled: " + tab.Enabled.ToString().ToLower() + "};\r\n"); } ClientScriptProxy.RegisterClientScriptBlock(this, typeof(WebResources), "TabInit_" + ClientID, sb.ToString(), true); // Force the page to show the Selected Tab if (SelectedTab != "") { script = "ActivateTab('" + ClientID + "','" + SelectedTab + "');\r\n"; ClientScriptProxy.RegisterStartupScript(this, typeof(WebResources), "TabStartup_" + ClientID, script, true); } base.OnPreRender(e); }
protected override void OnPreRender(EventArgs e) { StringBuilder startupScript = new StringBuilder(2048); string DhId = DragHandleID; if (string.IsNullOrEmpty(DragHandleID)) { DragHandleID = ClientID; } Control Ctl = FindControl(DragHandleID); if (Ctl != null) { DhId = Ctl.ClientID; } startupScript.AppendLine("\t$('#" + ClientID + "')"); if (Closable && !string.IsNullOrEmpty(DragHandleID)) { string imageUrl = CloseBoxImage; if (imageUrl == "WebResource") { imageUrl = ScriptProxy.GetWebResourceUrl(this, GetType(), WebResources.CLOSE_ICON_RESOURCE); } StringBuilder closableOptions = new StringBuilder("imageUrl: '" + imageUrl + "'"); if (!string.IsNullOrEmpty(DragHandleID)) { closableOptions.Append(",handle: $('#" + DragHandleID + "')"); } if (!string.IsNullOrEmpty(ClientDialogHandler)) { closableOptions.Append(",handler: " + ClientDialogHandler); } if (FadeOnClose) { closableOptions.Append(",fadeOut: 'slow'"); } startupScript.AppendLine("\t\t.closable({ " + closableOptions + "})"); } string options = ""; if (Draggable) { // force auto stacking of windows (last dragged to top of zIndex) options = "{ stack: \"*\", opacity: 0.80, dragDelay: " + DragDelay.ToString(); if (!string.IsNullOrEmpty(DragHandleID)) { options += ",handle:'#" + DragHandleID + "'"; } if (!string.IsNullOrEmpty(Cursor)) { options += ",cursor:'" + Cursor + "'"; } options += " }"; startupScript.AppendLine("\t\t.draggable(" + options + " )"); } if (ShadowOffset != 0) { startupScript.AppendLine( "\t\t.shadow({ opacity:" + ShadowOpacity.ToString(CultureInfo.InvariantCulture.NumberFormat) + ",offset:" + ShadowOffset.ToString() + "})"); } if (Centered) { startupScript.AppendLine( "\t\t.centerInClient()"); } startupScript.Length = startupScript.Length - 2; // strip last CR/LF \r\n startupScript.AppendLine(";"); string script = "$( function() {\r\n" + startupScript + "});"; ScriptProxy.RegisterStartupScript(this, GetType(), ID + "_DragBehavior", script, true); base.OnPreRender(e); }
/// <summary> /// Most of the work happens here for generating the hook up script code /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { // Ignore if we're calling this in a Callback if (AjaxMethodCallback.IsCallback) { return; } base.OnPreRender(e); // MS AJAX aware script management ClientScriptProxy scriptProxy = ClientScriptProxy.Current; // Register resources RegisterResources(scriptProxy); // Capture and map the various option parameters StringBuilder sbOptions = new StringBuilder(512); sbOptions.Append("{"); if (!string.IsNullOrEmpty(OnClientSelection)) { sbOptions.Append("select: " + OnClientSelection + ","); } else { sbOptions.AppendLine( @"select: function (e, ui) { $(""#" + this.UniqueID + @""").val(ui.item.value); },"); } if (CallbackHandler != null) { // point the service Url back to the current page method if (AjaxMethodCallback != null) { ServerUrl = Page.Request.Url.LocalPath + "?" + "Method=AutoCompleteCallbackHandler&CallbackTarget=" + AjaxMethodCallback.ID; } } if (!string.IsNullOrEmpty(ServerUrl)) { sbOptions.Append("source: \"" + ServerUrl + "\","); } sbOptions.AppendFormat("autoFocus: {0},delay: {1},minLength: {2},", AutoFocus.ToString().ToLower(), Delay, MinLength); // strip off trailing , sbOptions.Length--; sbOptions.Append("}"); // Write out initilization code for calendar StringBuilder sbStartupScript = new StringBuilder(400); sbStartupScript.AppendLine("$(document).ready( function() {"); sbStartupScript.AppendFormat(" var autocompl = $(\"#{0}\").autocomplete({1});\r\n", ClientID, sbOptions.ToString()); // close out the script function sbStartupScript.AppendLine("} );"); scriptProxy.RegisterStartupScript(Page, typeof(WebResources), "_cal" + UniqueID, sbStartupScript.ToString(), true); }
/// <summary> /// Creates the JavaScript client side object that matches the /// server side method signature. The JScript function maps /// to a CallMethod() call on the client. /// </summary> private void GenerateClassWrapperForCallbackMethods() { //if (ServiceType != AjaxMethodCallbackServiceTypes.AjaxMethodCallback) //{ // GenerateClassWrapperForWcfAndAsmx(); // return ; //} StringBuilder sb = new StringBuilder(); if (GenerateClientProxyClass == ProxyClassGenerationModes.jsdebug) { ClientScriptProxy.Current.RegisterClientScriptInclude(this, typeof(WebResources), ServerUrl.ToLower() + "/jsdebug", ScriptRenderModes.Script); return; } if (GenerateClientProxyClass == ProxyClassGenerationModes.Inline) { Type objectType = null; if (ClientProxyTargetType != null) { objectType = ClientProxyTargetType; } else if (TargetInstance != null) { objectType = TargetInstance.GetType(); } // assume Page as default else { objectType = Page.GetType(); } sb.Append("var " + ID + " = { "); MethodInfo[] Methods = objectType.GetMethods(BindingFlags.Instance | BindingFlags.Public); foreach (MethodInfo Method in Methods) { if (Method.GetCustomAttributes(typeof(CallbackMethodAttribute), false).Length > 0) { sb.Append("\r\n " + Method.Name + ": function " + "("); string ParameterList = ""; foreach (ParameterInfo Parm in Method.GetParameters()) { ParameterList += Parm.Name + ","; } sb.Append(ParameterList + "completed,errorHandler)"); sb.AppendFormat( @" {{ var _cb = {0}_GetProxy(); _cb.callMethod(""{1}"",[{2}],completed,errorHandler); return _cb; }},", ID, Method.Name, ParameterList.TrimEnd(',')); } } if (sb.Length > 0) { sb.Length--; // strip trailing , } // End of class sb.Append("\r\n}\r\n"); } string Url = null; if (string.IsNullOrEmpty(ServerUrl)) { Url = Context.Request.Path; } else { Url = ResolveUrl(ServerUrl); } sb.Append( "function " + ID + @"_GetProxy() { var _cb = new AjaxMethodCallback('" + ID + "','" + Url + @"', { timeout: " + Timeout.ToString() + @", postbackMode: '" + PostBackMode.ToString() + @"', formName: '" + PostBackFormName + @"' }); return _cb; } "); ClientScriptProxy.RegisterStartupScript(this, GetType(), ID + "_ClientProxy", sb.ToString(), true); }
/// <summary> /// Most of the work happens here for generating the hook up script code /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // MS AJAX aware script management ClientScriptProxy scriptProxy = ClientScriptProxy.Current; // Register resources RegisterResources(scriptProxy); string dateFormat = DateFormat; if (string.IsNullOrEmpty(dateFormat) || dateFormat == "Auto") { // Try to create a data format string from culture settings // this code will fail if culture can't be mapped on server hence the empty try/catch try { dateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; } catch { } } dateFormat = dateFormat.ToLower().Replace("yyyy", "yy"); // Capture and map the various option parameters StringBuilder sbOptions = new StringBuilder(512); sbOptions.Append("{"); string onSelect = OnClientSelect; if (DisplayMode == DatePickerDisplayModes.Button) { sbOptions.Append("showOn: 'button',"); } else if (DisplayMode == DatePickerDisplayModes.ImageButton) { string img = ButtonImage; if (img == "WebResource") { img = scriptProxy.GetWebResourceUrl(this, typeof(WebResources), WebResources.CALENDAR_ICON_RESOURCE); } else { img = ResolveUrl(ButtonImage); } sbOptions.Append("showOn: 'button', buttonImageOnly: true, buttonImage: '" + img + "',buttonText: 'Select date',"); } else if (DisplayMode == DatePickerDisplayModes.Inline) { // need to store selection in the page somehow for inline since it's // not tied to a textbox scriptProxy.RegisterHiddenField(this, ClientID, Text); onSelect = ClientID + "OnSelect"; } if (!string.IsNullOrEmpty(onSelect)) { sbOptions.Append("onSelect: " + onSelect + ","); } if (DisplayMode != DatePickerDisplayModes.Inline) { if (!string.IsNullOrEmpty(OnClientBeforeShow)) { sbOptions.Append("beforeShow: function(y,z) { $('#ui-datepicker-div').maxZIndex(); " + OnClientBeforeShow + "(y,z); },"); } else { sbOptions.Append("beforeShow: function() { $('#ui-datepicker-div').maxZIndex(); },"); } } if (MaxDate.HasValue) { sbOptions.Append("maxDate: " + WebUtils.EncodeJsDate(MaxDate.Value) + ","); } if (MinDate.HasValue) { sbOptions.Append("minDate: " + WebUtils.EncodeJsDate(MinDate.Value) + ","); } if (ShowButtonPanel) { sbOptions.Append("showButtonPanel: true,"); } sbOptions.Append("dateFormat: '" + dateFormat + "'}"); // Write out initilization code for calendar StringBuilder sbStartupScript = new StringBuilder(400); sbStartupScript.AppendLine("$( function() {"); if (DisplayMode != DatePickerDisplayModes.Inline) { scriptProxy.RegisterClientScriptBlock(Page, typeof(WebResources), "__attachDatePickerInputKeys", AttachDatePickerKeysScript, true); sbStartupScript.AppendFormat("var cal = jQuery('#{0}').datepicker({1}).attachDatepickerInputKeys();\r\n", ClientID, sbOptions); } else { sbStartupScript.AppendLine("var cal = jQuery('#" + ClientID + "Div').datepicker(" + sbOptions.ToString() + ")"); if (SelectedDate.HasValue && SelectedDate.Value > new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc)) { WestwindJsonSerializer ser = new WestwindJsonSerializer(); ser.DateSerializationMode = JsonDateEncodingModes.NewDateExpression; string jsDate = ser.Serialize(SelectedDate); sbStartupScript.AppendLine("cal.datepicker('setDate'," + jsDate + ");"); } else { sbStartupScript.AppendLine("cal.datepicker('setDate',new Date());"); } // Assign value to hidden form var on selection scriptProxy.RegisterStartupScript(this, typeof(WebResources), UniqueID + "OnSelect", "function " + ClientID + "OnSelect(dateStr) {\r\n" + ((!string.IsNullOrEmpty(OnClientSelect)) ? OnClientSelect + "(dateStr);\r\n" : "") + "jQuery('#" + ClientID + "')[0].value = dateStr;\r\n}\r\n", true); } sbStartupScript.AppendLine("} );"); scriptProxy.RegisterStartupScript(Page, typeof(WebResources), "_cal" + UniqueID, sbStartupScript.ToString(), true); }