Asp.net 2.0 solution to prevent password box clearing

Source: Internet
Author: User

 
1. We often have the following situations:
That is, the user must enter a new one due to an incorrect information during registration. However, this process goes through the server PostBack. So the Password box is cleared. In PostBack mode, if the textmode of textbox is password, the value attribute is not passed, so the Password box is empty. In fact, this problem can be solved.

2 .:
Generally, the password cannot be saved:

 

After processing, you can save the password

Code:
Background code
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. runtime. remoting;
Using system. runtime. remoting. lifetime;
Using system. IO;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

This. Password. Attributes. Add ("value", request ["password"]); // events added to the password box

}

Protected void button#click (Object sender, eventargs E)
{

}
}

Front-end code
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> tips for saving the Password box http://blog.csdn.net/21aspnet/ clear moon </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "label1" runat = "server" text = "enter the password"> </ASP: Label>
& Nbsp; <asp: textbox id = "password" runat = "server" textmode = "password"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" text = "Submit" onclick = "button#click"/> </div>
</Form>
</Body>
</Html>

 

Related Article

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.