Used standard setup for validation. DynamicValidator control for the main dataentry control (a Formview) and a ValidationSummary control. Validation rules are set using attributes in the Meta class. Delete checking and cross validation (result depends on
the value of more than a single field) are done in OnValidate(), throwing a ValidationException for failures.
This works perfectly. Validation and Delete failure (referentail integrity violations) messages are displayed in the Validation Summary. EXCEPT for when I have a formview or gridview within a formview. I should add that they are actually within an TabPanel
of an AJAX Toolkit TabContainer, withn a Formview.
There is a problem with the internal formview and gridview. The attribute validation messages are displayed fine, but not the OnValidate() messages. The ValidationException is not caught by the DynamicValidator, and instead appears as an unhandled exception
in the RowDeleted/ItemUpdated events. I delete from the internal gridview, and insert/update from the internal formview.
Having a forview within a formview is a user requirement for one of my web pages.
Anyway, I have to go to the RowDeleted/ItemUpdated event and check for any unhandled ValidationExceptions, and manually display the message in a label. I don't think I should have to do this. Is it a Dynamic Data problem or am I doing something wrong (apart
from the formview within formview, which is a user requirement.)
Yes I have that at the back of my mind Stephen, but it is a cost vs. functionality decision for the client.
Just in case it was a black magic solution I want ahead and tried it, but not.
I put in a new DynamicValidator and ValidationSummary controls with ValidationGroup set to Group1, and assigned that same group to the Update button for the internal Formview. (I didn't need to apply the ValidationGroup anywhere else because individual field
validation errors are displayed fine. It is just he OnValidate error messages that do not display.) Again the ValidationException is thrown by OnValidate but not caught. In the ItemUpdated event, it ispassed in the event args as a (unhandled) exception.
I know it's going out on a limb with my limited experience here but I really think it is a DD bug.
I know it's going out on a limb with my limited experience here but I really think it is a DD bug.
Sorry no it's not I have this same situation, I have multiple gridviews and formfiews embeded and have no issues, the one thing you did not mention was the fields must also have validation group set.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Hi Stephen. I went back and applied the ValidationGroup to all the properties. Same problem. If it had worked, it would have been a "magic " solution to me anyway, meaning I wouldn't understand why it worked.
Have you seen the problem occur over there?
If not, I might try to do a simple case example and post up the code.
I wonder if the TabContainer could be causing a problem.
Hi Cbirch, like I said before, I have a DetailsList page which consists of two FormViews one hold the Details and the other FormView shows in an AJAX Tab container all the Children Tables each in a ListView. Each ListView has inlince Edit and Insert enabled
and all works fine.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I'll do a simple case tomorrow and post the code. Maybe you'll see something wrong. I'll include a ValidationGroup. It's 9:25pm here and I was working too late last night to be much good now. Thanks for replying.
Thanks for looking at this. I have reproduced the problem in a very simple page. It uses the AdventureWorksLT2008R2 database, so let me know if it would be simpler for me to email you the project (and on what email address).
Problem 1.
OrderDate in fvSalesOrderHeader is a required field. If you blank out the field and then Update, the required field message only shows next to the field, not in the validation messages at the top. You have to press Update again to make it appear in the validation
messages.
Then, if you input a valid date and Update, it is again a two state process to clear the messages. First the message beside the field clears, then the message at the top (on the second press of Update).
Problem 2.
I have hard-coded a ValidationException in the OnValidate method for SalesOrderHeader. If you enter a valid date and Update, no message is ever shown. I think this is something to do with the two-stage process being interrupted, since the ValidationException
bubbles up to the top (Internet Exporer breakpoints with Display a Notifcation About Every Script Error enabled).
Private Sub OnValidate(ByVal action As System.Data.Linq.ChangeAction)
Dim errMsg As String = ""
If action = Data.Linq.ChangeAction.Update Then
Using DC As New AdventureWorksDataContext
Dim bValid As Boolean = False
If Not bValid Then
errMsg = "Testing SalesOrderHeader OnValidate Error Messages"
Throw New ValidationException(errMsg)
End If
End Using
End If
End Sub
cbirch
Member
10 Points
18 Posts
Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 20, 2010 08:22 AM|LINK
A newbie to Dynamic Data.
Used standard setup for validation. DynamicValidator control for the main dataentry control (a Formview) and a ValidationSummary control. Validation rules are set using attributes in the Meta class. Delete checking and cross validation (result depends on the value of more than a single field) are done in OnValidate(), throwing a ValidationException for failures.
This works perfectly. Validation and Delete failure (referentail integrity violations) messages are displayed in the Validation Summary. EXCEPT for when I have a formview or gridview within a formview. I should add that they are actually within an TabPanel of an AJAX Toolkit TabContainer, withn a Formview.
There is a problem with the internal formview and gridview. The attribute validation messages are displayed fine, but not the OnValidate() messages. The ValidationException is not caught by the DynamicValidator, and instead appears as an unhandled exception in the RowDeleted/ItemUpdated events. I delete from the internal gridview, and insert/update from the internal formview.
Having a forview within a formview is a user requirement for one of my web pages.
Anyway, I have to go to the RowDeleted/ItemUpdated event and check for any unhandled ValidationExceptions, and manually display the message in a label. I don't think I should have to do this. Is it a Dynamic Data problem or am I doing something wrong (apart from the formview within formview, which is a user requirement.)
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 20, 2010 03:02 PM|LINK
You may need to use validation groups for each different dataq control on the page [:)]
Dynamic Data
Always seeking an elegant solution.
cbirch
Member
10 Points
18 Posts
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 04:20 AM|LINK
Yes I have that at the back of my mind Stephen, but it is a cost vs. functionality decision for the client.
Just in case it was a black magic solution I want ahead and tried it, but not.
I put in a new DynamicValidator and ValidationSummary controls with ValidationGroup set to Group1, and assigned that same group to the Update button for the internal Formview. (I didn't need to apply the ValidationGroup anywhere else because individual field validation errors are displayed fine. It is just he OnValidate error messages that do not display.) Again the ValidationException is thrown by OnValidate but not caught. In the ItemUpdated event, it ispassed in the event args as a (unhandled) exception.
I know it's going out on a limb with my limited experience here but I really think it is a DD bug.
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 07:14 AM|LINK
Sorry no it's not I have this same situation, I have multiple gridviews and formfiews embeded and have no issues, the one thing you did not mention was the fields must also have validation group set.
Dynamic Data
Always seeking an elegant solution.
cbirch
Member
10 Points
18 Posts
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 09:22 AM|LINK
Hi Stephen. I went back and applied the ValidationGroup to all the properties. Same problem. If it had worked, it would have been a "magic " solution to me anyway, meaning I wouldn't understand why it worked.
Have you seen the problem occur over there?
If not, I might try to do a simple case example and post up the code.
I wonder if the TabContainer could be causing a problem.
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 11:20 AM|LINK
Hi Cbirch, like I said before, I have a DetailsList page which consists of two FormViews one hold the Details and the other FormView shows in an AJAX Tab container all the Children Tables each in a ListView. Each ListView has inlince Edit and Insert enabled and all works fine.
Dynamic Data
Always seeking an elegant solution.
cbirch
Member
10 Points
18 Posts
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 11:27 AM|LINK
Catherine.
I'll do a simple case tomorrow and post the code. Maybe you'll see something wrong. I'll include a ValidationGroup. It's 9:25pm here and I was working too late last night to be much good now. Thanks for replying.
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 21, 2010 12:02 PM|LINK
I'll look in tomorrow [:)]
Dynamic Data
Always seeking an elegant solution.
cbirch
Member
10 Points
18 Posts
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 22, 2010 03:14 AM|LINK
Stephen.
Thanks for looking at this. I have reproduced the problem in a very simple page. It uses the AdventureWorksLT2008R2 database, so let me know if it would be simpler for me to email you the project (and on what email address).
Problem 1.
OrderDate in fvSalesOrderHeader is a required field. If you blank out the field and then Update, the required field message only shows next to the field, not in the validation messages at the top. You have to press Update again to make it appear in the validation messages.
Then, if you input a valid date and Update, it is again a two state process to clear the messages. First the message beside the field clears, then the message at the top (on the second press of Update).
Problem 2.
I have hard-coded a ValidationException in the OnValidate method for SalesOrderHeader. If you enter a valid date and Update, no message is ever shown. I think this is something to do with the two-stage process being interrupted, since the ValidationException bubbles up to the top (Internet Exporer breakpoints with Display a Notifcation About Every Script Error enabled).
Regards,
Catherine
<%@ Page Language="VB" MasterPageFile="~/Site.master" CodeFile="Edit.aspx.vb" Inherits="Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<h2>Edit entry from table <%= table.DisplayName %></h2>
<asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" EnableClientScript="true" ValidationGroup="Group1"
HeaderText="List of validation errors" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" />
<asp:DynamicValidator runat="server" ID="DynamicValidator1" ValidationGroup="Group1" ControlToValidate="FormView1" Display="None" />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="CustomerID"
DataSourceID="DetailsDataSource" CssClass="detailstable" DefaultMode="Edit" >
<EditItemTemplate>
<asp:LinkButton ID="lbtnUpdate" runat="server" CommandName="Update" Text="Update and Return" CausesValidation="true" style="font-size:12pt"></asp:LinkButton>
<asp:LinkButton ID="lbtnCancel" runat="server" CommandName="Cancel" Text="Cancel and Return" CausesValidation="false" style="font-size:12pt"></asp:LinkButton>
<br /><br />
<br />
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" >
<cc1:TabPanel ID="tpSalesOrderHeaders" runat="server" HeaderText="SalesOrderHeaders">
<ContentTemplate>
<br />
<asp:FormView ID="fvSalesOrderHeader" runat="server" DataKeyNames="SalesOrderID"
Caption='<div>Selected Sales Order</div>'
DataSourceID="ldsSalesOrderHeader" CssClass="detailstable" DefaultMode="Edit" >
<EditItemTemplate>
<table runat="server" id="tblTop" style="width: 100%; font-size: 8pt">
<tr>
<td>Order Date</td><td colspan="5">
<asp:DynamicControl ID="dcOrderDate" ValidationGroup="Group1" mode="Edit" DataField="OrderDate" runat="server" />
</td></tr><tr>
<td colspan="6">
<asp:LinkButton ID="UpdateButton" ValidationGroup="Group1" causesValidation="true" Text="Update SalesOrderHeader" CommandName="Update" RunAt="server" CssClass="sub_update " />
<asp:LinkButton ID="CancelUpdateButton" CausesValidation="false" Text="Cancel" CommandName="Cancel" RunAt="server" CssClass="sub_update "/>
</td></tr></table></EditItemTemplate>
<EmptyDataTemplate>
No SalesOrderHeader selected.
</EmptyDataTemplate>
</asp:FormView>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
</EditItemTemplate>
</asp:FormView>
<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true">
<WhereParameters>
<asp:DynamicQueryStringParameter />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="ldsSalesOrderHeader" runat="server"
ContextTypeName="AdventureWorksDataContext"
TableName="SalesOrderHeaders"
EnableUpdate="True" Where="SalesOrderID == @SalesOrderID" >
<WhereParameters>
<asp:Parameter DefaultValue="71946" Name="SalesOrderID" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
---------------------------------------------------------------------------
Private Sub OnValidate(ByVal action As System.Data.Linq.ChangeAction)
Dim errMsg As String = ""
If action = Data.Linq.ChangeAction.Update Then
Using DC As New AdventureWorksDataContext
Dim bValid As Boolean = False
If Not bValid Then
errMsg = "Testing SalesOrderHeader OnValidate Error Messages"
Throw New ValidationException(errMsg)
End If
End Using
End If
End Sub
cbirch
Member
10 Points
18 Posts
Re: Formview/Gridview withinTabContainer within Formview - No ValidatorSummary Messages
Apr 22, 2010 03:28 AM|LINK
P.S. Visual Web Developer 2008 Express and SQL Server 2008 Express.