views:

116

answers:

2

Hello, I have an asp.net page with a datalist with few textboxes, and a submit button. when i cahnge the text in the textbox, and click submit, the value i get in the vb code is the old value and not the one i just entered.

Any idea?

thanks

+1  A: 

There are two possible reasons for this.

Either (1) the part of your code that sets this value is being run at postback, thus resetting it, or (2) your textbox is disabled in .NET code (and enabled in javascript) so that .NET assumes that its value cannot have changed, and doesn't check the POST data.

Sorry for C# code examples, but i'm sure you'll work it out:

1:

if(!Page.IsPostBack) { myTextBox.Value = "original value"; }

2:

string valueFromTextbox = Request.Form[myTextBox.ClientID];
David Hedlund
A: 

please explain this answer I also faced with a similar issue. My TextBox doesn't show the new text assigned from the code. It shows the old text. This text box resides inside a web user control.

Sisith
The page by defauld acts like it is the first time it opens, so if you have a submit button and the page posts back, you will need to do fields assignments on the _onload() event only if it is not a postback.