Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have single button in aspx. if i clik a button textbox will create at runtime. Then again i click the button aanother textbox will create. toataly 1 + 1 = 2. But the problem is single text box only created. pls help me.
Posted
Comments
DaveAuld 3-Oct-12 4:46am    
What code did you try with?

try this

VB
'declare static varible for id
       Static id As Integer

       'In the button click event function

       'write a code

       Dim txt = New TextBox()
       txt.Id = "txt_" + id
       txt.ClientIDMode = UI.ClientIDMode.Static
       form1.Controls.Add(txt)
       id = id + 1
 
Share this answer
 
Public Class TextBox1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Session("count") = 0
Dim table As Table = New Table()
table.ID = "Tab1"
Page.Form.Controls.Add(table)
Dim i As Integer
For i = 0 To 3
Dim text As TextBox = New TextBox()
text.ID = "text_" & i
Page.Form.Controls.Add(New TextBox())
Session("count") = Session("count") + 1
Next
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


If Session("count") > 0 Then
For i1 As Integer = 0 To Session("count") - 1
Dim text1 As TextBox = New TextBox()
text1.ID = "text_" & i1
Page.Form.Controls.Add(New TextBox())
If i1 >= 4 Then
If (i1 Mod 4) = 0 Then
Response.Write("

")
End If
End If


Next
End If
Response.Write("

")
For i = 0 To 3
Dim text As TextBox = New TextBox()
text.ID = "text_" & i
Page.Form.Controls.Add(New TextBox())
Session("count") = Session("count") + 1
Next
End Sub



End Class
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900