VB .NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If IsPostBack Then
    If Not String.IsNullOrEmpty(txtPassword.Text.Trim()) Then
      txtPassword.Attributes.Add("value", txtPassword.Text)            
      End If
  End If
End Sub

C#

protected void Page_Load(object sender, EventArgs e)
{    
  if (IsPostBack) 
    {        
      if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())) 
        {          
          txtPassword.Attributes["value"]= txtPassword.Text;  
        }    
     }
}