Avatar of Crazy_Penguins
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
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

Open in new window

.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
raja_ind82

8/22/2022 - Mon
MijaeDjinn

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
raja_ind82

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy