Wednesday, March 28, 2012

Programmatically defining the FilteredTextBoxExtender FilterType Property

Hi there!

I'm toying with the FilteredTextBoxExtender for a web portal we're developping at job, and thought it would simpler to define different data-entry textboxes.

With that objective in mind, I created a web user control that include a FilteredTextBoxExtender, its TextBox, some public properties to access underlying controls properties (like TextBox.Text, FilteredTextBoxExtender.FilterMode, etc.), plus a 'BoxType' private member (Type = internal enum) that's gonna define the different TextBoxes we might need (Postal codes, zip codes, money, Person namem email, and so on...)

Intended use is to simply drag the WUC on a page, define its _boxType member value, et voilĂ !

Problem is, I make a verification in the page_Load event of the WUC regarding the _boxType, and then would set the underlying extender's FilterType and ValidChars properties. But when I try to set a value for the FilterType property, I can't use more than one! The Toolkit references page says that you can use a '[...]comma-separated combination ofNumbers,LowercaseLetters,UppercaseLetters, andCustom[...]' but it won't accept the '+' operator for different FilterTypes, won't cast from string to FilterTypes (and vice versa)..

Anyone knows if that's intended?

Hi,

It's aflag enumeration. In ASP.NET's declarative markup you can specify multiple values with commas, but in C# you use the bitwise or operator |. For example, myExtender.FilterTypes = FilterTypes.UppercaseLetters | LowercaseLetters.

Thanks,
Ted


Thank you so very much, Ted. That did the trick!

And I'll most probably face that behavior a couple of times, thanks for the insight!

No comments:

Post a Comment