Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: TextBox.Text doesn't have updated value

I have an initialize function that loads data into my textbox NameTextBox, and then I add an "s" to the name. I then click the Save button that executes SaveButton_Click when debugging the value for NameTextBox.Text is still the original string (FirstName) and not (FirstNames). Why is this? Thanks.

Edit: Sorry here you go let me know if you need more...

Page_Load(sender, e)

Info = GetMyInfo()
Initialize()

Initialize()

NameTextBox.Text = Info.Name

SaveButton_Click(sender, e)

Dim command As SqlCommand

command = GetSQLCommand("StoredProcedure")
command.Parameters.AddWithValue("@Paramter", NameTextBox.Text)
ExecuteSQLCommand(command)
like image 881
daveomcd Avatar asked Dec 17 '22 07:12

daveomcd


1 Answers

If the textbox is disabled it will not be persisted back to the codebehind, also if you set the initial value everytime (regardless of IsPostBack) you are essentially over writing what the value is when it gets to the Event handler (SaveButton_Click). Ex:

page_load() { NameTextBox.Text = "someValue";}
....

saveButton_Click() { string x = NameTextBox.Text;}

The above code will always have the text value of the textbox be "someValue". You would need to wrap it in an if(!IsPostBack) like so....

page_load() { if(!IsPostBack) {NameTextBox.Text = "someValue";}}
....

saveButton_Click() { string x = NameTextBox.Text;}
like image 200
szeliga Avatar answered Dec 31 '22 00:12

szeliga