Databinding int32 to MaskedEditExtender enabled TextBox

风格不统一 提交于 2019-12-08 03:36:20

问题


I have a master/detail scheme for editing an asp:GridView using an asp:DetailsView. One of my fields is for a phone number of type int64 (always 10 digits). I would like this field to always be displayed as (###)###-####. My issue is the first digit in the phone number is always truncated for my edit item field which I used a MaskedEditExtender to achieve the formatting.

Here is my EditItemTemplate for the details view:

<cc1:MaskedEditExtender TargetControlID="edtPROJ_Leader_Phone" Mask="(999)999-9999" runat="server" ClearMaskOnLostFocus="false" ClipboardEnabled="true" MaskType="Number" />
<asp:TextBox ID="edtPROJ_Leader_Phone" runat="server" Text='<%# Bind("PROJ_Leader_Phone") %>' ></asp:TextBox>

When my details view is displayed for editing, the text box displays(_23)456-7890 for the integer 1234567890. Also worth noting that if the property MaskType="Number" is removed, the textbox shows: (234)567-890_. I would of course have the textbox show (123)-546-67890 after binding.


回答1:


Problem could be that you're not using "Escape Characters" for your "(", ")", and "-".

Might want to change your mask from

Mask="(999)999-9999"

to

Mask="\(999\)999\-9999"

According to the documentation, there is no "(", ")", or "-", so you may be telling it to do something unintended. From the section on masks...

/ - Date separator

: - Time separator

. - Decimal separator

, - Thousand separator

\ - Escape character

{ - Initial delimiter for repetition of masks

} - Final delimiter for repetition of masks

Examples

9999999 - Seven numeric characters

99/99 - Four numeric characters separated in the middle by a "/"

http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx




回答2:


This issue appears to be a bug related to: http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=11819




回答3:


I had the same issue, and what solved it for me was changing the MaskedEditExtender's property
"ClearMaskOnLostFocus" to True.




回答4:


I had the same issue too, and :

  1. Doing despecialisation in the mask like :

        Mask="\(999\)999\-9999",
    
  2. With ClearMaskOnLostFocus set to true.

Solved the problem.

Thanks for all.



来源:https://stackoverflow.com/questions/2412542/databinding-int32-to-maskededitextender-enabled-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!