We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to add another text box programatically on a textchanged evnt of a text box in a place holder

Please give a solution for me for the following code. here i have a text box already after that when a text box value is changed and a new textbox will come in the place holder with postback property=true. After that when iam typing a value in that textbox (new one) and pressing the tab then the form will postback. but me want a new text box will generate there as the first text box textchanged event. how can me resolve the prob. Please help me

test.aspx
***************
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" Inherits="partyroute.test"%>



test







cellPadding="1" width="300" border="1">














***************************
test.vb
************
Public Class test
Inherits System.Web.UI.Page

Dim k As Integer = 2

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
Private Sub InitializeComponent()

End Sub
Protected WithEvents a1 As System.Web.UI.WebControls.TextBox
Protected WithEvents ph As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents lb As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
ViewState("prd") = 1
lb.Text = ViewState("prd")
Else
If ViewState("prd") > 1 Then
For k = 2 To ViewState("prd")
addfds(k)
lb.Text = "hai"
Next
End If
'lb.Text = ViewState("prd")
End If
End Sub

Sub addfds(ByVal s As String)
Dim txt As TextBox

txt = New TextBox
txt.ID = "a" & s
txt.AutoPostBack = True
'txt.Text = "a" & s
ph.Controls.Add(txt)
ph.Controls.Add(New LiteralControl("
"))
End Sub

Private Sub a1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles a1.TextChanged
ViewState("prd") = ViewState("prd") + 1
addfds(ViewState("prd"))
End Sub
End Class

Loader.
Live Chat Icon For mobile
Up arrow icon