public override void RenderBeginTag(HtmlTextWriter writer) { StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"panel panel-default\">"); sb.Append(Environment.NewLine); sb.Append("<div class=\"panel-heading\">"); sb.Append(Environment.NewLine); Guid gPanel = Guid.NewGuid(); //Guid gSwitch = Guid.NewGuid(); if (CreateHideButton) { sb.Append(this.Title); sb.Append("<div class=\"btn-group pull-right\" style=\"margin-top: -5px\">"); bSwitch = new Switch(); bSwitch.Size = Enumerations.SwitchSize.Small; bSwitch.Checked = !PanelIsInitiallyHidden; bSwitch.OffText = "<i class=\"glyphicon glyphicon-remove\">"; bSwitch.OnText = "<i class=\"glyphicon glyphicon-ok\">"; this.Controls.Add(bSwitch); TextWriter txtWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(txtWriter); bSwitch.RenderControl(htmlWriter); sb.Append(txtWriter); sb.Append("<script type=\"text/javascript\">"); sb.Append("$(window).load(function() {"); sb.Append("if($('#" + bSwitch.ClientID + "').attr('checked')){"); sb.Append("$('#" + gPanel + "').show();"); sb.Append("}"); sb.Append("else{"); sb.Append("$('#" + gPanel + "').hide();"); sb.Append("}"); sb.Append("});"); sb.Append("$('#" + bSwitch.ClientID + "').on('switchChange.bootstrapSwitch', function(event, state) {"); sb.Append("if(state){"); sb.Append("$('#" + gPanel + "').slideDown(500);"); sb.Append("}"); sb.Append("else{"); sb.Append("$('#" + gPanel + "').slideUp(500);"); sb.Append("}"); sb.Append("});"); sb.Append("</script>"); sb.Append("</div>"); } else { sb.Append(this.Title); } sb.Append(Environment.NewLine); sb.Append("</div>"); sb.Append(Environment.NewLine); sb.Append("<div class=\"panel-body\" id=\"" + gPanel + "\">"); sb.Append(Environment.NewLine); Literal litEnd = new Literal(); litEnd.Text = sb.ToString(); litEnd.RenderControl(writer); }