You must Sign In to post a response.
  • Category: JQuery

    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.
  • #755718
    You can use following code snippet for dynamically create control and set id for control in asp.net in VB.Net

    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

  • #755744
    Please check this sample code for a link button




    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");
    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #760998
    Hi

    You can try this code for dynamic control create


    TextBox txt = new TextBox();
    txt.ID = "TxtName";
    txt.Text = "Name";
    form1.Controls.Add(txt);

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments