Click here to Skip to main content
11,925,292 members (58,426 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


16 bookmarked

Programmatically Set the Password to the TextBox in ASP.NET

, 24 Sep 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
An Extended TextBox to programmatically set the Text when control is in Password-Mode


During Web development, we often face a situation where we need to set the password within the code. Unfortunately the standard TextBox while in PasswordMode never allows us to do that. In the ExtendedTextBox, I have tried to resolve this problem.  


During the development process when I had faced this situation, I searched on the internet. I found the following article on CodeProject, it was a very good article but it was a limited one. That control can only be used as a Password control. I have extended this control to make it more flexible. It will behave like a standard textbox and when you set its...  

TextMode = TextBoxMode.Password

... it will allow you to set the Password from code behind.

Using the Code

I have changed the Text property of the control in the following way:

public string Text
        String s = (String)ViewState["Text"];
        return ((s == null) ? String.Empty : s);

       if (this.TextMode == TextBoxMode.Password)
           this.Attributes.Add("value", value);
           ViewState["Text"] = value;

If you want to use only the DLL, please download ExtendedTextBoxOupt_dll.

If you want to go through the code that is written inside the DLL, please download ExtendedTextBoxSource.

I have also added a sample Web project that uses this ExtendedTextBox control. 

Points of Interest

You don't have to do anything, just include the DLL in the toolbox, drop it on your webpage/webusercontrol. Either use it as a standard textbox or set its mode to Password, in either way it will behave the same.


  • Version 1 released on 25th September, 2008

Suggestions and comments are welcome.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Raheel Afzal Khan
CEO DatumSquare IT Services Pvt. Ltd.
Pakistan Pakistan
A computer science graduate with senior-level programming skills, Raheel Afzal has developed a number of management information systems and real estate portals. Through his work with other companies, Raheel was highly exposed to client relations, as well as American business models and operations.

Raheel started DatumSquare IT Services in 2009, facilitating daily operational management. His previous career experience and administration expertise have given him the insight and strategic planning skills to successfully transform a two-employee company into a thriving business with more than 60 highly skilled employees on staff.

Raheel presently resides in Rawalpindi, Pakistan, with his wife and two children. In his spare time he loves to read historical books and keep up with the latest worldly technological advancements.

You may also be interested in...

Comments and Discussions

QuestionSolution not working... Pin
KundanKumar Ugale14-May-09 8:42
memberKundanKumar Ugale14-May-09 8:42 
AnswerRe: Solution not working... Pin
Raheel Afzal Khan14-May-09 8:46
memberRaheel Afzal Khan14-May-09 8:46 
General[Message Deleted] Pin
Juraj Suchan20-Apr-09 4:18
memberJuraj Suchan20-Apr-09 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 25 Sep 2008
Article Copyright 2008 by Raheel Afzal Khan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid