Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. getting value of dynamic textbox after post back

getting value of dynamic textbox after post back

Scheduled Pinned Locked Moved ASP.NET
designhelp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saam_cse
    wrote on last edited by
    #1

    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.

    H A K M 4 Replies Last reply
    0
    • S Saam_cse

      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.

      H Offline
      H Offline
      himanshu2561
      wrote on last edited by
      #2

      Because you are adding textbox in the click event of Add button. So when u click save button you are not getting anything

      himanshu

      1 Reply Last reply
      0
      • S Saam_cse

        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.

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        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(), because Postback 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

        1 Reply Last reply
        0
        • S Saam_cse

          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.

          K Offline
          K Offline
          Kapil Thakur
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S Saam_cse

            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.

            M Offline
            M Offline
            Matt Cavanagh
            wrote on last edited by
            #5

            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") ?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups