Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Maintain State With Dynamic Controls
Build a process controller to simplify multistep input.
by Garry McGlennon

April 2003 Issue

Technology Toolbox: VB.NET, ASP.NET

ASP.NET gives you the opportunity to create reusable custom controls that maintain state, and drag and drop them onto Web pages. This is a huge advantage in designing pages, because it lets you bring the Win32 programming model to the Web. ASP.NET also allows you to create the same controls dynamically at run time. Microsoft has done a good job, in general, of enabling you to create dynamic controls; however, things don't always work as planned. I'll discuss the issues you face when you create dynamic controls, and I'll show you how to address them. I'll also demonstrate the use of dynamic controls by showing you an example of a process controller; you can use the same technique for any multistep process.

You need only this line of code to create a control dynamically at run time:

Me.Panel1.Controls.Add(Page. _
   LoadControl("~/MyControl.ascx")

Figure A. House Dynamic Controls.

You must use the fully qualified path of the control you're loading; otherwise, you might get a "file not found" error. A good tip is to use the tilde (~) at the beginning, because it represents the root of the Web application when you use it with server-side controls.

You can add controls to any container control that supports the Controls collection, such as a Panel or Placeholder control. The DynamicControlHost.asx control you'll build later uses the Panel control (see Figure A). There's no visual content, because you add the content dynamically each time the page loads.

Figure B. Encapsulate Processes for Reuse.

Now I'll show you how to create a process controller that demonstrates the use of dynamic controls. It handles the series of steps or screens required to register someone on a Web site. You can use the finished control anywhere within the site by dragging and dropping it on a page. A traditional wizard-style interface that encapsulates the steps is the process controller's core (see Figure B).





Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home