how to put two textboxes under each other?

C

Cas

Hi,

I create two textboxes and two labels.
My problem is that: i want to get them under each other instead of beside
each other.
My second problem is that i want to have more spaces between the label and
the textbox.
Is there a way to do that?
Thanks
Cas

Dim b As New Label
b.Text = "label" & Space(7) 'space doesn't work
form1.Controls.Add(b)
Dim a = New TextBox
form1.Controls.Add(a)

Dim bb As New Label
bb.Text = "label" & Space(7)
form1.Controls.Add(bb)
Dim aa = New TextBox
form1.Controls.Add(aa)
 
M

Mythran

Cas said:
Hi,

I create two textboxes and two labels.
My problem is that: i want to get them under each other instead of beside
each other.
My second problem is that i want to have more spaces between the label and
the textbox.
Is there a way to do that?
Thanks
Cas

Dim b As New Label
b.Text = "label" & Space(7) 'space doesn't work
form1.Controls.Add(b)
Dim a = New TextBox
form1.Controls.Add(a)

Dim bb As New Label
bb.Text = "label" & Space(7)
form1.Controls.Add(bb)
Dim aa = New TextBox
form1.Controls.Add(aa)

Is this for a windows app or for a web app?

Mythran
 
C

Cas

It's for using it with asp.net. I also don't know how to use the style
"position: absolute" and left="..px" ...
Thanks again
 
M

Mythran

Cas said:
It's for using it with asp.net. I also don't know how to use the style
"position: absolute" and left="..px" ...
Thanks again

Personally, I would use absolute positioning...instead, while dynamically
adding the label controls, you need to add a LiteralControl in between the
textbox and the label #2. The LiteralControl would contain a "<br>" tag ..

HTH,
Mythran
 
A

André

My problrm is that i have to create a unknown number of texboxes, and labels
(the amount is fetched from a database), and i want them to be displayed
more or less correctly ....
 
M

Mythran

Mythran said:
Personally, I would use absolute positioning...instead, while dynamically
adding the label controls, you need to add a LiteralControl in between the
textbox and the label #2. The LiteralControl would contain a "<br>" tag
..

HTH,
Mythran

That should read, "Personally, I would NOT use ..."

:p

Mythran
 
M

Mythran

André said:
My problrm is that i have to create a unknown number of texboxes, and
labels (the amount is fetched from a database), and i want them to be
displayed more or less correctly ....


How do you mean "more or less correctly..."? Do you want them displayed
top-down or left-right? Do you want something like:

Label : TextBox
Label : TextBox
??

If so, then the following should work:

Dim frm As HtmlForm = Me.FindControl("form1") ' gave the form an id
of 'form1'
Dim lbl As Label
Dim lit As LiteralControl
Dim txt As TextBox

' Create first control set.
lbl = New Label()
lbl.Text = "Label #1: "
frm.Controls.Add(lbl)
txt = New TextBox()
txt.ID = "txtBox1"
frm.Controls.Add(txt)
lit = New LiteralControl("<br>")
frm.Controls.Add(lit)

' Create second control set.
lbl = New Label()
lbl.Text = "Label #2: "
frm.Controls.Add(lbl)
txt = New TextBox()
txt.ID = "txtBox2"
frm.Controls.Add(txt)
lit = New LiteralControl("<br>")
frm.Controls.Add(lit)

HTH :)

Mythran
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

I would put the label and the field in a block container, i.e. a div
tag. I would set a class on the div tag so that I could use CSS to
format them.

Resulting HTML:

<div class="FormItem">
<label for="someId"></label>
<input type="text" id="someId" />
</div>

CSS:

..FormItem { margin: 3px 0; }
..FormItem label { float: left; width: 150px; }
..FormItem input { float: left; width: 150px; }

I don't think that the Label control creates a real label tag, though.
You would have to use an HtmlGenericControl for that, just as for the
div tag.
 
C

Cas

Thanks

Göran Andersson said:
I would put the label and the field in a block container, i.e. a div tag. I
would set a class on the div tag so that I could use CSS to format them.

Resulting HTML:

<div class="FormItem">
<label for="someId"></label>
<input type="text" id="someId" />
</div>

CSS:

.FormItem { margin: 3px 0; }
.FormItem label { float: left; width: 150px; }
.FormItem input { float: left; width: 150px; }

I don't think that the Label control creates a real label tag, though. You
would have to use an HtmlGenericControl for that, just as for the div tag.
 
C

Cas

Thanks

Mythran said:
How do you mean "more or less correctly..."? Do you want them displayed
top-down or left-right? Do you want something like:

Label : TextBox
Label : TextBox
??

If so, then the following should work:

Dim frm As HtmlForm = Me.FindControl("form1") ' gave the form an id
of 'form1'
Dim lbl As Label
Dim lit As LiteralControl
Dim txt As TextBox

' Create first control set.
lbl = New Label()
lbl.Text = "Label #1: "
frm.Controls.Add(lbl)
txt = New TextBox()
txt.ID = "txtBox1"
frm.Controls.Add(txt)
lit = New LiteralControl("<br>")
frm.Controls.Add(lit)

' Create second control set.
lbl = New Label()
lbl.Text = "Label #2: "
frm.Controls.Add(lbl)
txt = New TextBox()
txt.ID = "txtBox2"
frm.Controls.Add(txt)
lit = New LiteralControl("<br>")
frm.Controls.Add(lit)

HTH :)

Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top