So I have a scenario where I need to change the filter type of an Filteredtextboxextender based on a value in the config file in my asp.net project.
This change propagates through about 80 input forms currently. Since my web.config value is a string I need to do an if statement on every page to define the filter type.
e.g.
If ConfigurationManager.AppSettings("SomeVariable") = "A" Then
txtLTWo_Filteredtextboxextender.FilterType = AjaxControlToolkit.FilterTypes.LowercaseLetters Or AjaxControlToolkit.FilterTypes.UppercaseLetters Or AjaxControlToolkit.FilterTypes.Numbers
ElseIf ConfigurationManager.AppSettings("SomeVariable") = "B" Then
txtLTWo_Filteredtextboxextender.FilterType = AjaxControlToolkit.FilterTypes.Numbers
Else
txtLTWo_Filteredtextboxextender.FilterType = AjaxControlToolkit.FilterTypes.Custom
txtLTWo_Filteredtextboxextender.ValidChars = "!QW"
End If
The problem here is that a change to a filter type for a particular result would have me changing every page.
I would really like a way to define it in the config file directly. Something like this, but obviously doesn't work.
txtML_Wo_Filteredtextboxextender.FilterType = ConfigurationManager.AppSettings("FilterType")
The only way to do it that I can come up with is to keep the filter as AjaxControlToolkit.FilterTypes.Custom
And then define the string of valid characters in the config file. However this would be a large string and seems senseless when the filter has the attributes I need.
Any ideas to streamline this would be great, thanks in advance.
Hum some ideas to float here:
On page pre render (not 100% sure of the event), the you can/could inject that code.
Or you simple have a global function in a code module that fetches the config settings you have, and then use this:
this:
becomes:
Or say Module1.FilterType().
So, we could say have a global vb function, and then use a sever side expression in the markup settings.
I don't know what (if) those values like Filter Type "LowercaseLetters" are string or enum???
However, a server side expression in the markup could and should work.