Click here to Skip to main content
Licence CPOL
First Posted 24 Sep 2008
Views 15,540
Downloads 245
Bookmarked 14 times

Programmatically Set the Password to the TextBox in ASP.NET

By | 24 Sep 2008 | Article
An Extended TextBox to programmatically set the Text when control is in Password-Mode

Introduction

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.  

Background

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
{
    get
    {
        String s = (String)ViewState["Text"];
        return ((s == null) ? String.Empty : s);
    }

    set
    {
       if (this.TextMode == TextBoxMode.Password)
       {
           this.Attributes.Add("value", value);
       }
       else
       {
           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.

History

  • Version 1 released on 25th September, 2008

Suggestions and comments are welcome.

License

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

Software Developer (Senior)
Self Employee
Pakistan Pakistan

Member

Follow on Twitter Follow on Twitter
I have been in the programming for the last 6 years. Created many desktop and web based applications using Microsoft technologies.Currently i have been exploring the features of .NET 4.0.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSolution not working... PinmemberKundanKumar Ugale7:42 14 May '09  
AnswerRe: Solution not working... PinmemberRaheel Afzal Khan7:46 14 May '09  
General[Message Deleted] PinmemberJuraj Suchan3:18 20 Apr '09  

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

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

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