.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Set Text to textbox of type password In Asp.Net

Posted By:Praveen       Posted Date: January 27, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Set Text Property of a Textbox of Type Password in ASP.Net using code is not straight forward as it is like a TextBox of TextMode Single or Mode Multiline.

So the question arises that can we set the Text or value to a TextBox of Type Password or Mode=Password?

Well the answer is YES.

Lets see how can we do that

Suppose you have a TextBox Control name TextBox1 and its TextMode is set to Password. Now to set the Text to this control we have to set text through its Attributes Property like this

Using c# Code

this.TextBox1.Attributes["value"] = "YourPassword";

Using Vb.Net Code

Me.TextBox1.Attributes("value") = "YourPassword"

Hope this will help all who are trying to set the text to a TextBox control with its TextMode property to Password.

Happy Coding!!!
Praveen


     

Further Readings:

Responses
Author: Dana         Company URL: http://www.dotnetspark.com
Posted Date: April 27, 2009

Hi Praveen,
It is nice example. But the Problem is that if you view the source of that page you can able to see the password. That may be a Security Risk

Dana
Author: Praveen         Company URL: http://www.dotnetspark.com
Posted Date: April 30, 2009

Hi Dana,

Thanks for posting feedback.

Yes you are right there is security risk. But see the scenario why do you need to assign back the password to TextBox control? Usually We do this when we are trying to implement "Remember Me on This Computer" functionality, In this scenario we are saving the password in cookies etc. here person usually assign on his/her personnel computer.

Encryption and Decryption is the solution of Security Concern.

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend