On an ASP.NET web page I have an EntityDataSource:
<asp:EntityDataSource ID="EntityDataSourceOrders" runat="server"
ConnectionString="name=EntitiesContext"
DefaultContainerName="EntitiesContext"
EntitySetName="Order"
Select="it.OrderID,it.OrderCode,it.OrderDateTime"
Where="it.OrderDateTime >= @DateTimeFrom AND it.OrderDateTime <= @DateTimeTo"
OrderBy="it.SOrderCode"
StoreOriginalValuesInViewState="False" >
<WhereParameters>
<asp:ControlParameter Name="DateTimeFrom"
ControlID="TextBoxDateTimeFrom"
DbType="DateTime"
PropertyName="Text" />
<asp:ControlParameter Name="DateTimeTo"
ControlID="TextBoxDateTimeTo"
DbType="DateTime"
PropertyName="Text" />
</WhereParameters>
</asp:EntityDataSource>
As you can see there are two Textboxes on the page to enter an earliest and latest date for my selection. These Textboxes are used as ControlParameters in Where-clause of the EntityDataSource.
Now imagine someone enters an invalid date like "32/01/2010" in one of those ControlParameter textboxes.
I am aware that I can validate at first on client side (using the ASP.NET validators), so I prevent a postback if the input is invalid.
But how do I implement the more important "final" validation on server side? Especially WHERE (which method or event) do I implement it to prevent the EntityDataSource to execute the query with invalid DateTime values in the Textboxes?
Basically my idea was to call something like Page.Validate()
and then Page.IsValid
and, if IsValid returns false, to "cancel" the EntityDataSource query execution (or prevent it to start at all). But I don't know where or in which event I can hook up into the EntityDataSource to prevent the query execution.
Perhaps I am thinking into the wrong direction. Does somebody have an idea what to do?
Thank you in advance for help!