Imports System.Data
Imports System.Data.OleDb
Public Class ControlAdd
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'*** Create New Textbox ***'
Dim i As Integer = 0
Dim ctrlBox As TextBox
For i = 1 To 5
ctrlBox = New Textbox
With ctrlBox
.Name = "txtbox" & i
End With
Me.pnlMain1.Controls.Add(ctrlBox)
Next
End Sub
End Class
Code (C#)
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.OleDb;
public class ControlAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
//*** Create New Textbox ***'
int i = 0;
TextBox ctrlBox = default(TextBox);
for (i = 1; i <= 5; i++) {
ctrlBox = new Textbox();
var _with1 = ctrlBox;
_with1.Name = "txtbox" + i;
this.pnlMain1.Controls.Add(ctrlBox);
}
}
public ControlAdd()
{
Load += Page_Load;
}
}