0

Here is my code for creating the textbox and label from code

        int i = 0;
        Label lbl = new Label();
        lbl.Text = "Label - " + i.ToString();
        lbl.ID = "Label - " + i.ToString();

        TextBox txt = new TextBox();
        txt.Text = "txt - " + i.ToString();

        data.Controls.Add(lbl);
        data.Controls.Add(txt);

Is it possible I add a new line after the data.Controls.Add(txt);?

I tried to use Environment.NewLine but its not working. anyone have any idea how to do it?

Spider man
  • 3,224
  • 4
  • 30
  • 42
Lst Patrick
  • 123
  • 6
  • 19
  • I'm not sure, but I think that labels can't be multiline. But you can set your textbox to be multiline and then use *System.Environment.NewLine*. – Rob Jun 09 '15 at 10:56
  • @Robert you may be wrong! You can do it (only tested in WPF) with label.Content += "\n This is a new Line". So he is using asp.net and i have no experience in it - moreover in asp.net i assume that a label has no .Content so it would be label.Text += "\n new Line" – Jens Jun 09 '15 at 10:58
  • What is the data object you use here? The question is not about Label or TextBox, it is about the data object that we have no definition of. – Belurd Jun 09 '15 at 11:02
  • 1
    Since it seems that you are a beginner in ASP.NET development, why do you start with dynamic controls at all? Use the aspx to declare your controls. You can control visiblity from codebehind if that's what you want. Maybe you want to use a web-databound control like `Repeater` or `GridView` if you habe a loop. You can also use a `UserControl` if you want to wrap your two control in one. On that way you can reuse it wherever you want. – Tim Schmelter Jun 09 '15 at 11:11

4 Answers4

1
data.Controls.Add(new LiteralControl("<br/>"));

Add this for new line

sriman reddy
  • 763
  • 8
  • 22
0

Add a Literal Control in between your two controls for line space. Programatically you can do it.

Set Literal Control's Mode property to PassThrough For Example :

Literal myLiteral = new Literal();
myLiteral.Id="lit_newline"
myLiteral.Mode = "PassThrough";
data.Controls.Add(myLiteral);

Then Add this control in between your textbox and label control

Also you can do like this

data.Controls.Add(new LiteralControl("<br />")); 

And If you want, you can apply css to your textbox without adding the literal control which will increase the height - as answered by user : bgs264

Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
  • refer this http://stackoverflow.com/questions/2118316/how-can-i-add-a-line-break-or-html-inside-of-a-panel and this http://stackoverflow.com/questions/830304/hw-to-create-line-breaks-between-dynamically-generated-labels-in-a-placeholder – Chandan Kumar Jun 09 '15 at 11:13
  • 1
    @srimanreddy: he has not copied your answer, he uses `
    ` and you `
    `. He also posted one minute earlier.
    – Tim Schmelter Jun 09 '15 at 11:14
  • also look here : http://stackoverflow.com/questions/14463766/add-line-breaks-to-literal-controls – Chandan Kumar Jun 09 '15 at 11:17
0

You should use CSS if it's purely for presentation.

Add .CssClass = "TextboxSpace" to the textbox
Add a css file to the project (or add a new style to an existing one) something like

.TextboxSpace {
 margin-bottom: 20px;
}
bgs264
  • 4,572
  • 6
  • 38
  • 72
-1

Are you saying the space between the two controls.. If this is the case, you can set the location for the next control such that there is a empty space after that text.

Nila
  • 37
  • 5