ASP.NET: TextBox.Text has no updated value

I have an initialization function that loads data into the NameTextBox text box, and then add "s" to the name. Then I click the Save button, which does SaveButton_Click when debugging the value for NameTextBox.Text is still the source string (FirstName), 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) 
+4
source share
1 answer

If the text field is disabled, it will not be saved back to the code, also if you set the initial value each time (regardless of IsPostBack), you are essentially over the fact that this value when it gets into the event handler (SaveButton_Click), Example:

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

In the above code, there will always be a text value for the text field "someValue". You will need to wrap it in if (! IsPostBack) like this ....

 page_load() { if(!IsPostBack) {NameTextBox.Text = "someValue";}} .... saveButton_Click() { string x = NameTextBox.Text;} 
+12
source

Source: https://habr.com/ru/post/1381500/


All Articles