I have a textbox with a masked exit extender that appears and works perfectly... until a postback occurs.
The control:
<asp:Label ID="lblWorkstation13" Text="Workstation Name (13):" AssociatedControlID="txtWorkstation13" CssClass="lblLabel" runat="server" />
<asp:TextBox ID="txtWorkstation13" MaxLength="13" Columns="16" AutoPostBack="true" runat="server" />
<asp:RequiredFieldValidator ID="rfvtxtWorkstation13" ControlToValidate="txtWorkstation13" Text="*" CssClass="valid" ErrorMessage="Workstation Name is required" Display="Dynamic" ValidationGroup="Submit" runat="server" />
<ajaxToolkit:MaskedEditExtender ID="meetxtWorkstation13" TargetControlID="txtWorkstation13" Mask="LL\-????\-?????" ClearMaskOnLostFocus="false" ClearTextOnInvalid="false" runat="server" />
<asp:RegularExpressionValidator ID="revtxtWorkstation13" ControlToValidate="txtWorkstation13" Text="!" CssClass="valid" ErrorMessage="Workstation Name must be entered as XX-XXXX-XXXXX" ValidationExpression="^([A-Z]{2})\-([A-Z0-9]{4})\-([A-Z0-9]{5})$" ValidationGroup="Submit" runat="server" />
The desired behavior:
limit input to two cap letters, dash, four cap letters or numbers, dash, five cap letters or numbers.
Before postback, the textbox text appears as AB-NAME-12345 (for example)
After postback, the textbox text appears as AB--NAM-E-123 (for example). The last two characters are truncated, the dashes are added, in addition to those supposed to be there, in the wrong place, and now the control does not validate.
I have installed updated Ajax Control Toolkit, etc. Any assistance would be appreciated.
Comments: This happens because of the way the MaskedEditExtender populates its initial value. It simply grabs a value from the server and tries to put it, char by char, to the mask, validating every character. But the value contains dashes that are the part of the mask, not the value. To easily workaround this issue, you can add the following code to your code behind: ``` txtWorkstation13.Text = txtWorkstation13.Text.Replace("-", ""); ```
The control:
<asp:Label ID="lblWorkstation13" Text="Workstation Name (13):" AssociatedControlID="txtWorkstation13" CssClass="lblLabel" runat="server" />
<asp:TextBox ID="txtWorkstation13" MaxLength="13" Columns="16" AutoPostBack="true" runat="server" />
<asp:RequiredFieldValidator ID="rfvtxtWorkstation13" ControlToValidate="txtWorkstation13" Text="*" CssClass="valid" ErrorMessage="Workstation Name is required" Display="Dynamic" ValidationGroup="Submit" runat="server" />
<ajaxToolkit:MaskedEditExtender ID="meetxtWorkstation13" TargetControlID="txtWorkstation13" Mask="LL\-????\-?????" ClearMaskOnLostFocus="false" ClearTextOnInvalid="false" runat="server" />
<asp:RegularExpressionValidator ID="revtxtWorkstation13" ControlToValidate="txtWorkstation13" Text="!" CssClass="valid" ErrorMessage="Workstation Name must be entered as XX-XXXX-XXXXX" ValidationExpression="^([A-Z]{2})\-([A-Z0-9]{4})\-([A-Z0-9]{5})$" ValidationGroup="Submit" runat="server" />
The desired behavior:
limit input to two cap letters, dash, four cap letters or numbers, dash, five cap letters or numbers.
Before postback, the textbox text appears as AB-NAME-12345 (for example)
After postback, the textbox text appears as AB--NAM-E-123 (for example). The last two characters are truncated, the dashes are added, in addition to those supposed to be there, in the wrong place, and now the control does not validate.
I have installed updated Ajax Control Toolkit, etc. Any assistance would be appreciated.
Comments: This happens because of the way the MaskedEditExtender populates its initial value. It simply grabs a value from the server and tries to put it, char by char, to the mask, validating every character. But the value contains dashes that are the part of the mask, not the value. To easily workaround this issue, you can add the following code to your code behind: ``` txtWorkstation13.Text = txtWorkstation13.Text.Replace("-", ""); ```