Wednesday 15 January 2014

c# - Strange Bug when getting new values from textbox -


I have a website that is on page load, gets some information from the database and collects many text boxes The user can then modify the content of these text boxes if he wants to make any changes and he can save the changes since then.

The change I'm using to save the contents of the box is:

  string user name = session ["user name"]. ToString (); String vendor_name = Textbox_Vendor.Text; String Address = Textbox_Edress Text; String city = textboxgate. Text; String country = textboxcountry Text;   

Now, the main problem is that values ​​are being retrieved from the old values. For example, we say that on page load, the telephone field area was 12345678 and the user 789046778 changed the value of the value in the text box. Before saving the changes, the variable is being loaded in the tele, this value is 12345678 instead of 789 9 4678.

How can I get a new updated value from the text box? Thank you :)

Page Load

  Secure Zero Page_load (Object Sender, Event Events E) {Label_Error.Visible = false; Encryption encoded = new encryption (); If (session ["user name"] == tap) {Response.Redirect ("HomePage.aspx"); } Else {string username = session ["user name"]. ToString (); String vendor_name = ""; String address = ""; String city = ""; String country = ""; Bool exists1 = false; Bool error1 = true; Try {String connection1 = Configuration Manager. Connection strings ["DB_Connection"]. ConnectionString; SqlConnection conn1 = new SqlConnection (connection1); SqlDataReader rdr1 = Faucet; Conn1.Open (); SqlCommand cmd1 = New SqlCommand ("GetByUsername", conn1); Cmd1.CommandType = CommandType.StoredProcedure; Cmd1.Parameters.AddWithValue ("Username", "Username"); Rdr1 = cmd1.ExecuteReader ();    

Old values ​​should overwrite new values ​​on Page_Load Used to be . You are telling the old values ​​for the text box on each page load, whereas in fact you only want to do this during the first call. You do not have to assign anything to postback:

  if (! Page.IsPostback) {// First Call - Assign Value Textbox_Vendor.Text = vendor_name; ...}    

No comments:

Post a Comment