会话返回值

编程入门 行业动态 更新时间:2024-10-28 11:18:37
本文介绍了会话返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

只是一个小问题,因为我找不到解决我问题的答案.

Just small question as I cannot find an answer that resolves my problem.

我有一个ASP页面,该页面将输入发送到数据库,然后创建一个会话.我想知道如何在另一个 aspx页面上的会话中返回某个值.

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 [创建会话]

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 [想在此处解析值]

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? } } }

我希望将 Page1 中的QuestionnaireName.Text值返回给 Page2

I would like the value QuestionnaireName.Text from Page1 to be returned to ReturnQnrName.Text on Page2

推荐答案

您没有将 QuestionnaireName.Text 放到Page1的Session中,而是放了一个整数.如果您需要实际的text属性,请将其放入会话

You didn't put QuestionnaireName.Text into Session on Page1, you put an integer. If you need the actual text property, put that into session

Session["theText"] = QuestionnaireName.Text;

然后您可以检索它

string text = (string)Session["theText"];

这揭示了有关Session的一些信息.对象的存储类型为 object ,一旦使用它们,就需要将它们转换为正确的类型.例如,要检索放入Session中的整数,应编写

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

int questionnaire = (int)Session["Questionnaire"];

更多推荐

会话返回值

本文发布于:2023-10-26 14:43:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!