TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jennifer ODonovan
NA
29
11.4k
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:
protected
void
AddBooking_Click(
object
sender, EventArgs e)
{
//Creating a connection to my database using the connection string
string
cs = ConfigurationManager.ConnectionStrings[
"BookingDb"
].ConnectionString;
SqlConnection con =
new
SqlConnection(cs);
//preparing a query which will insert the data entered in the textboxes to the database
SqlCommand cmd =
new
SqlCommand(
"[dbo].[spAddBooking]"
, con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue(
"@UserId"
, UserID.Text.Trim());
cmd.Parameters.AddWithValue(
"@MemberType"
, ddlMemberType.SelectedValue);
cmd.Parameters.AddWithValue(
"@PitchSection"
, ddlSyntheticPitch.SelectedValue);
cmd.Parameters.AddWithValue(
"@Date"
, txtDate.Text.Trim());
cmd.Parameters.AddWithValue(
"@StartTime"
, ddlStartTime.SelectedValue);
cmd.Parameters.AddWithValue(
"@EndTime"
, ddlEndTime.SelectedValue);
cmd.Parameters.AddWithValue(
"@Description"
, txtDescription.InnerText.Trim());
con.Open();
cmd.ExecuteNonQuery();
}
catch
(Exception ex)
{
Response.Write(ex);
}
finally
{
con.Close();
Response.Redirect(
"BookingForm.aspx"
);
}
Reply
Answers (
1
)
WebGrid Bind Error in Asp.net MVC
no global.aspx.cs in project