Enter text box using C # Development Mask

xiaoxiao2021-03-06  38

Mask input is a commonly used control, I remember that this control is in Visual FoxPro! It feels strong, nice. Now use C # development ASP.NET applications, you need to use this input control, just do one yourself. But because the mask text box in Visual FoxPro is too strong, I still don't dare to do it for a while. There are also some homemade online, such as http://www.weste.net/2004/11-25/09162561988.html, but feeling is not very suitable. Later, I saw the mask text boxes they did in http://www.stedy.com, I feel that this way is very suitable in the web application, I will down the client code DOWN! (STEDY Software is a product, it is necessary to spend money! And very expensive 79.99USD, ft.) Analyze STEDY client scripts (VBScript) They make a client method for each mask rule. The following is a client script code formatted by the date mask:

Function Maskdate (Svalue, Stype)

DIM ZMONTH

Zmonth = Array ("January", "February", "March", "April", "June", "July", "August", "September", "October", "November", "DecEmber ")

IF LEN (TRIM (Svalue)) = 0 THEN

Maskdate = ""

SetViewState False

Elseif Not (Isdate (Svalue)) THEN

Maskdate = "# invalid date entered #"

SetViewState True

Else

SELECT CASE (STYPE)

Case "Medium"

Maskdate = day (DateValue) & "-" & left (zmonth (Month (Svalue) - 1), 3) & "-" & Year (DateValue (SVALUE))

Case "long"

Maskdate = zmonth (Month (Svalue) - 1) & "& Day (DateValue) &", "& Year (DateValue (Svalue))

Case Else

Maskdate = formatdatetime (svalue, vbshortdate)

End SELECT

SetViewState False

END IF

END FUNCTION

It can be seen that the processing mode is formatted in the text box, and if the format is successful, it appears as a formatted string, otherwise, "# invalid date entered" is displayed. Other methods are like maskcurrency, what is Maskssn. The MaskTextBox client has two custom properties The first is the mask format, the second It is the true value of the text box, such as: ¥ 30.00 The true value is: 30.00. The problem currently encountered has a: how can the client text box pass back to the two properties mentioned above? I want to use a Hidden type control to store the true value of the mask text box with a Hidden type control. This will get true values ​​by passing the Value property of the corresponding hidden control to the server! The C # code snippet is as follows: protected override void render (HTMLTextWriter Output)

{

Output.writebegintag ("input");

Output.writeAttribute ("Type", "Hidden");

Output.writeAttribute ("Value", "");

Output.writeAttribute ("ID", "__" this.uniqueID);

Output.writeAttribute ("Name", "__" this.uniqueID);

Output.write (htmltextwriter.tagrightchar);

Base.Render (Output);

}

转载请注明原文地址:https://www.9cbs.com/read-66339.html

New Post(0)