[ASP.] Say the password box and the Read-only box

Source: Internet
Author: User

Original: [ASP.] Say the password box and the Read-only box

Introduction

Recently responsible for a small project of a company, from the front to the future generations, are engaged in, for a customer to get a small system of information management, although the interface and what did not require, in charge of the attitude, or give him a bit of style, of course, most of the style is still from the Internet.

Password box

This is the case, when you select the record you want to edit in the user list, you need to fill in the user information in the corresponding box on the edit page, and the problem of the password box comes up. Here is a simple page to test, the code is as follows:

1 <%@ Page Language="C #"AutoEventWireup="true"codebehind="Default.aspx.cs"Inherits="Wolfy.TextBoxDemo.Default" %>2 <!DOCTYPE HTML>3 <HTMLxmlns= "http://www.w3.org/1999/xhtml">4 <Headrunat= "Server">5     <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />6     <title></title>7 </Head>8 <Body>9     <formID= "Form1"runat= "Server">Ten         <Div> OnePassword box:<Asp:textboxrunat= "Server" textmode= "Password" ID= "Txtpwd" /> A             -         </Div> -     </form> the </Body> - </HTML>

Now we, when the page loads, set a value for it, the code is as follows:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8 namespaceWolfy.textboxdemo9 {Ten      Public Partial classDefault:System.Web.UI.Page One     { A         protected voidPage_Load (Objectsender, EventArgs e) -         { -             if(!IsPostBack) the             { -                  This. Txtpwd.text ="Admin"; -             } -         } +     } -}

Under normal circumstances, will be accustomed to write like this, browse, was the pit.

There is no value, how to assign it?

Fortunately, there is another way, otherwise the password box is useless, can only take, can not change the value, too no language.

1 namespaceWolfy.textboxdemo2 {3      Public Partial classDefault:System.Web.UI.Page4     {5         protected voidPage_Load (Objectsender, EventArgs e)6         {7             if(!IsPostBack)8             {9                 //this.txtPwd.Text = "admin";Ten                  This. TXTPWD.ATTRIBUTES.ADD ("value","Admin"); One             } A         } -     } -}

Browse to see the results:

This.....

Why not use this way, with the Text property how good!

Read-Only box

This is the case, use JS or jquery to copy the read-only box, get this value in CS, click the button, and then save to the database.

JS Code:

 1  <script type= "  text/javascript   "  >2  window.onload = fun Ction () { 3  document.getElementById ( " txtreadonly  " ). Innertext=  Span style= "Color:rgb (128, 0, 0); > "  4    5  </script> 

To modify the code:

1Read-only box:<Asp:textboxrunat= "Server"ReadOnly= "true"ID= "Txtreadonly" />2             <Asp:buttonText= "button"ID= "BTN"OnClick= "Btn_click"runat= "Server" />

Effect

The code in CS:

Out of habitual, want to go to the value of the text box, generally will use the above way, but ....

1         protected void Btn_click (object  sender, EventArgs e)2        {3             string  This . Txtreadonly.text; 4         }

Debug, see if you can get to:

Workaround:

1         protected void Btn_click (object  sender, EventArgs e)2        {3             string strreadonly = request.form["txtreadonly"]; 4         }

Results:

Analysis:

HTML Source:

Modify the Read-only box to give him a default value:

1Read-only box: <asp:textbox runat="Server"readonly="true"text="This is the default value"Id="txtreadonly"/>2<asp:button text="Button"Id="btn"onclick="Btn_click"runat="Server"/>

Debug and look at the results:

The corresponding HTML source code:

Guess: read-only box through the Text property, you can only get the value of the text box that has the Value property in the HTML tag generated by the client browser. (more difficult to pronounce)

Summarize

Before development is responsible for a module, this first time from the login to other business processing, their own full responsibility, so it feels very strange. Today, people in the group also asked about it, it felt necessary to summarize. For a read-only box, if there is a value for itself, it can be obtained through the Text property. If it is the foreground, the content that is set dynamically will not be available.

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.