开发者

Retaining Data in ASP.NET Page

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 c开发者_StackOverflowlick 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.


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.

'Save
Session("username") = txtUsername.Text
Session("password") = txtPassword.Text

'Retrieve
Response.Write(Session("username"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜