Emil’s Blog

Programming Windows, .Net, EPiServer and whatnot…

[Powered by WordPress.]

August 3, 2006

Initializing the contents of a password textfield in ASP.NET 2.0

by @ 16:10. Filed under .Net programming

Question
How do I initialize the contents of a password textfield in ASP.NET 2.0?

Simple anwser
You can't! This doesn't work (apparently this is for security reasons, although the exact motivation escapes me):

txtPassword.Text = "this sucks";

Better answer
Create an event handler for the TextBox's PreRender event:

protected void txtPassword_PreRender(object sender, EventArgs e)
{
    TextBox txt = (TextBox)sender;
    txt.Attributes["value"] = txt.Text;
}

Voilá! Now you can assign to the Text property as in the first example.

(Credits for this tip to David Silverlight.)

[powered by WordPress.]

jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.

Internal links:

Categories:

Search blog:

Archives:

August 2006
M T W T F S S
« Jul   Sep »
 123456
78910111213
14151617181920
21222324252627
28293031  


View Emil Åström's profile on LinkedIn

General links:

I read:

Visitors

Recent Comments

Spam caught

Other:

Clicky Web Analytics

36 queries. 0.476 seconds