Click here to Skip to main content
15,896,348 members
Articles / Web Development / ASP.NET

Dynamically Created Controls in ASP.NET

Rate me:
Please Sign up or sign in to vote.
3.23/5 (35 votes)
27 Aug 2004CPOL1 min read 312.5K   7.3K   60  
How to dynamically create controls in an ASP.NET page.
<%@ Page language="c#" Codebehind="DynamicControls.aspx.cs" AutoEventWireup="false" Inherits="WebTest.DynamicControls"  %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>Dynamic Controls</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="C#" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:button id="cmdAdd" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 48px" runat="server"
				Text="Add Button"></asp:button><asp:textbox id="TextBox1" style="Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 96px" runat="server"></asp:textbox><asp:button id="Button1" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 96px" runat="server"
				Text="Button 1"></asp:button><asp:label id="lblResult" style="Z-INDEX: 104; LEFT: 336px; POSITION: absolute; TOP: 40px"
				runat="server" Width="136px"></asp:label><asp:label id="lblText" style="Z-INDEX: 105; LEFT: 336px; POSITION: absolute; TOP: 72px" runat="server"
				Width="136px"></asp:label>
			<asp:Label id="Label1" style="Z-INDEX: 106; LEFT: 336px; POSITION: absolute; TOP: 112px" runat="server"
				Width="272px" Height="88px" Font-Size="Larger" ForeColor="Blue">Click "Add Button" to add controls.<br>
			Click buttons and type some text to check event handlers</asp:Label></form>
	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Israel Israel
Leon works as Chief Architect at SRL Group. He leads architectural design and development of various enterprise level projects.
You can meet him on user groups, conferences and forums dedicated to Architecture, ASP.NET, Team System etc. or join him for the next white water rafting adventure

Comments and Discussions