Saturday, June 18, 2011

How to retain password during postback

How to retain password during postback in ASP.NET

Generally password is lost when page is post. To save the password during postback you have to save the password in “Value” Attributes of textbox. because Text is the server side properties when page post then password text is lost while "Value" is the HTML properties and does not go to the server side. Hence does not empty during postback.


C#
if (IsPostBack)
{
    if (txtPassword.Text.Trim() != "")
    {
        txtPassword.Attributes["value"]= txtPassword.Text;
    }
}

VB
If IsPostBack Then
      If txtPassword.Text.Trim() <> "" Then
          txtPassword.Attributes("value") = txtPassword.Text
      End If
 End If

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.