asp.net label creation

  • Thread starter Thread starter ahmed
  • Start date Start date
A

ahmed

hi .. i am trying to make a webform where i can create label with out
actually going to the toolbox and dargging the thing over the webform in
design mode.

Is there a way to do that
i tried doing this

Imports System

Imports System.Windows.Forms

dim label1 as new label()
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Set the ImageList to use for displaying an image.

'label1.ImageList = imageList1

' Use the second image in imageList1.

label1.ImageIndex = 1

' Align the image to the top left corner.

label1.ImageAlign = ContentAlignment.TopLeft

' Specify that the text can display mnemonic characters.

label1.UseMnemonic = True

' Set the text of the control and specify a mnemonic character.

label1.Text = "First &Name:"

' Set the size of the control based on the PreferredHeight and
PreferredWidth values.

'label1.Size = New Size(label1.PreferredHeight, label1.PreferredWidth)

label1.BringToFront()

Me.label1.Size = New System.Drawing.Size(232, 20)


... but when i run the asp code .. this thing doesn't appear in my browser ..
what must i do .. please help ..
 
ahmed said:
hi .. i am trying to make a webform where i can create label with out
actually going to the toolbox and dargging the thing over the webform
in design mode.

Is there a way to do that
i tried doing this

Imports System

Imports System.Windows.Forms

dim label1 as new label()
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Set the ImageList to use for displaying an image.

'label1.ImageList = imageList1

' Use the second image in imageList1.

label1.ImageIndex = 1

' Align the image to the top left corner.

label1.ImageAlign = ContentAlignment.TopLeft

' Specify that the text can display mnemonic characters.

label1.UseMnemonic = True

' Set the text of the control and specify a mnemonic character.

label1.Text = "First &Name:"

' Set the size of the control based on the PreferredHeight and
PreferredWidth values.

'label1.Size = New Size(label1.PreferredHeight, label1.PreferredWidth)

label1.BringToFront()

Me.label1.Size = New System.Drawing.Size(232, 20)


.. but when i run the asp code .. this thing doesn't appear in my
browser .. what must i do .. please help ..

It's called "creating a label dynamically" or "on-the-fly".

You forgot to add the label to your page:
Page.Controls.Add(Label1)

(You could also add it to a Panel or to a PlaceHolder web control).
 
Back
Top