Wierd: Can't get .text value of textbox

V

VB Programmer

I have a textbox on my webform. I can set it, like txt1.text = "hi", but if
I change the text and click a button to display the current value it RETAINS
the old value. Any ideas?

Any ideas?
 
F

Frank Mamone

If you set the value of the Textbox programmatically, then when the Page
Loads it sets it to that value. When you submit it will keep doing it unless
you include some code to tell it to do it on initial load like this:

private Page_Load
{

if(!IsPostBack)
{
txt1.Text = "Hi";

}

}

Not sure of syntax for VB:)


The IsPostBack property of the Page class detects when the request is a
postback. That is it has been submitted after initial load.


Hope this helps,

Frank
 
B

Brian Barnes

VB Programmer said:
I have a textbox on my webform. I can set it, like txt1.text = "hi", but
if
I change the text and click a button to display the current value it
RETAINS
the old value. Any ideas?

Any ideas?
Before you initailise the page, are you checking to see if the page has been
posted back (ie page.ispostback)? Otherwise you are writing the old value
into the textbox when you intialise the page.
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top