Link to home
Create AccountLog in
Avatar of 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

Avatar of MijaeDjinn
Flag of Canada image

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.
Avatar of raja_ind82
Flag of India image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account