2. 2222
Objectives
You will be able to
Dynamically add controls to a page.
Dynamically alter properties of controls.
Use the Panel control as a container for other controls.
3. 3
Panel Demo
Example of dynamically creating controls and
adding them to a page.
Also using a Panel control as a container for other controls.
An alternative way to put new HTML onto a
page at run time.
Rather than outputting HTML directly, we add
control objects to the internal representation of the
page in server memory.
They output HTML during the “render” phase of the
page life cycle on the server.
4. Adding ASPX Controls Dynamically
Think about what would happen if we
used Response.Write( ) to add an ASPX
control to the page.
To add a dynamically created ASPX
control to the page we have to add it to
the data structure in server memory that
is the internal representation of the page.
5. 5
Panel Demo
The Panel control is a container for other
controls.
Use it to put a border around a group of
related controls.
Can set styling, position, and visibility for the
entire group by setting properties of the
panel.
Provides a convenient way to add controls to
the page dynamically.
6. 6
Panel Demo
We will create a page with a panel control
containing some static text.
Dropdown lists permit the user to
Add 1 – 4 labels to the panel.
Add 1 – 4 textboxes to the panel.
CheckBox permits user to hide the panel.
17. 17
Dynamic Controls
Let’s add some controls that will have the effect of
adding other controls to the panel dynamically.
A new DropDown List will add a specified number of
labels to the panel.
Options for 0 – 4 labels
A second new DropDownList will add a specified
number of CheckBoxes.
Options for 0 – 4 CheckBoxes
Also a CheckBox that will hide the panel
And a Button to refresh the panel
31. Summary
We can create ASPX controls
dynamically using C# code and add them
to the page before the page is translated
into HTML.
We can dynamically modify controls
defined in the .aspx file in the Page_Load
event handler.
End of Presentation