How to save textbox viewstate that modetype is password, show Password
<Asp: textbox runat = "server" id = "txtpassword" textmode = "password" value = '<% # eval ("password") %>'> </ASP: textbox>
Or
Txtpassword. Attributes. Add ("value", password );
See addattributestorender method you can find the answer. Because the control is check modetype if modetype is password
That don't add the attribute.
How to make the Asp.net Password box *** disappear.
Using reflector, we can see that its control will judge whether the mode is password or not, so we will not write the value into it.
We can use txtpassword. Attributes. Add ("value", password) to bypass this layer, so that we can write the password.
You can also create a widget by yourself.
The following is the passwordbox code.
Code
Public class passwordbox: Textbox, ipostbackdatahandler, itextcontrol
{
Protected override htmltextwritertag tagkey
{
Get
{
Return htmltextwritertag. input;
}
}
Protected override void onprerender (eventargs E)
{
// Base. onprerender (E );
This. Page. registerrequirespostback (this );
}
Protected override void addattributestorender (htmltextwriter writer)
{
Writer. addattribute (htmltextwriterattribute. Name, this. uniqueid );
Writer. addattribute (htmltextwriterattribute. value, this. Text );
Writer. addattribute (htmltextwriterattribute. type, "password ");
If (this. ID! = NULL)
{
Writer. addattribute (htmltextwriterattribute. ID, this. clientid );
}
If (! This. enabled)
{
Writer. addattribute (htmltextwriterattribute. Disabled, "disabled ");
}
Int tabindex = This. tabindex;
If (tabindex! = 0)
{
Writer. addattribute (htmltextwriterattribute. tabindex, tabindex. tostring (numberformatinfo. invariantinfo ));
}
If (! String. isnullorempty (this. cssclass ))
{
Writer. addattribute (htmltextwriterattribute. Class, this. cssclass, false );
}
If (this. controlstylecreated &&! This. controlstyle. isempty)
{
This. controlstyle. addattributestorender (writer, this );
}
}
# Region ipostbackdatahandler members
Public new bool loadpostdata (string postdatakey, system. Collections. Specialized. namevaluecollection postcollection)
{
String text = This. text;
String str2 = postcollection [postdatakey];
If (! Text. Equals (str2, stringcomparison. ordinal ))
{
This. Text = str2;
Return true;
}
Return false;
}
# Endregion
}
Address: http://www.cnblogs.com/lovebanyi/archive/2008/10/29/1322151.html