and
to the page in codebehind asp.net I am adding tags to the programmaticaly page (C # codebehind file) Label label1 = new ...">

Add <br/ "> and <hr / "> to the page in codebehind asp.net

I am adding tags to the programmaticaly page (C # codebehind file)

Label label1 = new Label(); label1.Text = "abc"; this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add(label1); Label label2 = new Label(); label2.Text = "def"; this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add(label2); 

I want to add hr and br between these shortcuts. How to do it?

 this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add("<hr/>"); 

does not work.

+4
source share
4 answers
 Label label1 = new Label(); label1.Text = "Test 1"; form1.Controls.Add(label1); form1.Controls.Add(new Literal() { ID="row", Text="<hr/>" } ); Label label2 = new Label(); label2.Text = "Test 2"; form1.Controls.Add(label2); Output: Test 1 --------------------------------------------------------------------------------- Test 2 
+13
source

Add LiteralControl :

 this.Page.Form.FindControl("ContentPlaceHolder1") .Controls.Add(new LiteralControl("<hr/>")); 
+6
source

You can use HtmlGenericControl

  var hrControl = new HtmlGenericControl("hr") this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add(hrControl); 
+6
source

you can use a literal control

 Literal c = new Literal(); c.Text = "<hr />; 
+4
source

All Articles