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"); }
private void RenderGotoPage(HtmlTextWriter writer, int totalPages) { WebControl webControl = new WebControl(HtmlTextWriterTag.Span); webControl.Attributes.Add("class", this.SkipPanelCssClass); ControlCollection controls = webControl.Controls; object arg = this.PageIndex; string arg2 = totalPages.ToString(CultureInfo.InvariantCulture); int num = this.TotalRecords; controls.Add(new LiteralControl($"第{arg}/{arg2}页 共{num.ToString(CultureInfo.InvariantCulture)}记录")); WebControl webControl2 = new WebControl(HtmlTextWriterTag.Input); webControl2.Attributes.Add("type", "text"); webControl2.Attributes.Add("class", this.SkipTxtCssClass); System.Web.UI.AttributeCollection attributes = webControl2.Attributes; num = this.PageIndex; attributes.Add("value", num.ToString(CultureInfo.InvariantCulture)); webControl2.Attributes.Add("size", "3"); webControl2.Attributes.Add("id", "txtGoto"); webControl.Controls.Add(webControl2); webControl.Controls.Add(new LiteralControl("页")); WebControl webControl3 = new WebControl(HtmlTextWriterTag.Input); webControl3.Attributes.Add("type", "button"); webControl3.Attributes.Add("class", this.SkipBtnCssClass); webControl3.Attributes.Add("value", "确定"); webControl3.Attributes.Add("onclick", $"location.href=AppendParameter('{this.PageIndexFormat}', $.trim($('#txtGoto').val()));"); webControl.Controls.Add(webControl3); webControl.RenderControl(writer); }
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> /// This will add or modify an HTML attribute. If the attribute does not exist, it will be added. /// If the attribute exists, and it contains the value of attrValue, it is left unchanged. /// If the attribute exists, but does not contain the value of attrValue, attrValue is appended to the attribute's value /// </summary> public static void AddAttribute(AttributeCollection attributes, string attrKey, string attrValue) { string existingValue = attributes[attrKey]; if (string.IsNullOrEmpty(existingValue)) { attributes.Add(attrKey, attrValue); } else { if (!existingValue.Contains(attrValue)) attributes[attrKey] += attrValue; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["name"] != null) { } else { Response.Redirect("webform1.aspx"); } if (Session["type"].ToString() == "false") { TextBox1.Visible = false; Button1.Visible = false; } try { string DBHost = "127.0.0.1"; string DBName = "base"; string DBUserName = "******"; string DBPassword = "******"; string Conn_String = "server=" + DBHost + ";uid=" + DBUserName + ";password="******";database=" + DBName + ";"; MySqlConnection Conn = new MySqlConnection(Conn_String); Conn.Open(); MySqlCommand cmd; cmd = new MySqlCommand("SELECT link FROM live ORDER BY ID DESC LIMIT 1;", Conn); r = (String)cmd.ExecuteScalar(); //Label1.Text = r; // frame1.Attributes.Add("src", "https://www.youtube.com/embed/JGwWNGJdvx8"); System.Web.UI.AttributeCollection aCol = frame1.Attributes; aCol.Add("src", r); Conn.Close(); } catch (Exception eX) { //Label1.Text += eX.ToString(); } }
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); }
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"); }
public void InitialNoBag5() { AC ac = new AC(null); ac.Add("att", "value"); }
public void InitialNoBag5 () { AC ac = new AC (null); ac.Add ("att", "value"); }
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 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"); }
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"); }
private void AddAttribute(AttributeCollection a, string eventName, string imageUrl) { try { a.Remove(eventName); } finally { a.Add(eventName, "this.src='" + imageUrl + "'"); } }