This is a migrated thread and some comments may be shown as answers.

RadMaskedEditBox

11 Answers 261 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
JOSE MANUEL PÉREZ RAMÍREZ
Top achievements
Rank 1
JOSE MANUEL PÉREZ RAMÍREZ asked on 23 Jun 2009, 12:36 PM
i have one RadMaskedEdit bind to object, with date mask.
My object sets a value in radMasked and if i want to clear or set to null then radmasked does not clear.
the control does not set to empty.
how i do?

11 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 26 Jun 2009, 06:57 AM
Hi JOSE MANUEL PÉREZ RAMÍREZ,

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.
0
Robert
Top achievements
Rank 1
answered on 31 Mar 2015, 06:39 PM
Is there still no way to Clear a value from a RadMaskedEdit Editor after it has been set, even with 2015 Q1 Version of the controls. We find that if you clear the box, on Postback it still has the value and submits that to the database.
0
Hristo
Telerik team
answered on 03 Apr 2015, 12:26 PM
Hi Robert,

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.

 
0
Sergio
Top achievements
Rank 1
answered on 19 Jul 2015, 10:29 AM

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. 

 

0
Hristo
Telerik team
answered on 22 Jul 2015, 08:56 AM
Hello Sergio,

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

0
Adam P
Top achievements
Rank 2
answered on 23 Aug 2015, 11:31 AM

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

0
Adam P
Top achievements
Rank 2
answered on 23 Aug 2015, 11:31 AM
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
0
Adam P
Top achievements
Rank 2
answered on 23 Aug 2015, 11:33 AM
Sorry for the double posting, I got an error when I first submitted (but did a Select All + Copy before submitting) and reposted with my formatting lost lol
0
Hristo
Telerik team
answered on 26 Aug 2015, 11:38 AM
Hi Adam,

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

0
Adam P
Top achievements
Rank 2
answered on 27 Aug 2015, 04:57 AM

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.

0
Hristo
Telerik team
answered on 31 Aug 2015, 12:11 PM
Hello Adam,

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

Tags
MaskedEditBox
Asked by
JOSE MANUEL PÉREZ RAMÍREZ
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Robert
Top achievements
Rank 1
Hristo
Telerik team
Sergio
Top achievements
Rank 1
Adam P
Top achievements
Rank 2
Share this question
or