How to specify a value to password, passwordbox Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.