getting value of dynamic textbox after post back
-
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur. I am creating New textBox lile bellow... Partial Class postback Inherits System.Web.UI.Page Dim tx As New TextBox ................ ................ Protected Sub btnNewAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewAdd.Click PlaceHolder1.Controls.Add(tx) End Sub .............. ............... Now I pressed a 'save' button and try to show dynamically created text box's value in label.But it is not happening. Also textBox vanishes. My code is bellow... Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Label1.Text = tx.Text End Sub .......... ;P End Class Please help me to achive this.
-
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur. I am creating New textBox lile bellow... Partial Class postback Inherits System.Web.UI.Page Dim tx As New TextBox ................ ................ Protected Sub btnNewAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewAdd.Click PlaceHolder1.Controls.Add(tx) End Sub .............. ............... Now I pressed a 'save' button and try to show dynamically created text box's value in label.But it is not happening. Also textBox vanishes. My code is bellow... Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Label1.Text = tx.Text End Sub .......... ;P End Class Please help me to achive this.
Because you are adding textbox in the click event of Add button. So when u click save button you are not getting anything
himanshu
-
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur. I am creating New textBox lile bellow... Partial Class postback Inherits System.Web.UI.Page Dim tx As New TextBox ................ ................ Protected Sub btnNewAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewAdd.Click PlaceHolder1.Controls.Add(tx) End Sub .............. ............... Now I pressed a 'save' button and try to show dynamically created text box's value in label.But it is not happening. Also textBox vanishes. My code is bellow... Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Label1.Text = tx.Text End Sub .......... ;P End Class Please help me to achive this.
Saam_cse wrote:
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur.
You will not get. Because you have to create the textbox,
before Page_Load()
, becausePostback data and view state data load for control before page_load
. Create your control on Page_PreInit()
will resolve your problem.cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article
-
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur. I am creating New textBox lile bellow... Partial Class postback Inherits System.Web.UI.Page Dim tx As New TextBox ................ ................ Protected Sub btnNewAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewAdd.Click PlaceHolder1.Controls.Add(tx) End Sub .............. ............... Now I pressed a 'save' button and try to show dynamically created text box's value in label.But it is not happening. Also textBox vanishes. My code is bellow... Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Label1.Text = tx.Text End Sub .......... ;P End Class Please help me to achive this.
Create a HashTable and add the control id as key and control value as value. Then at postback get the control's value using Request.Form(control_id) and create the control again and assign it the same value. Example : Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Not IsNothing(ViewState("ht")) Then Dim v_ht As New Hashtable v_ht = CType(ViewState("ht"), Hashtable) For i As Integer = 0 To v_ht.Count - 1 'getting value of 1st control Dim a = Request.Form("txt_1") 'getting value of 2nd control Dim b = Request.Form("txt_2") Next Else Dim ht As New Hashtable 'dynamically created 1st control Dim txt As TextBox txt = New TextBox txt.ID = "txt_1" txt.Text = "CODE" &n
-
I like to create textBox dynamically by pressing a button. But I can’t getting the textbox or its value back after a postback occur. I am creating New textBox lile bellow... Partial Class postback Inherits System.Web.UI.Page Dim tx As New TextBox ................ ................ Protected Sub btnNewAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewAdd.Click PlaceHolder1.Controls.Add(tx) End Sub .............. ............... Now I pressed a 'save' button and try to show dynamically created text box's value in label.But it is not happening. Also textBox vanishes. My code is bellow... Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Label1.Text = tx.Text End Sub .......... ;P End Class Please help me to achive this.
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click TextBox txtBxTemp = (TextBox)e.Item.FindControl("tx"); Label1.Text = txtBxTemp.Text; End Sub Well those two list are C# I have no clue what VB would be maybe: txtBxTemp as TextBox = (TextBox)e.Item.FindControl("tx") ?