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. Problem with getting textbox value

Problem with getting textbox value

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 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.
  • V Offline
    V Offline
    vuthaianh
    wrote on last edited by
    #1

    when i pressed button add, the following code would add a text box to datagrid TextBox txtEdit = new TextBox(); dgTest.Items[0].Cells[0].Controls.Add( txtEdit ); After that i pressed button delete, the following would remove the textbox from datagrid TextBox txtEdit = ( TextBox ) dgTest.Items[0].Cells[0].FindControl("txtEdit"); // lblTest.Text = txtEdit.Text dgTest.Items[0].Cells[0].Controls.Remove( txtEdit ); What i can not understand is that it removed the textbox sucessfully that means it could find the textbox but it can't not get the text that i typed in the textbox Thanks

    A 1 Reply Last reply
    0
    • V vuthaianh

      when i pressed button add, the following code would add a text box to datagrid TextBox txtEdit = new TextBox(); dgTest.Items[0].Cells[0].Controls.Add( txtEdit ); After that i pressed button delete, the following would remove the textbox from datagrid TextBox txtEdit = ( TextBox ) dgTest.Items[0].Cells[0].FindControl("txtEdit"); // lblTest.Text = txtEdit.Text dgTest.Items[0].Cells[0].Controls.Remove( txtEdit ); What i can not understand is that it removed the textbox sucessfully that means it could find the textbox but it can't not get the text that i typed in the textbox Thanks

      A Offline
      A Offline
      analytiks
      wrote on last edited by
      #2

      the problem is most probably related to ViewState ~ when controls are added dynamically to a page ~ then its viewstate is not saved ~ if you see the rendered html of the page, a hidden field __viewstate is present which stores the viewstate information of all the controls in the page ~ when controls are added dynamically , its viewstate information is not available ~ what can be done is after you add the textbox, try saving it in the StateBag ~ in the page load event ~ retrieve the textbox from the StateBag and add it in the same location again ~ you will find that when the control reaches your post back event handler the text in the text box is now available

      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