Just small question as I cannot find an answer that resolves my problem.
I have an ASP page which sends input to a database and then creates a session. I would like to know how to return a certain value in that session on another aspx page.
page1.aspx.cs [creates session]
public partial class new_questionnaire : System.Web.UI.Page
{
OscarSQL c;
protected void Page_Load(object sender, EventArgs e)
{
c = new OscarSQL();
} // End Page_Load
////// Button Method //////
protected void NewQnrButton_Click(object sender, EventArgs e)
{
// Check if the input fields are empty.
if (QuestionnaireName.Text == "" || CustomerID.Text == "" || NumberOfQuest.Text == "")
{
Error.Text = "Please enter a name for your questionnaire.";
}
// Parse input values to OscarSQL.
else
{
int testRet = c.InsertQuestionnaire(QuestionnaireName.Text, Int32.Parse(CustomerID.Text), Int32.Parse(NumberOfQuest.Text));
Session["Questionnaire"] = testRet;
Confirm.Text = "Your questionnaire has been named " + QuestionnaireName.Text;
Response.Redirect("~/add_questions.aspx");
}
} // End NewQNRButton_Click
} // End new_questionnaire
Page2.aspx.cs [Would like value to be parsed here]
namespace OSQARv0._1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//ReturnQnrName.Text here?
}
}
}
I would like the value QuestionnaireName.Text from Page1 to be returned to ReturnQnrName.Text on Page2
You didn’t put
QuestionnaireName.Textinto Session on Page1, you put an integer. If you need the actual text property, put that into sessionAnd then you can retrieve it
This reveals something about Session. Objects are stored of type
object, you need to cast them to their correct types once you retrieve them before use. For example, to retrieve the integer you put into Session, you would write