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. Bug in TextBox control ?

Bug in TextBox control ?

Scheduled Pinned Locked Moved ASP.NET
helpdesignquestion
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.
  • I Offline
    I Offline
    israeli
    wrote on last edited by
    #1

    Hi, I'm using the control TextBox: protected System.Web.UI.WebControls.TextBox TextBox1; In the Page_Load function I'm initializing some value to the TextBox: TextBox1.Text="initial data"; The problem is that once I'm initializing a string to the TextBox control the changes that the user makes in the text are not taking place. When I'm getting the data from the control, for instance: string s=TextBox1.Text; the string I get is exactly the same as the one which was initialized. What can solve that ? Thanks

    S 1 Reply Last reply
    0
    • I israeli

      Hi, I'm using the control TextBox: protected System.Web.UI.WebControls.TextBox TextBox1; In the Page_Load function I'm initializing some value to the TextBox: TextBox1.Text="initial data"; The problem is that once I'm initializing a string to the TextBox control the changes that the user makes in the text are not taking place. When I'm getting the data from the control, for instance: string s=TextBox1.Text; the string I get is exactly the same as the one which was initialized. What can solve that ? Thanks

      S Offline
      S Offline
      SilentSeraph
      wrote on last edited by
      #2

      Ah! I made this mistake, too, until I stumbled across the answer. Whenever you are making your changes, you most normally have some type of submit button, I'm sure. So... You are expecting that the data the user inputs is going to be in the ViewState, and will stay in the textbox that the user input data into after he/she submits. Well, a Page_Load happens _every_ time the webpage refreshes, not just the very first time the particular application loads. So instead of doing just: TextBox1.Text="initialdata"; You should check to see whether or not the page is being posted back to itself, or in other words, whether or not the user just clicked a button to load the page, instead of just surfing to the page. You can do so by doing this in your Page_Load handler: If(!isPostBack()) { TextBox1.Text="initialdata"; } This way, the page will only initialize the text property when isPostBack returns false (which would be when the visitor hit the page for the very first time). Hope that helps! --Keith

      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