会话状态给出错误“上下文中不存在”

发布于 2024-10-24 00:30:30 字数 591 浏览 3 评论 0原文

好的...我尝试设置一些会话状态变量,但我收到错误:

错误 3 名称“txtFirstName”在当前上下文中不存在

添加到提交按钮的事件处理程序中的内容

Session["txtFirstName"] =
txtFirstName.Text;
Session["txtLastName"] = txtLastName.Text;
Session["txtPayRate"] = txtPayRate.Text;
Session["txtStartDate"] = txtStartDate.Text;
Session["txtEndDate"] = txtEndDate.Text;

这是我在输入时 这段代码中,文本字段名称(例如 txtLastName)在智能感知中弹出,因此这会让我相信它们在上下文中,但我仍然收到此错误。我也尝试过:

HttpContext.Current.Session["txtFirstName"] = txtLastName.Text;

但这给出了同样的错误。我很难过。我是不是忘记了什么?我需要添加其他内容吗?我的书在这个主题上非常模糊,实验室说明没有提供任何帮助。

Ok... im trying to set some session state variables but im getting back the error:

Error 3 The name 'txtFirstName' does not exist in the current context

Here is what I added into the event handler of a submit button

Session["txtFirstName"] =
txtFirstName.Text;
Session["txtLastName"] = txtLastName.Text;
Session["txtPayRate"] = txtPayRate.Text;
Session["txtStartDate"] = txtStartDate.Text;
Session["txtEndDate"] = txtEndDate.Text;

while i was typing this code, the text field names such as txtLastName were popping up in intellisense, so that would lead me to believe that they ARE in context, but im still getting this error. I've also tried:

HttpContext.Current.Session["txtFirstName"] = txtLastName.Text;

But that was giving the same error. Im stumped. Am i forgetting something? Do I need to add something else in. My book is very vague on the subject and the lab instruction don't give anything helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩扇题诗 2024-10-31 00:30:30

听起来这可能是文件背后的代码有问题。

有时(我不是 100% 知道为什么会发生这种情况,但我过去见过)*.aspx.designer.cs 可以停止更新自身。

解决方案是删除 *.aspx.designer.cs 文件,然后右键单击 *.aspx 文件并选择“转换为 Web 应用程序”来重新创建它。

这应该会重新生成设计器文件并解决问题。

Sounds like it may be a problem with the code behind files.

Sometimes (I'm not 100% on why this can happen but I've see it in the past) the *.aspx.designer.cs can stop updating its self.

The solution to this is to delete the *.aspx.designer.cs file and recreate it by right clicking on the *.aspx file and choosing "Convert to web application".

This should regenerate the designer file and fix the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文