Retain Password after Postback of the Page in ASP.NET

Currently I am working on a client requirement where I have to develop a registration form.

In this form I have used 8 textbox and 8 dropdown list including two text box named Password and confirm Password.



When I was working on this form I found that all the values persist after post back of the page except Password and confirm Password.

Then I searched a solution for this and fixed the issue as below

By writing below code bloc ok page load

if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())) && !(String.IsNullOrEmpty(txtConfirmPassword.Text.Trim())))
{
   txtPassword.Attributes["value"] = txtPassword.Text;
   txtConfirmPassword.Attributes["value"] = txtConfirmPassword.Text;
}