0

how to create as many textbox at runtime on button click. And also what will be the id's of textboxes created at runtime and send the value of textbox to next page through session

please someone help me. I've stucked at this point for many days but could not solve it.

thanks

prasanna

2 Answers 2

1

To create a textbox at runtime you set it up in your Page_Init like this:

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)

    TextBox2 = New TextBox()
    TextBox2.ID = "TextBox2"
    TextBox2.Style("Position") = "Absolute"
    TextBox2.Style("Top") = "60px"
    TextBox2.Style("Left") = "100px"
    Form1.Controls.Add(TextBox2)

End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

Creating dynamic controls in ASP.Net can be a little tricky. The reason is any control created after the Page_Init will not be stored in the View State. This means for controls created after the Page_Init, on the page post back the data entered into the control will be lost. Furthermore events will not be fire for the those controls.

A good three part article can be found here
https://web.archive.org/web/20211020131055/https://www.4guysfromrolla.com/articles/081402-1.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.