在 ASP.NET 页面中保留数据
我有一个简单的 ASP.NET 页面,在加载初始页面后,用户在两个文本框中输入用户名和密码。请注意,我无法使用 ASP.NET 中的内置登录控件,因为我使用此用户名和密码的目的略有不同。
现在,我希望用户仅输入上述两个值一次。然后,我使用这两个值执行多项任务。现在这是棘手的部分;由于我将密码文本框的 TextMode 属性设置为“密码”,每次单击按钮时都会清除密码字段,并且由于每个按钮单击事件也会触发页面加载,因此我会丢失密码数据。但我不希望用户每次单击按钮时都输入密码。
如何在代码中保留用户名和密码?如果这是一个普通的 .NET Windows 应用程序,我将使用全局变量并第一次分配值,并且我将在程序的整个生命周期中使用它。但我在这里该怎么做呢?
请注意,这是我的第一个 ASP.NET 程序,因此我们将非常感谢一些代码示例。
I have a simple ASP.NET page where after the initial page load the user enters a username and a password to two text boxes. Note that I can not use the built-in login control in ASP.NET, as my purpose of using this username and password is slightly different.
Now, I want the user to enter the said two values only once. Afterwards, using those two values I perform several tasks. Now here's the tricky part; since I set the TextMode property of the password text box to 'password', every time a button click occurs it clears the password field, and since every button click event triggers a page load as well, I lose the password data. But I do not want the user to keep entering the password every time he has to click a button.
How can I retain the username and password in my code? If this were a normal .NET Windows Application, I would use a global variable and assign the value the first time and I would have it available to me throughout the life cycle of my program. But how can I do it here?
Please note that this is my very first ASP.NET program, so some code sample would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 会话状态
在会话集合中您可以存储和检索用户连接到的会话的数据。会话有一个超时时间,我认为标准是 20 分钟。
You can use the Session State
In the session collection you can store and retrieve data for the session to which the user is connected to. A session has a timeout I think its 20 minutes standard.