Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TextBox.Text Prints Outdated Text

0 views
Skip to first unread message

willia...@gmail.com

unread,
Nov 12, 2007, 4:48:09 PM11/12/07
to
Suppose I have a button that, when pressed, takes the current value of
TextBox.Text pulled from SQL and sends it to Label1.Text. This code
should be:

private void update_Click(object sender, System.EventArgs e)
{
Label1.Text = TextBox1.Text;
}

As the program currently runs, clicking the button sends TextBox's
*first* value to Label1, not what was typed over it. That is, if
TextBox initially reads 'porkchop', change it to 'sandwiches' and
click the button, the label will read 'porkchop.'

My only idea of a solution is toggling AutoPostBack, but that didn't
help any. What else can I try?

Thanks.

Alberto Poblacion

unread,
Nov 13, 2007, 6:06:28 AM11/13/07
to
<willia...@gmail.com> wrote in message
news:1194904089.1...@o80g2000hse.googlegroups.com...

> private void update_Click(object sender, System.EventArgs e)
> {
> Label1.Text = TextBox1.Text;
> }
>
> As the program currently runs, clicking the button sends TextBox's
> *first* value to Label1, not what was typed over it. That is, if
> TextBox initially reads 'porkchop', change it to 'sandwiches' and
> click the button, the label will read 'porkchop.'
>
> My only idea of a solution is toggling AutoPostBack, but that didn't
> help any. What else can I try?

Take a look at your Page_Load event. This always fires *before* the
Click event. If you are reloading the textbox from the database inside
Page_Load, it will overwrite whatever the user typed before you can pick it
up in the update_Click event. If this is what is happening, you can use an
"if (!Page.IsPostBack)" inside Page_Load to avoid executing that part of the
code during the postback.

willia...@gmail.com

unread,
Nov 13, 2007, 9:54:00 AM11/13/07
to
On Nov 13, 5:06 am, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.org> wrote:
> <william.o...@gmail.com> wrote in message

>
> news:1194904089.1...@o80g2000hse.googlegroups.com...
>
> > private void update_Click(object sender, System.EventArgs e)
> > {
> > Label1.Text = TextBox1.Text;
> > }
>
> > As the program currently runs, clicking the button sends TextBox's
> > *first* value to Label1, not what was typed over it. That is, if
> > TextBox initially reads 'porkchop', change it to 'sandwiches' and
> > click the button, thelabelwill read 'porkchop.'

>
> > My only idea of a solution is toggling AutoPostBack, but that didn't
> > help any. What else can I try?
>
> Take a look at your Page_Load event. This always fires *before* the
> Click event. If you are reloading the textbox from the database inside
> Page_Load, it will overwrite whatever the user typed before you can pick it
> up in the update_Click event. If this is what is happening, you can use an
> "if (!Page.IsPostBack)" inside Page_Load to avoid executing that part of the
> code during the postback.

That did it. Thanks so much!

0 new messages