/// <summary> /// Outputs server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object and stores tracing information about the control if tracing is enabled. /// </summary> /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the control content.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("id", this.ClientID.ToString()); writer.AddAttribute("class", "toggle-container " + this.CssClass); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "btn-group btn-toggle " + this.CssClass); writer.RenderBeginTag(HtmlTextWriterTag.Div); if (this.Checked) { _btnOn.AddCssClass(this.ActiveButtonCssClass + " " + this.OnCssClass + " active"); //_btnOff.RemoveCssClass( this.OffCssClass ); } else { _btnOff.AddCssClass(this.ActiveButtonCssClass + " " + this.OffCssClass + " active"); //_btnOn.RemoveCssClass( this.OnCssClass ); } _btnOn.RenderControl(writer); _btnOff.RenderControl(writer); writer.RenderEndTag(); _hfChecked.RenderControl(writer); writer.RenderEndTag(); RegisterJavascript(); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); Controls.Clear(); RockControlHelper.CreateChildControls(this, Controls); Controls.Add(_hfBinaryFileId); _hfBinaryFileId.ID = this.ID + "_hfBinaryFileId"; _hfBinaryFileId.Value = "0"; Controls.Add(_hfBinaryFileTypeGuid); _hfBinaryFileTypeGuid.ID = this.ID + "_hfBinaryFileTypeGuid"; _aFileName = new HtmlAnchor(); Controls.Add(_aFileName); _aFileName.ID = "fn"; _aFileName.Target = "_blank"; _aFileName.AddCssClass("file-link"); _aRemove = new HtmlAnchor(); Controls.Add(_aRemove); _aRemove.ID = "rmv"; _aRemove.HRef = "#"; _aRemove.InnerHtml = "<i class='fa fa-times'></i>"; _aRemove.Attributes["class"] = "remove-file"; _fileUpload = new FileUpload(); Controls.Add(_fileUpload); _fileUpload.ID = this.ID + "_fu"; RequiredFieldValidator.InitialValue = "0"; RequiredFieldValidator.ControlToValidate = _hfBinaryFileId.ID; RequiredFieldValidator.Display = ValidatorDisplay.Dynamic; }
/// <summary> /// This is where you implment the simple aspects of rendering your control. The rest /// will be handled by calling RenderControlHelper's RenderControl() method. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("class", "fileupload-group"); writer.RenderBeginTag(HtmlTextWriterTag.Div); if (BinaryFileId != null) { _aFileName.HRef = string.Format("{0}GetFile.ashx?id={1}", ResolveUrl("~"), BinaryFileId); _aFileName.InnerText = new BinaryFileService().Queryable().Where(f => f.Id == BinaryFileId).Select(f => f.FileName).FirstOrDefault(); _aFileName.AddCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "inline"; } else { _aFileName.HRef = string.Empty; _aFileName.InnerText = string.Empty; _aFileName.RemoveCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "none"; } writer.AddAttribute("class", "fileupload-thumbnail"); writer.RenderBeginTag(HtmlTextWriterTag.Div); _hfBinaryFileId.RenderControl(writer); _hfBinaryFileTypeGuid.RenderControl(writer); _aFileName.RenderControl(writer); writer.RenderEndTag(); writer.AddAttribute("class", "fileupload-remove"); writer.RenderBeginTag(HtmlTextWriterTag.Div); _aRemove.RenderControl(writer); writer.RenderEndTag(); // render drop zone writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileupload-dropzone"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.Write("drop / click to upload"); writer.RenderEndTag(); _fileUpload.Attributes["name"] = string.Format("{0}[]", this.ID); _fileUpload.RenderControl(writer); writer.RenderEndTag(); RegisterStartupScript(); writer.RenderEndTag(); }
/// <summary> /// Outputs server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object and stores tracing information about the control if tracing is enabled. /// </summary> /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the control content.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("id", this.ClientID.ToString()); writer.AddAttribute("class", "toggle-container " + this.CssClass); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", $"btn-group btn-toggle {this.ButtonGroupCssClass}"); writer.RenderBeginTag(HtmlTextWriterTag.Div); _btnOn.Attributes["class"] = "btn btn-default js-toggle-on " + this.ButtonSizeCssClass; _btnOn.InnerHtml = this.OnText; _btnOff.Attributes["class"] = "btn btn-default js-toggle-off " + this.ButtonSizeCssClass; _btnOff.InnerHtml = this.OffText; if (this.Checked) { _btnOn.AddCssClass(this.ActiveButtonCssClass + " " + this.OnCssClass + " active"); //_btnOff.RemoveCssClass( this.OffCssClass ); } else { _btnOff.AddCssClass(this.ActiveButtonCssClass + " " + this.OffCssClass + " active"); //_btnOn.RemoveCssClass( this.OnCssClass ); } _btnOff.RenderControl(writer); _btnOn.RenderControl(writer); writer.RenderEndTag(); _hfChecked.RenderControl(writer); writer.RenderEndTag(); RegisterJavascript(); }
/// <summary> /// This is where you implement the simple aspects of rendering your control. The rest /// will be handled by calling RenderControlHelper's RenderControl() method. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("class", "fileupload-group"); writer.AddAttribute("id", this.ClientID); if (ToolTip.IsNotNullOrWhiteSpace()) { writer.AddAttribute("title", ToolTip); } writer.RenderBeginTag(HtmlTextWriterTag.Div); if (BinaryFileId != null || !string.IsNullOrWhiteSpace(this.UploadedContentFilePath)) { if (IsBinaryFile) { _aFileName.HRef = string.Format("{0}GetFile.ashx?id={1}", ResolveUrl("~"), BinaryFileId); _aFileName.InnerText = new BinaryFileService(new RockContext()).Queryable().Where(f => f.Id == BinaryFileId).Select(f => f.FileName).FirstOrDefault(); } else { _aFileName.HRef = ResolveUrl(this.UploadedContentFilePath); _aFileName.InnerText = this.UploadedContentFilePath; } _aFileName.AddCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "block"; } else { _aFileName.HRef = string.Empty; _aFileName.InnerText = string.Empty; _aFileName.RemoveCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "none"; } if (this.Enabled) { if (this.DisplayMode == UploaderDisplayMode.DropZone) { writer.AddAttribute("class", "fileupload-thumbnail"); writer.RenderBeginTag(HtmlTextWriterTag.Div); _hfBinaryFileId.RenderControl(writer); _hfBinaryFileTypeGuid.RenderControl(writer); _aFileName.RenderControl(writer); writer.AddAttribute("class", "fileupload-remove"); if (!ShowDeleteButton) { writer.AddStyleAttribute(HtmlTextWriterStyle.Visibility, "hidden"); } writer.RenderBeginTag(HtmlTextWriterTag.Div); _aRemove.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); } string uploadClass = this.DisplayMode == UploaderDisplayMode.DefaultButton ? "upload-progress-sm" : "upload-progress"; string spinnerSize = this.DisplayMode == UploaderDisplayMode.DefaultButton ? "fa-lg" : "fa-3x"; writer.Write($@" <div class='js-upload-progress {uploadClass}' style='display:none;'> <i class='fa fa-refresh {spinnerSize} fa-spin'></i> <div class='js-upload-progress-percent'></div> </div>"); if (this.DisplayMode == UploaderDisplayMode.Button) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileupload-button"); } else if (this.DisplayMode == UploaderDisplayMode.DefaultButton) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileuploaddefault-button"); } else { writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileupload-dropzone"); } writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.Write(this.UploadButtonText); writer.RenderEndTag(); _fileUpload.Attributes["name"] = string.Format("{0}[]", this.ID); _fileUpload.RenderControl(writer); writer.RenderEndTag(); } RegisterStartupScript(); writer.RenderEndTag(); }
/// <summary> /// This is where you implment the simple aspects of rendering your control. The rest /// will be handled by calling RenderControlHelper's RenderControl() method. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("class", "fileupload-group"); writer.AddAttribute("id", this.ClientID); writer.RenderBeginTag(HtmlTextWriterTag.Div); if (BinaryFileId != null || !string.IsNullOrWhiteSpace(this.UploadedContentFilePath)) { if (IsBinaryFile) { _aFileName.HRef = string.Format("{0}GetFile.ashx?id={1}", ResolveUrl("~"), BinaryFileId); _aFileName.InnerText = new BinaryFileService(new RockContext()).Queryable().Where(f => f.Id == BinaryFileId).Select(f => f.FileName).FirstOrDefault(); } else { _aFileName.HRef = string.Format("{0}GetFile.ashx?isBinaryFile=F&rootFolder={1}&fileName={2}", ResolveUrl("~"), Rock.Security.Encryption.EncryptString(this.RootFolder), BinaryFileId); _aFileName.InnerText = this.UploadedContentFilePath; } _aFileName.AddCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "block"; } else { _aFileName.HRef = string.Empty; _aFileName.InnerText = string.Empty; _aFileName.RemoveCssClass("file-exists"); _aRemove.Style[HtmlTextWriterStyle.Display] = "none"; } if (this.Enabled) { if (this.DisplayMode == UploaderDisplayMode.DropZone) { writer.AddAttribute("class", "fileupload-thumbnail"); writer.RenderBeginTag(HtmlTextWriterTag.Div); _hfBinaryFileId.RenderControl(writer); _hfBinaryFileTypeGuid.RenderControl(writer); _aFileName.RenderControl(writer); writer.AddAttribute("class", "fileupload-remove"); if (!ShowDeleteButton) { writer.AddStyleAttribute(HtmlTextWriterStyle.Visibility, "hidden"); } writer.RenderBeginTag(HtmlTextWriterTag.Div); _aRemove.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); } writer.Write(@" <div class='js-upload-progress upload-progress' style='display:none;'> <i class='fa fa-refresh fa-3x fa-spin'></i> </div>"); if (this.DisplayMode == UploaderDisplayMode.Button) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileupload-button"); } else { writer.AddAttribute(HtmlTextWriterAttribute.Class, "fileupload-dropzone"); } writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Span); if (this.DisplayMode == UploaderDisplayMode.Button) { writer.Write("Upload File"); } else { writer.Write("Upload"); } writer.RenderEndTag(); _fileUpload.Attributes["name"] = string.Format("{0}[]", this.ID); _fileUpload.RenderControl(writer); writer.RenderEndTag(); } RegisterStartupScript(); writer.RenderEndTag(); }