Jennifer ODonovan

Jennifer ODonovan

  • NA
  • 29
  • 10.9k

My Session Variable doesn't store the correct value

Feb 9 2018 5:17 PM
I have a session variable stored from when a User logs into the web app. Then the logged in user can store information. When this information stores the Session Variable(UserId) doubles itself
 
for example if the user ID is 1 it saves as 11 or if it should be 4 it saves as 44.
  
Any ideas why this might be the case.
 
I have the session variable saved into a label on the form when the page loads:
 
//show label with corresponding Name used in log in
UserID.Text += Session["UserId"].ToString();
 
This is my code behind the save button:
  1. protected void AddBooking_Click(object sender, EventArgs e)  
  2. {  
  3. //Creating a connection to my database using the connection string  
  4. string cs = ConfigurationManager.ConnectionStrings["BookingDb"].ConnectionString;  
  5. SqlConnection con = new SqlConnection(cs);  
  6. //preparing a query which will insert the data entered in the textboxes to the database  
  7. SqlCommand cmd = new SqlCommand("[dbo].[spAddBooking]", con);  
  8. cmd.CommandType = CommandType.StoredProcedure;  
  9. try  
  10. {  
  11. cmd.Parameters.AddWithValue("@UserId", UserID.Text.Trim());  
  12. cmd.Parameters.AddWithValue("@MemberType", ddlMemberType.SelectedValue);  
  13. cmd.Parameters.AddWithValue("@PitchSection", ddlSyntheticPitch.SelectedValue);  
  14. cmd.Parameters.AddWithValue("@Date", txtDate.Text.Trim());  
  15. cmd.Parameters.AddWithValue("@StartTime", ddlStartTime.SelectedValue);  
  16. cmd.Parameters.AddWithValue("@EndTime", ddlEndTime.SelectedValue);  
  17. cmd.Parameters.AddWithValue("@Description", txtDescription.InnerText.Trim());  
  18. con.Open();  
  19. cmd.ExecuteNonQuery();  
  20. }  
  21. catch (Exception ex)  
  22. {  
  23. Response.Write(ex);  
  24. }  
  25. finally  
  26. {  
  27. con.Close();  
  28. Response.Redirect("BookingForm.aspx");  
  29. }  

Answers (1)