ASP.NET WebForms Textbox removes HTML5 pattern attribute

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?

Answers


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"];

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.

https://github.com/wet-boew/wet-boew/blob/0f614e0efd50df7970a6fc6bb72104e43b48e8f5/src/plugins/formvalid/formvalid.js#L105


Need Your Help

Custom attribute not working in custom directive of angularjs xeditable

javascript angularjs twitter-bootstrap angular-ui-bootstrap x-editable

I have just build bootstrap input group new directive in to the xeditable unfortunately the attribute not working as per documentation