ユーザーが出席者ページから別のページに移動したときにテキストボックスの値を固定し、ラベルを固定したい場合enableviewstate="true"
を設定しましたが、私は消えた別のページに行く。ページで静的な値を保持する方法
は、ここに私のhtmlコードです:
<tr>
<td class="auto-style3">Login Time:</td>
<td class="auto-style4">
<asp:Label ID="lblLogin" enableviewstate="true" runat="server"></asp:Label>
</td>
<td class="auto-style5">Logout Time:</td>
<td>
<asp:Label ID="lblLogout" enableviewstate="true" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3">Remarks:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBoxRemarks" runat="server" enableviewstate="true" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
はここに私のc-シャープコードです:
TimeSpan logintime = System.DateTime.Now.TimeOfDay;
TimeSpan time = TimeSpan.Parse("09:20:00.000");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblAttendance.Text = Session["user"].ToString().Split('^')[1];
lblDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
if (btnLogin.Text == "Login(Daily Attendance)")
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Track_UserLog", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@EmployeeId", Session["user"].ToString().Split('^')[0]);
cmd.ExecuteNonQuery();
con.Close();
lblLogin.Text = System.DateTime.Now.ToString("hh:mm");
btnLogin.Text = "Logout(Daily Attendance)";
if (logintime > time)//&& TextBoxRemarks.Text.ToString() == String.Empty)
{
DateTime today = DateTime.Today;
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
cn.Open();
SqlCommand cd = new SqlCommand("update tblAttendanceDetails set [email protected] where LoginDate=convert(date,GETDATE()) AND EmployeeId=' " + Session["User"].ToString().Split('^')[0] + " '", cn);
cd.Parameters.AddWithValue("@rem", TextBoxRemarks.Text);
cd.ExecuteNonQuery();
cn.Close();
}
}
else if (btnLogin.Text == "Logout(Daily Attendance)")
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Track_logout", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@EmployeeId", Session["user"].ToString().Split('^')[0]);
cmd.ExecuteNonQuery();
lblLogout.Text = System.DateTime.Now.ToString("hh:mm");
btnLogin.Text = "Login(Daily Attendance)";
}
}
私はあなたがセッションオブジェクトを読むのを見ますが、どこで設定しますか? –
@PatrickHofman私はログインページに設定しました... – Simranjeet
正確にどこが間違っているのかは私には不明です。実際に何が起こったのか、どのようなステップを再現するのかをもっと説明できますか? –