Why do my text box values disappear when I click a button?

When I click the button on my web form, the data entered in the text boxes disappears and cannot be used in the VB behind the form. How can I fix this?
-Chuck
Protected Sub GetData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetData.Click
        If TextBox1.Text = "" Then
            Label1.Text = "You MUST enter a User Name"
            Label1.Visible = True
            Exit Sub
        End If
        If TextBox2.Text = "" Then
            Label1.Text = "You MUST enter a Password"
            Label1.Visible = True
            Exit Sub
        End If
    End Sub

Open in new window

WebForm.bmp
LVL 16
Chuck WoodAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
Check if you are clearing the TBs in your Page_Load ..if so you need to enclose that code inside:
If Not Page.IsPostBack block
Chuck WoodAuthor Commented:
I am very new to web programming. What is clearning the TBs?
-Chuck
Chuck WoodAuthor Commented:
Sorry, ...clearing the TBs?
-Chuck
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Chuck WoodAuthor Commented:
i wrapped the code shown in a "If Not Page.IsPostBack" block and found that the code does not run at all. It seems that the page is a postback. I need for this code to run so I can capture the text in the text boxes. What am I doing wrong?
-Chuck
guru_samiCommented:
Clearing the TB i.e the setting TextBoxes to empty string....
Do you have any code in your Page_Load ?

No you don't have to put that IsPostBack check inside your Button Click....i meant to put it inside your Page if you were using any....

Can we see your TextBox markup and the code behind...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chuck WoodAuthor Commented:
You nailed the problem. In Windows forms, I clear the text boxes when I open the form. It is now obvious that I don't want to do that in Web pages. Thank you so much.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.