I have an ObjectDataSource object bound to a GridView. The object takes a parameter from a TextBox. The problem is that when I use ClientValidator with the ServerValidate event, the ObjectDataSource object will still try to execute the DataBind, even though the client validator returned false.
Below is the code on the aspx page.
<asp:TextBox ID="sittingDate" runat="server" />
<asp:CustomValidator ID="DateValidator" runat="server" ControlToValidate="sittingDate" OnServerValidate="DateValidator_ServerValidate" />
<asp:ObjectDataSource ID="BatchDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetOrCreateSittingBatch" TypeName="BatchBLL" OnSelected="BatchDataSource_Selected" OnSelecting="BatchDataSource_Selecting">
<SelectParameters>
<asp:ControlParameter ControlID="sittingDate" Name="batchDate" PropertyName="Text"
Type="DateTime" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="BatchGridView" runat="server" DataSourceID="BatchDataSource">
In the custom validator I
protected void DateValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
string input = args.Value;
DateTime result;
args.IsValid = DateTime.TryParse(input.TrimEnd(), out result);
}
How to stop ObjectDataSource from data binding after validation fails?
source
share