I have created a compact table that allows users to edit, delete, and add records:
The table (DataGridView, bound) is user-friendly: click on "Edit" to enter the editing mode (which includes a "Cancel" option), update values, and then click "Add" to insert a new record.
Each field has specific rules (numeric values between x and y), so I have integrated them with MaskedEditExtender and MaskedEditValidator components:
(For example, for the first column):
<asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" HeaderText="First bus #">
<ItemTemplate>
<asp:Label runat="server" ID="BusIdStartLabel" Text='<% #Bind("BusIdStart","{0:D4}") %>' />
</ItemTemplate>
<EditItemTemplate>
<ajaxToolkit:MaskedEditExtender runat="server" ID="BusIdStartTextBoxMaskedEditExtender" TargetControlID="BusIdStartTextBox" BehaviorID="EditBusIdStartTextBoxBehavior"
MaskType="Number"
Mask="9999" PromptCharacter=" "
InputDirection="RightToLeft"
OnInvalidCssClass="maskedEditError" OnFocusCssClass="maskedEditFocus"
AutoComplete="False" ErrorTooltipEnabled="True" MessageValidatorTip="False" />
<ajaxToolkit:MaskedEditValidator runat="server" ID="BusIdStartTextBoxMaskedEditValidator" ControlToValidate="BusIdStartTextBox" ControlExtender="BusIdStartTextBoxMaskedEditExtender"
MinimumValue="0" MaximumValue="9999"
IsValidEmpty="False" Display="None"
InvalidValueMessage="Enter a value between 0000 and 9999"
MaximumValueMessage="Enter a value between 0000 and 9999"
EmptyValueMessage="Enter a value between 0000 and 9999" />
<asp:TextBox runat="server" ID="BusIdStartTextBox" Text='<% #Bind("BusIdStart","{0:D4}") %>' Width="2.5em" Height="13px" CssClass="rightAlignTextBox" />
</EditItemTemplate>
<FooterTemplate>
<ajaxToolkit:MaskedEditExtender runat="server" ID="BusIdStartTextBoxMaskedEditExtender" TargetControlID="BusIdStartTextBox" BehaviorID="FooterBusIdStartTextBoxBehavior"
MaskType="Number"
Mask="9999" PromptCharacter=" "
InputDirection="RightToLeft"
OnInvalidCssClass="maskedEditError" OnFocusCssClass="maskedEditFocus"
AutoComplete="False" ErrorTooltipEnabled="True" MessageValidatorTip="False" />
<ajaxToolkit:MaskedEditValidator runat="server" ID="BusIdStartTextBoxMaskedEditValidator" ControlToValidate="BusIdStartTextBox" ControlExtender="BusIdStartTextBoxMaskedEditExtender"
MinimumValue="0" MaximumValue="9999"
IsValidEmpty="False" Display="None"
InvalidValueMessage="Enter a value between 0000 and 9999"
MaximumValueMessage="Enter a value between 0000 and 9999"
EmptyValueMessage="Enter a value between 0000 and 9999" />
<asp:TextBox runat="server" ID="BusIdStartTextBox" Width="2.5em" Height="13px" CssClass="rightAlignTextBox" />
</FooterTemplate>
</asp:TemplateField>
The issue: Whenever any link (such as Edit or Delete) is clicked, it triggers validation for everything. So when clicking "Edit", it also validates (and returns "invalid") the "Insert" row. To prevent this, I attempted to disable validation using this method:
<asp:LinkButton runat="server" ID="ActionEditLink" CommandName="Edit" Text="Edit" OnClientClick="DeactivateValidation()" />
...
function DeactivateValidation() {
TryDispose('EditBusIdStartTextBoxBehavior');
TryDispose('FooterBusIdStartTextBoxBehavior');
//etc.
}
function TryDispose(behaviorId) {
var behavior = window.$find(behaviorId);
if (behavior != null)
behavior.dispose();
}
However, the validation remains active even after these attempts and continues to block the links. How can I effectively deactivate client-side validation?