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"); }
/// <summary> /// Removes custom binding attributes from a webcontrol to avoid them being rendered. /// </summary> private void RemoveBindingAttributes(IWebDataBound dataBound, WebControl wc) { AttributeCollection attributeCollection = wc.Attributes; attributeCollection.Remove(ATTR_BINDINGTARGET); attributeCollection.Remove(ATTR_BINDINGSOURCE); attributeCollection.Remove(ATTR_BINDINGTYPE); attributeCollection.Remove(ATTR_BINDINGDIRECTION); attributeCollection.Remove(ATTR_BINDINGFORMATTER); }
private static void RemoveAttributeInCol(string attKey, System.Web.UI.AttributeCollection attCol) { if (attCol[attKey] != null) { attCol.Remove(attKey); } }
internal static void WriteOnClickAttribute(HtmlTextWriter writer, HtmlControls.HtmlControl control, bool submitsAutomatically, bool submitsProgramatically, bool causesValidation) { AttributeCollection attributes = control.Attributes; string injectedOnClick = null; if (submitsAutomatically) { if (causesValidation) { injectedOnClick = Util.GetClientValidateEvent(control.Page); } } else if (submitsProgramatically) { if (causesValidation) { injectedOnClick = Util.GetClientValidatedPostback(control); } else { injectedOnClick = control.Page.GetPostBackClientEvent(control, ""); } } if (injectedOnClick != null) { string existingLanguage = attributes["language"]; if (existingLanguage != null) { attributes.Remove("language"); } writer.WriteAttribute("language", "javascript"); string existingOnClick = attributes["onclick"]; if (existingOnClick != null) { attributes.Remove("onclick"); writer.WriteAttribute("onclick", existingOnClick + " " + injectedOnClick); } else { writer.WriteAttribute("onclick", injectedOnClick); } } }
public void Count1() { StateBag bag = new StateBag(true); AC ac = new AC(bag); ac.Add("style", "padding: 0px; margin: 0px"); Assert.AreEqual(1, ac.Count, "AttributeCollection.Count"); Assert.AreEqual(2, ac.CssStyle.Count, "AttributeCollection.Count"); ac.Remove("style"); Assert.AreEqual(0, ac.Count, "AttributeCollection.Count"); Assert.AreEqual(0, ac.CssStyle.Count, "AttributeCollection.Count"); }
public static void RemoveKeyAttribute(ArrayList affectedControls) { if (affectedControls == null) { return; } int i; for (i = 0; i <= affectedControls.Count - 1; i++) { System.Web.UI.AttributeCollection ac = (System.Web.UI.AttributeCollection)affectedControls[i]; ac.Remove(Services.Localization.Localization.KeyName); } }
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); }
/// <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"); }
public void InitialNoBag9() { AC ac = new AC(null); ac.Remove("hola"); }
/// <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(); } }
public void Count1 () { StateBag bag = new StateBag (true); AC ac = new AC (bag); ac.Add ("style", "padding: 0px; margin: 0px"); Assert.AreEqual (1, ac.Count, "AttributeCollection.Count"); Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count"); ac.Remove ("style"); Assert.AreEqual (0, ac.Count, "AttributeCollection.Count"); Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count"); }
/// <summary> /// Retrieves custom binding attributes from a webcontrol and adds a new binding /// instance to the container's <see cref="UserControl.BindingManager"/> if necessary. /// </summary> private void BindControl(IWebDataBound dataBound, WebControl theControl) { // special handling of adapted controls DataBindingAdapter adapterControl = theControl as DataBindingAdapter; Control wc = (adapterControl != null && adapterControl.WrappedControl != null) ? adapterControl.WrappedControl : theControl; AttributeCollection attributeCollection = theControl.Attributes; string bindingTarget = attributeCollection[ATTR_BINDINGTARGET]; // at least a BindingTarget must be specified if (bindingTarget == null) { return; } attributeCollection.Remove(ATTR_BINDINGTARGET); // determine direction BindingDirection bindingDirection = BindingDirection.Bidirectional; string strBindingDirection = attributeCollection[ATTR_BINDINGDIRECTION]; if (strBindingDirection != null) { bindingDirection = (BindingDirection)Enum.Parse(typeof(BindingDirection), strBindingDirection); } // determine BindingSource string bindingSource = attributeCollection[ATTR_BINDINGSOURCE]; if (bindingSource == null) { bindingSource = AutoProbeSourceProperty(wc); } attributeCollection.Remove(ATTR_BINDINGSOURCE); // get formatter if any IFormatter bindingFormatter = null; string bindingFormatterName = attributeCollection[ATTR_BINDINGFORMATTER]; if (bindingFormatterName != null) { bindingFormatter = (IFormatter)dataBound.ApplicationContext.GetObject(bindingFormatterName); attributeCollection.Remove(ATTR_BINDINGFORMATTER); } // determine source expression string containerName = dataBound.UniqueID; string controlName = wc.UniqueID; string relativeControlName = null; if (dataBound is System.Web.UI.Page) { relativeControlName = string.Format("FindControl('{0}')", controlName); } else if ((Control)dataBound != this.NamingContainer) { relativeControlName = (controlName.StartsWith(containerName)) ? controlName.Substring(containerName.Length + 1) : controlName; relativeControlName = string.Format("FindControl('{0}')", relativeControlName); } else { relativeControlName = wc.ID; } // if no bindingSource, expression evaluates to the bound control bindingSource = (StringUtils.HasLength(bindingSource)) ? relativeControlName + "." + bindingSource : relativeControlName; Log.Debug( string.Format("binding control '{0}' relative to '{1}' using expression '{2}'", controlName, containerName, bindingSource)); //get bindingType if any IBinding binding = null; string bindingTypeName = attributeCollection[ATTR_BINDINGTYPE]; if (bindingTypeName == null) { bindingTypeName = AutoProbeBindingType(wc); } // get messageId and errorProviders list string messageId = attributeCollection[ATTR_MESSAGEID]; string errorProvidersText = attributeCollection[ATTR_ERRORPROVIDERS]; string[] errorProviders = null; if (StringUtils.HasLength(errorProvidersText)) { errorProviders = (string[])new Spring.Core.TypeConversion.StringArrayConverter().ConvertFrom(errorProvidersText); } // add binding to BindingManager if (bindingTypeName != null) { binding = CreateBindingInstance(bindingTypeName, bindingSource, bindingTarget, bindingDirection, bindingFormatter); binding = dataBound.BindingManager.AddBinding(binding); } else { binding = dataBound.BindingManager.AddBinding(bindingSource, bindingTarget, bindingDirection, bindingFormatter); } // set error message if (StringUtils.HasLength(messageId)) { binding.SetErrorMessage(messageId, errorProviders); } }
public void InitialNoBag9 () { AC ac = new AC (null); ac.Remove ("hola"); }
/// <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); }
/// <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(); }
private void AddAttribute(AttributeCollection a, string eventName, string imageUrl) { try { a.Remove(eventName); } finally { a.Add(eventName, "this.src='" + imageUrl + "'"); } }