Dynamically create control and set id for control in asp.net
Hi,how to create dynamic control and set id for that control using jquery.
Under Page Init
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
' Create dynamic controls here.
TextBox1 = New TextBox()
TextBox1.ID = "TextBox1"
TextBox1.Style("Position") = "Absolute"
TextBox1.Style("Top") = "25px"
TextBox1.Style("Left") = "100px"
Form1.Controls.Add(TextBox1)
InitializeComponent()
End Sub
Text properties under text load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
TextBox1.Text = "TextBox1"
End If
End Sub
TextBox TextChanged events
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
Dim txtBoxSender As TextBox
Dim strTextBoxID As String
txtBoxSender = CType(sender, TextBox)
strTextBoxID = txtBoxSender.ID
Select Case strTextBoxID
Case "TextBox1"
Label3.Text = "TextBox1 text was changed"
End Select
End Sub
protected void Page_Load(object sender, EventArgs e)
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnk" + 1;
lnk.Text = "more1";
lnk.Click += new EventHandler(LinkButton3_Click);
form1.Controls.Add(lnk);
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Write("Link Button Clicked");
}
TextBox txt = new TextBox();
txt.ID = "TxtName";
txt.Text = "Name";
form1.Controls.Add(txt);