Getting Literal Value from a Masked Text Box Input

荒凉一梦 提交于 2019-12-13 17:42:59

问题


I've set up a Telerik RadMaskedTextBox with a Mask of "####-####". The problem is, when I later grab the value from this box it returns as "########". I'm unfamiliar with MaskedTextBoxes but I'm guessing that this is the default way it's supposed to return my value.

How can I set the "-" as a literal character in the RadMaskedTextBox so it returns the whole value?

ex. "1234-5678" instead of "12345678"


回答1:


Use TextWithLiterals instead of Text property.




回答2:


I'm unfamiliar with the Telerik controls, but you know the mask and you know the value you're getting, so you can construct the formatted value yourself:

var val = control.Text;
var mask = control.Mask;
var v = 0;
var builder = new StringBuilder();

foreach(var c in mask)
   builder.Append(c == '#' ? val[v++] : c);

return builder.ToString();


来源:https://stackoverflow.com/questions/6945986/getting-literal-value-from-a-masked-text-box-input

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