Skip Navigation LinksASP.Net 2.0 Training : ASP.Net PlaceHolder
Banner for ASP.Net 2.0 training classes in Visual Basic 2005 

Skip Navigation Links
ASP.Net 2.0 Training
VS File Management
ASP.Net Image
ASP.Net Checkbox
ASP.Net ImageButton
ASP.Net RadioButton
ASP.Net Literal
ASP.Net Panel
ASP.Net LinkButton
ASP.Net Calendar
ASP.Net BulletedList
ASP.Net FileUpload
ASP.Net User Controls
ASP.Net PlaceHolder
ASP.Net Lists
ASP.Net CheckBoxList
ASP.Net DropDownList
ASP.Net Data Access
ASP.Net DetailsView
ASP.Net FormView
ASP.Net Repeater Control
ASP.Net:Master Pages
Sending EMail
MultiView
Tabbed MultiView
ASP.Net:Wizard Control
Login Controls 1
ASP.Net:Site Navigation
ASP.Net:Classes
ASP.Net:SQLDataSource Control
ASP.Net:Error Handling
ASP.Net:dataTables
ASP.Net:datasets

Visit my other site:

Free Flash 8 tutorials and training

Free Dreamweaver Video Tutorials

Free PHP Training




If you like this site please link to it


Placeholder

The placeholder control saves a spot for you to programmatically add or remove controls.

You can add or remove as many controls as you want to the placeholder control

Use the Add method to add controls to the placeholder

Use the remove method to remove them

  • Open Visual Studio
  • Add a new webform
  • Name it Placeholder.aspx
  • Click the Add button
  • Select the Design View
  • Add 3 RadioButton controls
    • Name then
      • Opttextbox
      • Optlabel
      • Optbutton
    • Set the text properties to
      • Textbox
      • Label
      • Button
    • Set the groupName of them all to controlType
    • Set the autoPostback properties to true for all 3
  • Add a button control
    • Set the name to btnSubmit
    • Set the text to Submit
  • Add a Placeholder control
    • Name it myPlaceholder

  • Double-click the button and add this code:

If optTextbox.Checked Then

myPlaceholder.Controls.Add(textbox1)

textbox1.Text = ""

End If

If optLabel.Checked Then

myPlaceholder.Controls.Add(label1)

label1.Text = "Hello World"

End If

If optButton.Checked Then

myPlaceholder.Controls.Add(button1)

button1.Text = "Submit"

End If

  • Above the subroutine add this code:

Dim button1 As Button = New Button()

Dim textbox1 As TextBox = New TextBox()

Dim label1 As Label = New Label()

 

Code Example:

1

Dim button1 As Button = New Button()

2

Dim textbox1 As TextBox = New TextBox()

3

Dim label1 As Label = New Label()

Explanation:

1

Dynamically creates a button control in memory

2

Dynamically creates a textbox control in memory

3

Dynamically creates a label control in memory


Code Example:

1

If optTextbox.Checked Then

2

myPlaceholder.Controls.Add(textbox1)

3

textbox1.Text = ""

4

End If

5

If optLabel.Checked Then

6

myPlaceholder.Controls.Add(label1)

7

label1.Text = "Hello World"

8

End If

9

If optButton.Checked Then

10

myPlaceholder.Controls.Add(button1)

11

button1.Text = "Submit"

12

End If

Explanation:

1

Check to see if the first radioButton is checked

2

If it is checked add the textbox control that was created dynamically to the controls collection of the placeholder

3

Erase the default text on the textbox

4

End the if statement

5

Check to see if the second radioButton is checked

6

If it is checked add the label control that was created dynamically to the controls collection of the placeholder

7

Change the default text on the label to Hello World

8

End the if statement

9

Check to see if the third radioButton is checked

10

If it is checked add the button control that was created dynamically to the controls collection of the placeholder

11

Change the default text on the button to Submit

12

End the if statement


      ASP.Net 2.0 tutorials & training