使用会话我想清除值,也不想清除特定的两个文本框值 [英] using session i want to clear the values and also do not want to clear particular two textbox values

查看:69
本文介绍了使用会话我想清除值,也不想清除特定的两个文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果页面代码如下;



页面加载代码中的结果页面如下;

Result page code as follows;

In result page in page load code as follows;

 protected void Page_Load(object sender, EventArgs e)
 {

   try
   {
       Int32 Avg;
       Avg = Convert.ToInt32(Session["Avg"]);
       BtnReExam.Text = "Next Candidate";
       Image1.ImageUrl = "images/Congratulation.gif";
       Image1.Visible = true;
       if (Avg >= 90 && Avg <= 100)
           Label2.Text = "Excellent  " + Session["StudName"] + "  Congrats";
       else if (Avg >= 75 && Avg <= 90)
           Label2.Text = "Very Good  " + Session["StudName"] + "  Congrats";
       else if (Avg >= 60 && Avg <= 75)
           Label2.Text = "Good  " + Session["StudName"] + "  Congrats";
       else if (Avg < 60)
        Label2.Text = "Sorry " + Session["StudName"] + ". You are Failed. You have to attend the Re-Exam Now.";
           BtnReExam.Text = "Press here to Start Re-Exam";
           Image1.ImageUrl = "";
           Image1.Visible = false;
       //}
       Label1.Text = "You scored " + Avg + "% of marks";
       Session.Clear();
       Session.RemoveAll();
   }
   catch (Exception ex1)
   {
       this.Label4.Text = ex1.Message.ToString();
       return;
   }
}







按钮重新验证代码如下






Button ReExam code as follows

protected void BtnReExam_Click(object sender, EventArgs e)
{
     Int32 Avg;
     Avg = Convert.ToInt32(Session["Avg"]);
     if (Avg < 60)
     {
         string studname = "";
         string studid = "";
         studname = Session["StudName"].ToString();
         studid = Session["StudID"].ToString();
         Session.Clear();
         Session.RemoveAll();
         Session["StudName"] = studname.ToString();
         Session["StudID"] = studid.ToString();
     }
     else
     {
         Session.Clear();
         Session.RemoveAll();
     }
       Response.Redirect("login.aspx");
}







我跑步参加考试如果学生失败,那个学生ID和名字想要显示在登录页面上。



为此我在Button(Rexam)中写了一个代码。



在结果页面中,如果学生失败,我写的页面加载意味着会话清除,

但我希望学生ID和学生姓名值不想在会话



当学生失败时我想在登录页面显示学生姓名和学生ID。



那个ido怎么样?



来自我在结果页面的上面代码,页面加载有什么问题



请帮帮我。



问候,

Narasiman P.




when i run and attend the exam if student fails, then that student id and name want to display in the login page.

for that i written a code in Button (Rexam).

In the result page, page load i written if student fails means session clear,
but i want the student id and student name values do not want to clear in the session

when student fails i want to display the student name and student id in the login page.

for that how can ido?

from my above code in the result page, page load what is the problem

please help me.

Regards,
Narasiman P.

推荐答案

您正在使用

You are using
Session.Clear();
Session.RemoveAll();





它将清除并删除所有会话变量



尝试删除特定会话使用

Session.Remove(会话名称);



如果你在页面加载时出现错误,检查天气您正在使用的会话变量是否为NULL

示例 - >



it will clear and remove all the Session Variables

try to remove particular sessions using
Session.Remove("Session Name");

if you are getting errors on page load, check weather the session variables you are using are NULL or not
Example->

if (Session["Session Name"] != null)
        {
            Label2.Text = Session["Session Name"].ToString();
        }


这篇关于使用会话我想清除值,也不想清除特定的两个文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆