Reputation: 879
Let's say that I have a textbox in a webforms project that looks like this:
<asp:textbox id="TextBox1" runat="server" pattern="[A-Za-z0-9\s]{4,}"/>
Upon rendering, the pattern attribute is removed. If I add the attribute in the code-behind the attribute is also removed:
TextBox1.Attributes.Add("pattern", "[A-Za-z0-9\\s]{4,}");
It doesn't matter what the pattern actually is. It's the attribute named "pattern" that is scrubbed-out upon rendering. Name the attribute something else and it will be rendered.
I can find no documentation about this and nobody with the same problem. Has anybody got a work-around, short of writing a custom server control that extends TextBox?
Upvotes: 1
Views: 3249
Reputation: 879
I've tracked it down to the use of the Web Experience Toolkit. Specifically, the part that reads, "Remove the pattern attribute until it is safe to use with jQuery Validation". Will file an issue with them.
Upvotes: 1
Reputation: 625
Your patter attribute is not being removed. If you define your pattern as the pattern attribute of the textbox:
<asp:textbox id="TextBox1" runat="server" pattern="[A-Za-z0-9\s]{4,}"/>
Then in your code behind you can check the value:
var r = TextBox1.Attributes["pattern"];
Upvotes: 1