Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Result screen page as follows;

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

    }



Login Page code as follows;

In login page, page load i written the below code

C#
TxtName.Text = Session["StudName"].ToString();
   TxtStudID.Text = Session["studID"].ToString();



from the above code i am retrieving the studname and studentid value from the result page and display into the login page using session.


When i run shows error as follows in the result page as follows;

use of unassigned local variable studname
use of unassigned local variable studid


please help me what is the problem in my code?

Regards,
Narasiman P.
Posted
Updated 6-May-13 1:59am
v2

Look at your code:
C#
string studname;
string studid;
Session["StudName"] = studname;
Session["StudID"] = studid;
What value is in studname or studid when you try to set the value of the session variable?
None - so it is an unassigned local variable: it does not have any value assigned when you use it for the first time.
Set it to a value, and all will be well:
C#
string studname = "";
string studid = "";
Session["StudName"] = studname;
Session["StudID"] = studid;
 
Share this answer
 
set
C#
string studname=string.Empty;
string studid=string.Empty;
 
Share this answer
 
You have not assigned any values to string studname and string studid.

First assign them with some value before assign them with session parameters try this.
C#
string studname="Any String";
             string studid="Any String";
             Session["StudName"] = studname;
             Session["StudID"] = studid;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900