Asp:TextBox value doesnt change

G

Guest

I have a form for a customer to edit his customer information. It has several
textboxes that I will populate with some existing data from the database
before displaying the form to the user. I populate each of the textboxes
inside Page_Load using

(1) TextBox1.Text = "some value"

After changing some of the text in the textboxes and pressing submit button,
when I tried to get the edited text in the submit_button handler using

(2) dim something as String = TextBox1.Text

I got back the same value as in (1) even through I have made changes to the
textbox's text. any idea why this is so?
 
G

Grant Merwitz

Yes, when your page reloads, it's loading the original values in the textbox
before you try read them

To fix this, wrap the code inside of your page_load in a "Page.IsPostBack"
statement like so:

private void Page_Load(object Sender, System.EventArgs e)
{
if(!Page.IsPostBack) //the code within this statement will only load
the first time your page loads
{
SetSomeValues();
}
}

That should fix your problem

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top