将 int32 数据绑定到启用 MaskedEditExtender 的 TextBox
我有一个使用 asp:DetailsView 编辑 asp:GridView 的主/详细方案。我的字段之一是 int64 类型的电话号码(始终为 10 位数字)。我希望此字段始终显示为 (###)###-####
。我的问题是电话号码中的第一个数字总是在我的编辑项目字段中被截断,我使用 MaskedEditExtender 来实现格式化。
这是我的详细信息视图的 EditItemTemplate:
<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>
当显示我的详细信息视图进行编辑时,文本框会显示整数 1234567890 的(_23)456-7890
。还值得注意的是,如果删除属性 MaskType="Number",则文本框会显示: <代码>(234)567-890_。我当然会让文本框在绑定后显示 (123)-546-67890
。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题可能是您没有为“(”、“)”和“-”使用“转义字符”。
可能想要将您的掩码从 更改为
根据
文档,没有“(”、“)”或“-”,因此您可能会告诉它做一些意想不到的事情。从关于掩码的部分...
/ - 日期分隔符
: - 时间分隔符
。 - 小数分隔符
, - 千位分隔符
\ - 转义字符
{ - 掩码重复的初始分隔符
} - 掩码重复的最终分隔符
示例
9999999 - 七个数字字符
99/99 - 四个数字字符中间用“/”分隔
< a href="http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx" rel="nofollow">http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx
Problem could be that you're not using "Escape Characters" for your "(", ")", and "-".
Might want to change your mask from
to
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
此问题似乎是与以下相关的错误:http://www. codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=11819
This issue appears to be a bug related to: http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=11819
我遇到了同样的问题,为我解决的方法是更改 MaskedEditExtender 的属性
“ClearMaskOnLostFocus”为 True。
I had the same issue, and what solved it for me was changing the MaskedEditExtender's property
"ClearMaskOnLostFocus" to True.
我也遇到了同样的问题,并且:
在面具中进行去专业化,例如:
将 ClearMaskOnLostFocus 设置为 true。
解决了问题。
谢谢大家。
I had the same issue too, and :
Doing despecialisation in the mask like :
With ClearMaskOnLostFocus set to true.
Solved the problem.
Thanks for all.