how to set text to password field at Runtime or Dynamically

The Dot Net will not allow you setting Text to password field dynamically

For Exp:

if password Field with name Passtxt is there

then you cant set

Passtxt.Text = ” hellow”;

it wont show any error but it wont display any thing in password keeps it as blank

For Example consider a senario where you are creating a registration page and if that registration is having fields like

User Id


Country (drop down list –> on selecting this post back occurs)


so here when user fills the form

he will fill user id, password and once if he is selecting Country (which is Drop down list ) so Post back occurs to it so once the post back occurs all the data will be visible except Password which is left blank . so in order to tackel with this situation

we will do coding like this

try to write like

in Passtxt_textChanged Method in last line we Write

String Str1 =  Passtxt.Text;

// saving password to string so that we can retrive it on post back

and then in  Country(dropdownlist__SelectedIndexChanged method)

then we will write

txtpassword.Attributes(“value”) = Str1;

so this works fine as a solution for seting text to password at runtime or

maintaining password at Post back


About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Articles, Programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s