public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Assign Value to Asp.Net TextBox with mode=”Password”

Posted by Virendra Dugar on January 16, 2009

Quick summary of what’s changed in ASP.NET Core 1.0

ASP.NET server control doesn’t want to add/display the value in a password textbox because of security concerns. You have to add it yourself using an attribute.

Add this following line of code when you want set the value 

TextBox1.Attributes.Add(“value”, “thePassword”)
*( TextBox1 is a password textbox.)

While given solution will work, if a user does a view source on the form, the password is visible as plain text and that is never good from a security standpoint.

Rather, I would use Viewstate to hold the password value and if the userdoesn’t change it then retrieve the value from view state.

Other Scenario is:-

On most of the web sites at the time of registration password is asked.You must have noticed after submitting the page if you are again redirected to the page due to unsuccessful registration value of password field is lost.

This is due to security concerns as everything is gets rendered on the client side So when you view the source in the browser password value will be there.

But if you want to set the value of password text box explicitly then use following method in .NET 2.0

txtPassword.Attributes[“value”] = Request.Form[txtPassword.ClientID]; //in C#.Net 2.0

Enjoy…..

Learn new ASP.NET Core 1.0 Framework

Advertisements

11 Responses to “Assign Value to Asp.Net TextBox with mode=”Password””

  1. mohanraj said

    Thanks it worked

  2. Welcome…

  3. Bin Zeng said

    Hey Virendra,
    Your solution can solve the problem to view the password as ******, but when you click on update button, the password value is “thePassword”, will automatically change the password to “thePassword”…

    • Hi bin,

      Developer need to handle above problem using any logic. We can set a variable whenever text box data gets change and while updating check the value of variable. If it is changed then update the password otherwise there is no need.

      Hope this help!!!

  4. Priya said

    Worked,Good information.
    Thanks!

  5. Shubh said

    Works Good,Thanks a lot.

  6. God bless you. thanks

  7. Tanvir said

    I was exactly looking for a solution for the problem as i am disabling the password field but wanted to show **** for the user to see the password field is disable. Thanks works great !!!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: