public void InitialBag1() { StateBag bag = new StateBag(true); AC ac = new AC(bag); Assert.AreEqual(0, ac.Count, "count"); Assert.AreEqual(null, ac ["hola"], "item"); Assert.AreEqual(0, ac.Keys.Count, "keys"); ac.Add("notexists", "invalid"); ac.Remove("notexists"); ac.Remove("notexists"); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); ac.AddAttributes(writer); ac.Render(writer); Assert.AreEqual(0, writer.InnerWriter.ToString().Length, "length"); CssStyleCollection css = ac.CssStyle; Assert.AreEqual(0, css.Count, "csscount"); Assert.AreEqual(null, css ["hola"], "cssitem"); Assert.AreEqual(0, css.Keys.Count, "csskeys"); css.Add("notexists", "invalid"); css.Remove("notexists"); css.Remove("notexists"); css.Add("notexists", "invalid"); css.Clear(); Assert.AreEqual(0, css.Keys.Count, "csskeys2"); }
public void InitialNoBag7() { AC ac = new AC(null); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); ac.AddAttributes(writer); }
protected internal override void Render(HtmlTextWriter writer) { EnsureChildControls(); writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID); if (_dynamicLayout) { writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); } else { writer.AddStyleAttribute(HtmlTextWriterStyle.Visibility, "hidden"); writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "block"); } if (_attributes != null) { _attributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Div); base.Render(writer); writer.RenderEndTag(); // div if (!DesignMode) { ScriptManager.RegisterScriptDescriptors(this); } }
public void NonStyleAttributes2() { StateBag bag = new StateBag(true); AC ac = new AC(bag); StringWriter sr = new StringWriter(); HtmlTextWriter writer = new HtmlTextWriter(sr); ac.Add("class", "classname"); ac.AddAttributes(writer); string str = sr.ToString(); Assert.AreEqual("", str, "value1"); Assert.AreEqual(1, bag.Count, "count1"); writer = new HtmlTextWriter(sr); writer.RenderBeginTag(HtmlTextWriterTag.A); ac.AddAttributes(writer); writer.RenderEndTag(); Assert.AreEqual("", str, "value2"); Assert.AreEqual(1, bag.Count, "count2"); }
private void RenderLabel(HtmlTextWriter writer, string text, string clientID) { writer.AddAttribute(HtmlTextWriterAttribute.For, clientID); if (_labelAttributes != null && _labelAttributes.Count != 0) { _labelAttributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Label); writer.Write(text); writer.RenderEndTag(); }
public void Deny_Unrestricted () { // nothing else is required AttributeCollection ac = new AttributeCollection (bag); Assert.AreEqual (0, ac.Count, "Count"); Assert.IsNotNull (ac.CssStyle, "CssStyle"); ac["mono"] = "monkey"; Assert.AreEqual ("monkey", ac["mono"], "this"); Assert.IsNotNull (ac.Keys, "Keys"); ac.Add ("monkey", "mono"); ac.AddAttributes (writer); ac.Clear (); ac.Remove ("mono"); ac.Render (writer); }
private void RenderLabel(HtmlTextWriter writer, string text, string clientID) { writer.AddAttribute(HtmlTextWriterAttribute.For, clientID); if (BinaryCompatibility.Current.TargetsAtLeastFramework48 && _labelAttributesState != null && _labelAttributesState.Count != 0) { LabelAttributes.AddAttributes(writer); } else if (_labelAttributes != null && _labelAttributes.Count != 0) { _labelAttributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Label); writer.Write(text); writer.RenderEndTag(); }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="text"></param> /// <param name="clientID"></param> private void RenderOption(HtmlTextWriter writer, ListItem item) { //<option selected="selected" value="2">fifo</option> if (item == null) { return; } writer.AddAttribute(HtmlTextWriterAttribute.Selected, item.Selected.ToString()); writer.AddAttribute(HtmlTextWriterAttribute.Value, item.Value); if (_optionAttributes != null && _optionAttributes.Count != 0) { _optionAttributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Option); writer.Write(item.Text); writer.RenderEndTag(); }
internal virtual void RenderInputTag(HtmlTextWriter writer, string clientID, string onClick) { if (clientID != null) { writer.AddAttribute(HtmlTextWriterAttribute.Id, clientID); } writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox"); if (UniqueID != null) { writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID); } // Whidbey 20815 if (_valueAttribute != null) { writer.AddAttribute(HtmlTextWriterAttribute.Value, _valueAttribute); } if (Checked) { writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked"); } // ASURT 119141: Render ---- attribute on the INPUT tag (instead of the SPAN) so the checkbox actually gets disabled when Enabled=false if (!IsEnabled && SupportsDisabledAttribute) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } if (AutoPostBack && (Page != null) && Page.ClientSupportsJavaScript) { PostBackOptions options = new PostBackOptions(this, String.Empty); if (CausesValidation && Page.GetValidators(ValidationGroup).Count > 0) { options.PerformValidation = true; options.ValidationGroup = ValidationGroup; } if (Page.Form != null) { options.AutoPostBack = true; } // ASURT 98368 // Need to merge the autopostback script with the user script onClick = Util.MergeScript(onClick, Page.ClientScript.GetPostBackEventReference(options, true)); writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick); if (EnableLegacyRendering) { writer.AddAttribute("language", "javascript", false); } } else { if (Page != null) { Page.ClientScript.RegisterForEventValidation(this.UniqueID); } if (onClick != null) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick); } } string s = AccessKey; if (s.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, s); } int i = TabIndex; if (i != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, i.ToString(NumberFormatInfo.InvariantInfo)); } if (_inputAttributes != null && _inputAttributes.Count != 0) { _inputAttributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); }
/// <summary> /// Sends the ToolCheckBox content to a provided HtmlTextoutput object, which writes the content to be rendered on the client. /// </summary> /// <param name="output">The HtmlTextoutput object that receives the server control content.</param> protected override void Render(HtmlTextWriter output) { bool useSpan = false; if (!Enabled) { output.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); useSpan = true; } if (BorderColorRollOver != Color.Empty && AllowRollOver) { output.AddAttribute(string.Format("onMouseover=\"this.style.borderColor='{0}'\"", Utils.Color2Hex(this.BorderColorRollOver)), null); output.AddAttribute(string.Format("onMouseout=\"this.style.borderColor='{0}'\"", Utils.Color2Hex(this.BorderColor)), null); } string toolTipText = ToolTip; if (toolTipText.Length > 0) { output.AddAttribute(HtmlTextWriterAttribute.Title, toolTipText); useSpan = true; } if (ControlStyleCreated) { System.Web.UI.WebControls.Style style = base.ControlStyle; style.AddAttributesToRender(output, this); useSpan = true; } if (Attributes.Count != 0) { System.Web.UI.AttributeCollection attributeCollection = Attributes; string attributeValue = attributeCollection["value"]; if (attributeValue != null) { attributeCollection.Remove("value"); } if (attributeCollection.Count != 0) { attributeCollection.AddAttributes(output); useSpan = true; } if (attributeValue != null) { attributeCollection["value"] = attributeValue; } } if (useSpan) { output.RenderBeginTag(HtmlTextWriterTag.Span); } if (this.ClientSideClick != string.Empty) { output.AddAttribute(HtmlTextWriterAttribute.Onclick, this.ClientSideClick); } /*if (this.ClientSideOver != string.Empty) * output.AddAttribute("onmouseover", this.ClientSideOver);*/ if (Text.Length == 0) { RenderInputTag(output, ClientID); } else if (TextAlign == System.Web.UI.WebControls.TextAlign.Left) { RenderLabel(output, Text, ClientID); RenderInputTag(output, ClientID); } else { RenderInputTag(output, ClientID); RenderLabel(output, Text, ClientID); } if (useSpan) { output.RenderEndTag(); } }
/// <summary> /// User By Control Designer /// </summary> /// <param name="writer"></param> public void RenderDropDownList(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Id, "span_" + this.ClientID); // render begin tag of wrapper SPAN writer.RenderBeginTag(HtmlTextWriterTag.Span); AddAttributesToRender(writer); // Make sure we are in a form tag with runat=server. if (Page != null) { Page.VerifyRenderingInServerForm(this); } bool renderWrapper = false; // On wrapper, render the style, if (ControlStyleCreated) { Style controlStyle = ControlStyle; if (!controlStyle.IsEmpty) { controlStyle.AddAttributesToRender(writer, this); renderWrapper = true; } } // And Enabled if (!IsEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); renderWrapper = true; } // And ToolTip string toolTip = ToolTip; if (toolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip); renderWrapper = true; } string onSelectedIndexChanged = string.Format("PostCommand_{0}()", base.ClientID); // And other attributes if (HasAttributes) { AttributeCollection attribs = Attributes; // remove value from the attribute collection so it's not on the wrapper string val = attribs["value"]; if (val != null) { attribs.Remove("value"); } // remove and save onclick from the attribute collection so we can move it to the input tag onSelectedIndexChanged = attribs["onchange"]; if (onSelectedIndexChanged != null) { // onClick = System.Web.UI.Design.Util.EnsureEndWithSemiColon(onClick); attribs.Remove("onchange"); } if (attribs.Count != 0) { attribs.AddAttributes(writer); renderWrapper = true; } if (val != null) { attribs["value"] = val; } } string clientID = base.ClientID; //ClientID; RenderSelectTag(writer, clientID, onSelectedIndexChanged); // render end tag of wrapper SPAN writer.RenderEndTag(); }
internal virtual void RenderInputTag(HtmlTextWriter writer, string clientID, string onClick) { if (clientID != null) { writer.AddAttribute(HtmlTextWriterAttribute.Id, clientID); } writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox"); if (UniqueID != null) { writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID); } if (_valueAttribute != null) { writer.AddAttribute(HtmlTextWriterAttribute.Value, _valueAttribute); } if (Checked) { writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked"); } if (!IsEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } if (Page != null && !Page.IsCallback && !Page.IsPostBack) { Page.ClientScript.RegisterForEventValidation(this.UniqueID); } if (onClick != null) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick); } string s = AccessKey; if (s.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, s); } int i = TabIndex; if (i != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, i.ToString(NumberFormatInfo.InvariantInfo)); } if (_inputAttributes != null && _inputAttributes.Count != 0) { _inputAttributes.AddAttributes(writer); } writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); }
public void NonStyleAttributes2 () { StateBag bag = new StateBag (true); AC ac = new AC (bag); StringWriter sr = new StringWriter (); HtmlTextWriter writer = new HtmlTextWriter (sr); ac.Add ("class", "classname"); ac.AddAttributes (writer); string str = sr.ToString (); Assert.AreEqual ("", str, "value1"); Assert.AreEqual (1, bag.Count, "count1"); writer = new HtmlTextWriter (sr); writer.RenderBeginTag (HtmlTextWriterTag.A); ac.AddAttributes (writer); writer.RenderEndTag (); Assert.AreEqual ("", str, "value2"); Assert.AreEqual (1, bag.Count, "count2"); }
/// <internalonly/> /// <devdoc> /// <para>Displays the <see cref='System.Web.UI.WebControls.CheckBox'/> on the client.</para> /// </devdoc> protected internal override void Render(HtmlTextWriter writer) { AddAttributesToRender(writer); // Make sure we are in a form tag with runat=server. if (Page != null) { Page.VerifyRenderingInServerForm(this); } bool renderWrapper = false; // On wrapper, render ---- attribute and class according to RenderingCompatibility if (!IsEnabled) { if (RenderingCompatibility < VersionUtil.Framework40) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); renderWrapper = true; } else if (!Enabled && !String.IsNullOrEmpty(DisabledCssClass)) { if (String.IsNullOrEmpty(CssClass)) { ControlStyle.CssClass = DisabledCssClass; } else { ControlStyle.CssClass = DisabledCssClass + " " + CssClass; } renderWrapper = true; } } // And Style if (ControlStyleCreated) { Style controlStyle = ControlStyle; if (!controlStyle.IsEmpty) { controlStyle.AddAttributesToRender(writer, this); renderWrapper = true; } } // And ToolTip string toolTip = ToolTip; if (toolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip); renderWrapper = true; } string onClick = null; // And other attributes if (HasAttributes) { AttributeCollection attribs = Attributes; // remove value from the attribute collection so it's not on the wrapper string val = attribs["value"]; if (val != null) { attribs.Remove("value"); } // remove and save onclick from the attribute collection so we can move it to the input tag onClick = attribs["onclick"]; if (onClick != null) { onClick = Util.EnsureEndWithSemiColon(onClick); attribs.Remove("onclick"); } if (attribs.Count != 0) { attribs.AddAttributes(writer); renderWrapper = true; } if (val != null) { attribs["value"] = val; } } // render begin tag of wrapper SPAN if (renderWrapper) { writer.RenderBeginTag(HtmlTextWriterTag.Span); } string text = Text; string clientID = ClientID; if (text.Length != 0) { if (TextAlign == TextAlign.Left) { // render label to left of checkbox RenderLabel(writer, text, clientID); RenderInputTag(writer, clientID, onClick); } else { // render label to right of checkbox RenderInputTag(writer, clientID, onClick); RenderLabel(writer, text, clientID); } } else { RenderInputTag(writer, clientID, onClick); } // render end tag of wrapper SPAN if (renderWrapper) { writer.RenderEndTag(); } }
protected internal override void Render(HtmlTextWriter writer) { this.AddAttributesToRender(writer); if (this.Page != null) { this.Page.VerifyRenderingInServerForm(this); } bool flag = false; if (!base.IsEnabled) { if (this.RenderingCompatibility < VersionUtil.Framework40) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); flag = true; } else if (!this.Enabled && !string.IsNullOrEmpty(WebControl.DisabledCssClass)) { if (string.IsNullOrEmpty(this.CssClass)) { base.ControlStyle.CssClass = WebControl.DisabledCssClass; } else { base.ControlStyle.CssClass = WebControl.DisabledCssClass + " " + this.CssClass; } flag = true; } } if (base.ControlStyleCreated) { Style controlStyle = base.ControlStyle; if (!controlStyle.IsEmpty) { controlStyle.AddAttributesToRender(writer, this); flag = true; } } string toolTip = this.ToolTip; if (toolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip); flag = true; } string str2 = null; if (base.HasAttributes) { System.Web.UI.AttributeCollection attributes = base.Attributes; string str3 = attributes["value"]; if (str3 != null) { attributes.Remove("value"); } str2 = attributes["onclick"]; if (str2 != null) { str2 = Util.EnsureEndWithSemiColon(str2); attributes.Remove("onclick"); } if (attributes.Count != 0) { attributes.AddAttributes(writer); flag = true; } if (str3 != null) { attributes["value"] = str3; } } if (flag) { writer.RenderBeginTag(HtmlTextWriterTag.Span); } string text = this.Text; string clientID = this.ClientID; if (text.Length != 0) { if (this.TextAlign == System.Web.UI.WebControls.TextAlign.Left) { this.RenderLabel(writer, text, clientID); this.RenderInputTag(writer, clientID, str2); } else { this.RenderInputTag(writer, clientID, str2); this.RenderLabel(writer, text, clientID); } } else { this.RenderInputTag(writer, clientID, str2); } if (flag) { writer.RenderEndTag(); } }
/// <summary> /// User By Control Designer /// </summary> /// <param name="writer"></param> public void RenderButton(HtmlTextWriter writer) { AddAttributesToRender(writer); // Make sure we are in a form tag with runat=server. if (Page != null) { Page.VerifyRenderingInServerForm(this); } bool renderWrapper = false; // On wrapper, render the style, if (ControlStyleCreated) { Style controlStyle = ControlStyle; if (!controlStyle.IsEmpty) { controlStyle.AddAttributesToRender(writer, this); renderWrapper = true; } } // And Enabled if (!IsEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); renderWrapper = true; } // And ToolTip string toolTip = ToolTip; if (toolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip); renderWrapper = true; } string onClick = string.Format("PostCommand_{0}()", ClientID); // And other attributes if (HasAttributes) { AttributeCollection attribs = Attributes; // remove value from the attribute collection so it's not on the wrapper string val = attribs["value"]; if (val != null) { attribs.Remove("value"); } // remove and save onclick from the attribute collection so we can move it to the input tag onClick = attribs["onclick"]; if (onClick != null) { attribs.Remove("onclick"); } if (attribs.Count != 0) { attribs.AddAttributes(writer); renderWrapper = true; } if (val != null) { attribs["value"] = val; } } string text = Text; string clientID = base.ClientID; //ClientID; RenderInputTag(writer, clientID, onClick, text); }
public void InitialNoBag7 () { AC ac = new AC (null); HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ()); ac.AddAttributes (writer); }
/// <summary> /// User By Control Designer /// </summary> /// <param name="writer"></param> public void RenderCheckBox(HtmlTextWriter writer) { AddAttributesToRender(writer); // Make sure we are in a form tag with runat=server. if (Page != null) { Page.VerifyRenderingInServerForm(this); } bool renderWrapper = false; // On wrapper, render the style, if (ControlStyleCreated) { Style controlStyle = ControlStyle; if (!controlStyle.IsEmpty) { controlStyle.AddAttributesToRender(writer, this); renderWrapper = true; } } // And Enabled if (!IsEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); renderWrapper = true; } // And ToolTip string toolTip = ToolTip; if (toolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, toolTip); renderWrapper = true; } string onClick = string.Format("PostCommand_{0}()", iclientID); // And other attributes if (HasAttributes) { AttributeCollection attribs = Attributes; // remove value from the attribute collection so it's not on the wrapper string val = attribs["value"]; if (val != null) { attribs.Remove("value"); } // remove and save onclick from the attribute collection so we can move it to the input tag onClick = attribs["onclick"]; if (onClick != null) { // onClick = System.Web.UI.Design.Util.EnsureEndWithSemiColon(onClick); attribs.Remove("onclick"); } if (attribs.Count != 0) { attribs.AddAttributes(writer); renderWrapper = true; } if (val != null) { attribs["value"] = val; } } writer.RenderBeginTag(HtmlTextWriterTag.Span); string text = Text; string clientID = iclientID; //ClientID; if (text.Length != 0) { if (TextAlign == TextAlign.Left) { // render label to left of checkbox RenderLabel(writer, text, clientID); RenderInputTag(writer, clientID, onClick); } else { // render label to right of checkbox RenderInputTag(writer, clientID, onClick); RenderLabel(writer, text, clientID); } } else { RenderInputTag(writer, clientID, onClick); } writer.RenderEndTag(); }
public void InitialBag1 () { StateBag bag = new StateBag (true); AC ac = new AC (bag); Assert.AreEqual (0, ac.Count, "count"); Assert.AreEqual (null, ac ["hola"], "item"); Assert.AreEqual (0, ac.Keys.Count, "keys"); ac.Add ("notexists", "invalid"); ac.Remove ("notexists"); ac.Remove ("notexists"); HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ()); ac.AddAttributes (writer); ac.Render (writer); Assert.AreEqual (0, writer.InnerWriter.ToString().Length, "length"); CssStyleCollection css = ac.CssStyle; Assert.AreEqual (0, css.Count, "csscount"); Assert.AreEqual (null, css ["hola"], "cssitem"); Assert.AreEqual (0, css.Keys.Count, "csskeys"); css.Add ("notexists", "invalid"); css.Remove ("notexists"); css.Remove ("notexists"); css.Add ("notexists", "invalid"); css.Clear (); Assert.AreEqual (0, css.Keys.Count, "csskeys2"); }