/// <summary> /// Construct button from a configuration instance. /// </summary> /// <param name="configuration"></param> public Button(ButtonConfiguration configuration) { this.Configuration = configuration; }
/// <summary> /// Create JSON string for JavaScript Button. /// </summary> /// <param name="jsonTextWriter"></param> /// <param name="buttonConfiguration"></param> /// <returns></returns> private void CreateButtonConfigJson(JsonTextWriter jsonTextWriter, ButtonConfiguration buttonConfiguration) { jsonTextWriter.WriteStartObject(); jsonTextWriter.WritePropertyName("DisplayAsImage"); jsonTextWriter.WriteValue(buttonConfiguration.ButtonRenderType != ButtonRenderTypes.Button && buttonConfiguration.ButtonRenderType != ButtonRenderTypes.Link); jsonTextWriter.WritePropertyName("ImageUrl"); jsonTextWriter.WriteValue(ResolveImageUrl(buttonConfiguration.ButtonRenderType, Kit.ResolveAbsoluteUrl(buttonConfiguration.ImageUrl))); jsonTextWriter.WritePropertyName("Text"); jsonTextWriter.WriteValue(buttonConfiguration.Text); jsonTextWriter.WritePropertyName("ToolTip"); jsonTextWriter.WriteValue(buttonConfiguration.ToolTip); jsonTextWriter.WritePropertyName("Css"); jsonTextWriter.WriteValue(buttonConfiguration.Css); jsonTextWriter.WritePropertyName("OnClientClick"); jsonTextWriter.WriteValue(WebUtility.EncodeJavaScriptString(buttonConfiguration.OnClientClick)); jsonTextWriter.WritePropertyName("CommandArgument"); jsonTextWriter.WriteValue(buttonConfiguration.CommandArgument); jsonTextWriter.WritePropertyName("GridSelectionRequired"); jsonTextWriter.WriteValue(buttonConfiguration.GridSelectionRequired.ToString().ToLowerInvariant()); jsonTextWriter.WritePropertyName("GridSelectionRequiredWarningMessage"); jsonTextWriter.WriteValue(buttonConfiguration.GridSelectionRequiredWarningMessage ?? ""); jsonTextWriter.WriteEndObject(); }
/// <summary> /// Raises the System.Web.UI.Control.PreRender event. /// </summary> /// <param name="e">An System.EventArgs object that contains the event data.</param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (this.Configuration == null) { this.Configuration = new ButtonConfiguration { ButtonRenderType = ButtonRenderTypes.Button, CommandArgument = this.CommandArgument, OnClientClick = this.OnClientClick, Text = this.Text }; } this.CommandArgument = this.Configuration.CommandArgument ?? this.CommandArgument; this.OnClientClick = this.Configuration.OnClientClick ?? this.OnClientClick; switch (this.Configuration.ButtonRenderType) { case ButtonRenderTypes.Link: this.Text = this.Configuration.Text ?? this.Text; break; case ButtonRenderTypes.Button: this.Text = this.Configuration.Text ?? this.Text; string toolTip = WebUtility.EncodeJavaScriptString(this.ToolTip); ClientScripts.OnDocumentReady.Add2BeginOfBody(EXT_FORMATTER_TEMPLATE .Replace("$ControlID$", this.ClientID) .Replace("$ToolTip$", this.ToolTip) .Replace("$ControlVariableName$", WebUtility.GenerateVariableName(this.ClientID)), JavaScriptPriority.Low); break; default: this.Text = ""; Image image = new Image(); image.ImageUrl = GetImageUrl(this.Configuration.ButtonRenderType); if (Kit.IsEmpty(image.ImageUrl)) { image.ImageUrl = this.Configuration.ImageUrl; this.Controls.Add(image); } break; } if (this.Configuration.ButtonRenderType == ButtonRenderTypes.DeleteImage && Kit.IsEmpty(this.OnClientClick)) this.OnClientClick = string.Format("return window.confirm('{0}');", Resources.DPCtrl_DeleteButtonClientConfirmMessage); }