11 Answers, 1 is accepted
Thank you for writing.
I am not sure that I fully understand your scenario. If you want to set a null value from RadMaskedEditBox to the data structure, RadMaskedEditBox does not currently support it. However, you can implement such option with using a Clear button for example.
Do not hesitate to contact me again if you have other questions
Best wishes,
Martin Vasilev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thank you for writing.
This is the UI For Winforms forum, I believe that your question has already been answered in the support ticket you have opened at Telerik UI for ASP.NET AJAX.
Should you have questions considering our suite do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
See What's Next in App Development. Register for TelerikNEXT.
I´am searching for the same solution for a long time, and it seem to me the most basic thing for one control. Setting it to empty.
When you clear the form for the next record or a new one, who do one clear the fields?
As incredibel as it seem to be the most dificul thing to do. If You set 'value' to '' does noithing. If you set 'text' to '', well it sems to work, but only changes the display. Even if You use clear still doesn't work.
Please advise.
Thank you for writing.
We have a similar issue which has been fixed in 2013, please check the feedback item which also suggests a workaround. With newer assemblies, I am unable to reproduce the incorrect behavior, setting RadMaskedEditBox.Value to null clears the text box.
If you are still experiencing issues please provide me with detailed information how I can reproduce the behavior on your end and also please specify what version of the suite you are using.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Hello, the fact that the Clear method doesn't work and setting the Value or Text props to "" doesn't work has cost me several hours of work.
When the form initializes, the RadMaskedEditBox control initializes with a blank "" value, not a null value. But to clear it, you have to set it to null, and the Clear() method (which the docs say clears the text from the control) seems useless. This is a very unintuitive API.
In order to reset the Value properly (to the initialized value of a blank string), you must call:
radMaskedEditBox2.Value =
null
;
radMaskedEditBox2.Value =
string
.Empty;
The source code for the control shows that Clear simply sets Text to "(string)null" which seems to get immediately reset to the stored underlying Value very easily (like refocusing the control). It seems as if the Clear method should set the Value to null instead (which would cause the Text to get set, too).
The Value getter has several conditions based on the different TextMaskFormat but all that gets overriden if "isNullValue" equals true (which seems to get set to false by simple things like key presses, regardless of the key).
Note, these issues are seen in 2014.3.1202.40. I can't confirm if newer versions have these problems.
Here is some sample code:
Designer:
//
// radMaskedEditBox2
//
this
.radMaskedEditBox2.Location =
new
System.Drawing.Point(12, 12);
this
.radMaskedEditBox2.Mask =
"000-00-0000"
;
this
.radMaskedEditBox2.MaskType = Telerik.WinControls.UI.MaskType.Standard;
this
.radMaskedEditBox2.Name =
"radMaskedEditBox2"
;
this
.radMaskedEditBox2.Size =
new
System.Drawing.Size(156, 24);
this
.radMaskedEditBox2.TabIndex = 0;
this
.radMaskedEditBox2.TabStop =
false
;
this
.radMaskedEditBox2.Text =
"___-__-____"
;
this
.radMaskedEditBox2.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
Code:
private
void
ClearAttempt1()
{
Debug.WriteLine(
"Attempt 1"
);
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
radMaskedEditBox2.Clear();
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
}
private
void
ClearAttempt2()
{
Debug.WriteLine(
"Attempt 2"
);
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
radMaskedEditBox2.Value =
string
.Empty;
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
}
private
void
ClearAttempt3()
{
Debug.WriteLine(
"Attempt 3"
);
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
radMaskedEditBox2.Text =
"___-__-____"
;
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
}
private
void
ClearAttempt4()
{
Debug.WriteLine(
"Attempt 4"
);
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
radMaskedEditBox2.Value =
null
;
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
radMaskedEditBox2.Value =
string
.Empty;
Debug.WriteLine(
"Text: {0}, Value: {1}, Mask: {2}"
, radMaskedEditBox2.Text ??
"[NULL]"
, radMaskedEditBox2.Value ??
"[NULL]"
, radMaskedEditBox2.Mask ??
"[NULL]"
);
}
Results (only Attempt 4 succeeds at setting null and then blank):
Attempt 1
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: , Value: 122442222, Mask: 000-00-0000
Attempt 2
Text: , Value: 122442222, Mask: 000-00-0000
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Attempt 3
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Attempt 4
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: ___-__-____, Value: [NULL], Mask: 000-00-0000
Text: ___-__-____, Value: , Mask: 000-00-0000
When the form initializes, the RadMaskedEditBox control initializes with a blank "" value, not a null value. But to clear it, you have to set it to null, and the Clear() method (which the docs say clears the text from the control) seems useless. This is a very unintuitive API.
In order to reset the Value properly (to the initialized value of a blank string), you must call:
radMaskedEditBox2.Value = null;
radMaskedEditBox2.Value = string.Empty;
The source code for the control shows that Clear simply sets Text to "(string)null" which seems to get immediately reset to the stored underlying Value very easily (like refocusing the control). It seems as if the Clear method should set the Value to null instead (which would cause the Text to get set, too).
The Value getter has several conditions based on the different TextMaskFormat but all that gets overriden if "isNullValue" equals true (which seems to get set to false by simple things like key presses, regardless of the key).
Note, these issues are seen in 2014.3.1202.40. I can't confirm if newer versions have these problems.
Here is some sample code:
Designer:
//
// radMaskedEditBox2
//
this.radMaskedEditBox2.Location = new System.Drawing.Point(12, 12);
this.radMaskedEditBox2.Mask = "000-00-0000";
this.radMaskedEditBox2.MaskType = Telerik.WinControls.UI.MaskType.Standard;
this.radMaskedEditBox2.Name = "radMaskedEditBox2";
this.radMaskedEditBox2.Size = new System.Drawing.Size(156, 24);
this.radMaskedEditBox2.TabIndex = 0;
this.radMaskedEditBox2.TabStop = false;
this.radMaskedEditBox2.Text = "___-__-____";
this.radMaskedEditBox2.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
Code:
private void ClearAttempt1()
{
Debug.WriteLine("Attempt 1");
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
radMaskedEditBox2.Clear();
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
}
private void ClearAttempt2()
{
Debug.WriteLine("Attempt 2");
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
radMaskedEditBox2.Value = string.Empty;
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
}
private void ClearAttempt3()
{
Debug.WriteLine("Attempt 3");
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
radMaskedEditBox2.Text = "___-__-____";
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
}
private void ClearAttempt4()
{
Debug.WriteLine("Attempt 4");
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
radMaskedEditBox2.Value = null;
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
radMaskedEditBox2.Value = string.Empty;
Debug.WriteLine("Text: {0}, Value: {1}, Mask: {2}", radMaskedEditBox2.Text ?? "[NULL]", radMaskedEditBox2.Value ?? "[NULL]", radMaskedEditBox2.Mask ?? "[NULL]");
}
Results (only Attempt 4 succeeds at setting null and then blank):
Attempt 1
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: , Value: 122442222, Mask: 000-00-0000
Attempt 2
Text: , Value: 122442222, Mask: 000-00-0000
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Attempt 3
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Attempt 4
Text: 122-44-2222, Value: 122442222, Mask: 000-00-0000
Text: ___-__-____, Value: [NULL], Mask: 000-00-0000
Text: ___-__-____, Value: , Mask: 000-00-0000
Thank you for writing.
The Clear method is inherited from the TextBoxBase class and is only responsible for deleting the text in the editor and is not related with the Value property. Setting the value to an empty string would not work because the value would get validated and it will not pass the requirements of the current mask.
With the latest version setting the Text property to its initial value sets produces the result you expect. If you stick with your current version as you have investigated you would need to use this approach:
radMaskedEditBox2.Value =
null
;
radMaskedEditBox2.Value =
string
.Empty;
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Thanks Hristo, that's good to know about the latest version. Far more intuitive that way.
If I could make one more suggestion: when you override the TextBoxBase, perhaps override the Clear method to either hide it completely from intellisense or override the functionality to properly clear it. It might want to be noted in the docs, too, since I read those and it seemed like the Clear method was the right way to do it.
Thank you for you suggestion.
I cannot confirm that we will add an overridden implementation of the Clear method, but for sure we will think of a better explanation in our documentation.
Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik