I'm adding controls to my page in code and needed <br> between the controls to put them on new lines. I just want to write <br>'s to the page without using the HtmlAnchor control. Is there a better way than this?
Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
HtmlAnchor an1 = new HtmlAnchor();
HtmlAnchor an2 = new HtmlAnchor();
l1.Text = "Label1";
l2.Text = "Label2";
l3.Text = "Label3";
an1.InnerHtml = an2.InnerHtml = "<br>";
Page.Controls.Add(l1);
Page.Controls.Add(an1);
Page.Controls.Add(l2);
Page.Controls.Add(an2);
Page.Controls.Add(l3);You could encapsulate the controls inside User Controls, and simply have a <br> appended in the HTML there.
You could encapsulate the controls inside User Controls, and simply have a <br> appended in the HTML there.
OK now I have the controls in a user control so how can I append the HTML? I still couldn't think of a better way than what I already have.
Just right click and go into the HTML Source for the user control, and put <br> at the bottom of it :)
But the <br> needs to be loaded dynamically between every element inside the user control. I thought I could just use some sort of HTML writer to write between the elements on the page.
Create a Generic Html Control HtmlControl namespace set it up as a <br> and add it between the controls.
If it needs to be added for every added control override the add/added control member and do it there.
Take the time to scroll down your toolbox until you find the Literal Control. That control is rarely seen because you normally have to scroll down to it. You see, it literally outputs what you put into it. So, you can put html into it, and it spits it out into the response stream just as you had put it in the .Text property. This is useful if you want to display html content from a database, or do exactly what you want to do. Example:
Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
LiteralControl lc1= new LiteralControl ();
LiteralControl lc2= new LiteralControl ();
l1.Text = "Label1";
l2.Text = "Label2";
l3.Text = "Label3";
lc1.Text= lc2.Text= "<br>";
Page.Controls.Add(l1);
Page.Controls.Add(lc1);
Page.Controls.Add(l2);
Page.Controls.Add(lc2);
Page.Controls.Add(l3);
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment