Thursday, February 10, 2011

how to display a value to textbox whos textmode is set to 'password' in c#

The code given below is to check the username n display the password via cookie. It works perfectly allright. since i want the value displayed in the password.text to be masked, i changed the textmode of the password.text to 'password'. as a result value isnt passed to the textbox.

Question: String cookiename = TextBox1.Text;

//grab cookie
HttpCookie cookie = Request.Cookies[cookiename];

if (null == cookie)
Label1.Text = "cookie not found";



HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];

TextBox2.Attributes.Add("value", cookie.Value.ToString());

The answer is just one line. but it saves a lot of time.

No comments: