Crazy_Penguins
asked on
ASP.NET TextBox won't keep value? Very Confused.
Can't get a test box to keep values when I want to read them in my code.
Problem easy to reproduce!
Steps - create new aspx page, drag on a textbox, button, another textbox
Clicking button on middle, should, with the code below, copy the test in box 1 to box 2 - be sure to change the text to something other than 'hello' - and it will revert back to 'hello' every single time. Do it any way you want, press enter, press the button, do it while half asleep working on a project late into the night...
Thanks for any help - Andrew
Problem easy to reproduce!
Steps - create new aspx page, drag on a textbox, button, another textbox
Clicking button on middle, should, with the code below, copy the test in box 1 to box 2 - be sure to change the text to something other than 'hello' - and it will revert back to 'hello' every single time. Do it any way you want, press enter, press the button, do it while half asleep working on a project late into the night...
Thanks for any help - Andrew
Partial Class TestPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.TextBox1.Text = "hello"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.TextBox2.Text = Me.TextBox1.Text
End Sub
End Class
Move the line to a different method. You could try setting TextBox1.Text in Me.Init or set the text in the designer so that the text is set when the form is created, not loaded.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.