Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add <br/> and <hr/> to page in codebehind asp.net

I am adding labels to the page programmaticaly(codebehind file c#)

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 labels.How to do that?

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

doesn't work.

like image 206
Nurlan Avatar asked Nov 27 '22 07:11

Nurlan


1 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
like image 66
Waqar Janjua Avatar answered Dec 06 '22 17:12

Waqar Janjua