On a page I have a gridview and a formview which shows the details of the selected record in the gridview.
Now in this FormView I have a tabcontainer with 6 tabs and each tab shows child tables.
Now the default validation is all working, so for example if a field which can't be empty is empty and they save the child record, then the validation fires off and shows the message just like default DD behavior. However I have added added some custom logic
when the child record is being saved like this:
public partial class AM_Entities
{
partial void OnContextCreated()
{
this.SavingChanges += new EventHandler(context_SavingChanges);
}
private static void context_SavingChanges(object sender, EventArgs e)
{
foreach (ObjectStateEntry entry in
((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified))
{
if ((entry.Entity.GetType() == typeof(AM_ARTICLE_SUPPLIER)))
{
AM_ARTICLE_SUPPLIER CurrentEntity = (AM_ARTICLE_SUPPLIER)entry.Entity;
if (entry.State == EntityState.Modified)
{
if (CurrentEntity.IsPreferred)
{
using (AM_Entities entities = new AM_Entities())
{
AM_ARTICLE_SUPPLIER ExistingIsPreferredRecord = (from rec in entities.AM_ARTICLE_SUPPLIER
where rec.IsPreferred
select rec).FirstOrDefault();
if (ExistingIsPreferredRecord != null)
{
throw new ValidationException("There already is a preferred supplier for article.");
}
}
}
}
}
}
}
}
That validatonExcption fires off an error in IE. It gives a popup which describes the error, but it should show it as a vlidation message just like where the default validation messages are shown.
I've tried to add an extra DynamicValidator, but I keep getting errors that it can't find the childgrid:
That validatonExcption fires off an error in IE. It gives a popup which describes the error, but it should show it as a vlidation message just like where the default validation messages are shown.
For this problem, because I didn't see your aspx codes……But I strongly recommand you trying to use the recursive FindControl instead of the normal one:
Well my code is nothing more than this at the end of my Page_Load event:
if (FormView1.CurrentMode == FormViewMode.ReadOnly)
{
TabContainer tabs = FormView1.Row.FindControl("TabContainer1") as TabContainer;
TabPanel tab = tabs.FindControl("TabPanel4") as TabPanel;
GridView relationsGrid = tab.FindControl("Article_Supplier_Gridview") as GridView;
RequiredFieldValidator ChildGridSupplierValidator = new RequiredFieldValidator();
ChildGridSupplierValidator.CssClass = "DDValidator";
ChildGridSupplierValidator.Display = ValidatorDisplay.None;
ChildGridSupplierValidator.ControlToValidate = relationsGrid.UniqueID;
UpdatePanel1.ContentTemplateContainer.Controls.Add(ChildGridSupplierValidator);
}
When I debug those lines it actually does find the GridView and the UniqueID is the correct one if you ask me, so I'm not sure if I should be looking at your recursive example or not. However when I add the validator to my updatepanel it keeps giving me
this error:
Unable to find control id 'ctl00$ContentPlaceHolder1$FormView1$TabContainer1$TabPanel4$Article_Supplier_Gridview' referenced by the 'ControlToValidate' property of ''.]
You're going to drown in code if I post my aspx ( 3221 lines so far ), but it's a customized ListDetails.aspx with in the formview a tabcontainer and on the 4th tab there's a grid which shows for example all related orderdetails of an order.
Anyway here's a piece of it. Search for TabPanel4 and you'll find the child grid. What I want is that the validation messages for this child grid are shown at the top where all the default validation messages are shown.
PS: I've tried to use the ClientID, the ID and the UniqueID, but nothing seems to work ...
PS2: Could it have something to do with Page_Load? I've tried in Page_Init, but I can't get it to work there either.
Now I was trying something else:
I added a second validationsummary at the top of my page and gave it the same validationgroup as the button which saves the changed child record.
But again, it results in a web page error in IE instead of nicely showing the validation message in the summary ...
The same code as before in my entities partial class:
public partial class AM_Entities { partial void OnContextCreated() { this.SavingChanges += new EventHandler(context_SavingChanges); } private static void context_SavingChanges(object sender, EventArgs e) { foreach (ObjectStateEntry entry in ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)) { if ((entry.Entity.GetType() == typeof(AM_ARTICLE))) { AM_ARTICLE CurrentEntity = (AM_ARTICLE)entry.Entity; if (entry.State == EntityState.Added) { CurrentEntity.Date_Creation_AM = DateTime.Now; } else if (entry.State == EntityState.Modified) { CurrentEntity.Date_Modified_AM = DateTime.Now; } } if ((entry.Entity.GetType() == typeof(AM_ARTICLE_SUPPLIER))) { AM_ARTICLE_SUPPLIER CurrentEntity = (AM_ARTICLE_SUPPLIER)entry.Entity; if (entry.State == EntityState.Modified) { if (CurrentEntity.IsPreferred) { using (AM_Entities entities = new AM_Entities()) { AM_ARTICLE_SUPPLIER ExistingIsPreferredRecord = (from rec in entities.AM_ARTICLE_SUPPLIER where rec.IsPreferred select rec).FirstOrDefault(); if (ExistingIsPreferredRecord != null) { throw new ValidationException("There already is a preferred supplier for this article."); } } } } } } } }
Yannick86
Member
565 Points
366 Posts
Childgrid custom validation
Nov 22, 2011 09:57 AM|LINK
Dear,
On a page I have a gridview and a formview which shows the details of the selected record in the gridview.
Now in this FormView I have a tabcontainer with 6 tabs and each tab shows child tables.
Now the default validation is all working, so for example if a field which can't be empty is empty and they save the child record, then the validation fires off and shows the message just like default DD behavior. However I have added added some custom logic when the child record is being saved like this:
public partial class AM_Entities { partial void OnContextCreated() { this.SavingChanges += new EventHandler(context_SavingChanges); } private static void context_SavingChanges(object sender, EventArgs e) { foreach (ObjectStateEntry entry in ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)) { if ((entry.Entity.GetType() == typeof(AM_ARTICLE_SUPPLIER))) { AM_ARTICLE_SUPPLIER CurrentEntity = (AM_ARTICLE_SUPPLIER)entry.Entity; if (entry.State == EntityState.Modified) { if (CurrentEntity.IsPreferred) { using (AM_Entities entities = new AM_Entities()) { AM_ARTICLE_SUPPLIER ExistingIsPreferredRecord = (from rec in entities.AM_ARTICLE_SUPPLIER where rec.IsPreferred select rec).FirstOrDefault(); if (ExistingIsPreferredRecord != null) { throw new ValidationException("There already is a preferred supplier for article."); } } } } } } } }That validatonExcption fires off an error in IE. It gives a popup which describes the error, but it should show it as a vlidation message just like where the default validation messages are shown.
I've tried to add an extra DynamicValidator, but I keep getting errors that it can't find the childgrid:
Same happens when I try to set it like this in my Page_Load event:
if (FormView1.CurrentMode == FormViewMode.ReadOnly) { ChildGridSupplier.ControlToValidate = "Article_Supplier_Gridview"; }And I also tried this:
TabContainer tabs = FormView1.Row.FindControl("TabContainer1") as TabContainer; TabPanel tab = tabs.FindControl("TabPanel4") as TabPanel; GridView relationsGrid = tab.FindControl("Article_Supplier_Gridview") as GridView; ChildGridSupplierValidator.ControlToValidate = relationsGrid.ClientID;Anyone got an idea?
Thanks in advance,
- Yannick
Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 23, 2011 01:34 PM|LINK
Anyone got an idea?
This is really urgent for me, so pretty please :)
Thanks in advance,
- Yannick
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Childgrid custom validation
Nov 24, 2011 12:56 AM|LINK
For this problem, because I didn't see your aspx codes……But I strongly recommand you trying to use the recursive FindControl instead of the normal one:
http://stevesmithblog.com/blog/recursive-findcontrol/
// Source: http://intrepidnoodle.com/articles/24.aspx{/// <summary>/// Similar to Control.FindControl, but recurses through child controls./// </summary>{{return found;/// <summary>/// Similar to Control.FindControl, but recurses through child controls./// Assumes that startingControl is NOT the control you are searching for./// </summary>{T found = null;{found = activeControl as T;{{break;return found;With this in place, you can easily access it from your Page by using a Base Page Class and adding these methods to it:
<div> <div style="padding: 0px; width: 100%; color: black; line-height: 12pt; overflow: visible; font-family: consolas,'Courier New',courier,monospace; font-size: 8pt; background-color: #f4f4f4;">// Source: http://intrepidnoodle.com/articles/24.aspx{// We know the control we're searching for isn't the Page itself,// so we use the more performant FindChildControl to search.return FindChildControl<T>(Page, id);{{return ControlFinder.FindChildControl<T>(startingControl, id);</div> </div>Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 24, 2011 06:34 AM|LINK
Well my code is nothing more than this at the end of my Page_Load event:
if (FormView1.CurrentMode == FormViewMode.ReadOnly) { TabContainer tabs = FormView1.Row.FindControl("TabContainer1") as TabContainer; TabPanel tab = tabs.FindControl("TabPanel4") as TabPanel; GridView relationsGrid = tab.FindControl("Article_Supplier_Gridview") as GridView; RequiredFieldValidator ChildGridSupplierValidator = new RequiredFieldValidator(); ChildGridSupplierValidator.CssClass = "DDValidator"; ChildGridSupplierValidator.Display = ValidatorDisplay.None; ChildGridSupplierValidator.ControlToValidate = relationsGrid.UniqueID; UpdatePanel1.ContentTemplateContainer.Controls.Add(ChildGridSupplierValidator); }When I debug those lines it actually does find the GridView and the UniqueID is the correct one if you ask me, so I'm not sure if I should be looking at your recursive example or not. However when I add the validator to my updatepanel it keeps giving me this error:
Unable to find control id 'ctl00$ContentPlaceHolder1$FormView1$TabContainer1$TabPanel4$Article_Supplier_Gridview' referenced by the 'ControlToValidate' property of ''.]
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Childgrid custom validation
Nov 24, 2011 06:41 AM|LINK
Hello:)
How did you add validator? You mean just add one so the code fails?
PS: Have a try of mine first. And plz list your aspx codes if possible.
Best reguards!
Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 24, 2011 06:51 AM|LINK
You're going to drown in code if I post my aspx ( 3221 lines so far ), but it's a customized ListDetails.aspx with in the formview a tabcontainer and on the 4th tab there's a grid which shows for example all related orderdetails of an order.
Anyway here's a piece of it. Search for TabPanel4 and you'll find the child grid. What I want is that the validation messages for this child grid are shown at the top where all the default validation messages are shown.
PS: I've tried to use the ClientID, the ID and the UniqueID, but nothing seems to work ...
PS2: Could it have something to do with Page_Load? I've tried in Page_Init, but I can't get it to work there either.
<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="ListDetails.aspx.cs" Inherits="AMT.DynamicData.CustomPages.AM_ARTICLE.ListDetails" %> <%@ Register Src="~/DynamicData/Content/GridViewPager.ascx" TagName="GridViewPager" TagPrefix="asp" %> <asp:Content ID="headContent" ContentPlaceHolderID="head" runat="Server"> <script language="javascript" type="text/javascript"> function fncInputNumericValuesOnly() { //44 is komma, 46 is punt. if (!(event.keyCode == 44 || event.keyCode == 45 || event.keyCode == 48 || event.keyCode == 49 || event.keyCode == 50 || event.keyCode == 51 || event.keyCode == 52 || event.keyCode == 53 || event.keyCode == 54 || event.keyCode == 55 || event.keyCode == 56 || event.keyCode == 57)) { event.returnValue = false; } } </script> </asp:Content> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true"> <DataControls> <asp:DataControlReference ControlID="FormView1" /> <asp:DataControlReference ControlID="GridView1" /> </DataControls> </asp:DynamicDataManager> <%-- <h2 class="DDSubHeader"><%= table.DisplayName %></h2>--%> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div class="DD"> <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true" HeaderText="List of validation errors" CssClass="DDValidator" /> <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" /> <asp:DynamicValidator runat="server" ID="FormViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" /> <asp:Table ID="Table1" runat="server"> <asp:TableRow> <asp:TableCell VerticalAlign="Top"> <asp:Panel ID="GridPanel" Width="900" ScrollBars="Horizontal" runat="server"> <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true" AutoGenerateSelectButton="false" AutoGenerateEditButton="false" AutoGenerateDeleteButton="false" AllowPaging="True" AllowSorting="True" OnDataBound="GridView1_DataBound" OnRowEditing="GridView1_RowEditing" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowDeleted="GridView1_RowDeleted" OnRowUpdated="GridView1_RowUpdated" OnRowCreated="GridView1_RowCreated" CssClass="DDGridView" RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6" OnPageIndexChanging="GridView1_PageIndexChanging" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="false" PagerSettings-PageButtonCount="10" PageSize="15"> <PagerStyle CssClass="DDFooter" /> <SelectedRowStyle CssClass="DDSelected" /> <PagerTemplate> <asp:GridViewPager ID="GridViewPager1" runat="server" /> </PagerTemplate> <EmptyDataTemplate> There are currently no items in this table. </EmptyDataTemplate> <Columns> <asp:TemplateField ShowHeader="false"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="TDtester" /> <ItemTemplate> <table> <tr> <td> <asp:ImageButton ID="BtnSelect" runat="server" CausesValidation="false" CommandName="Select" ImageUrl="../../Content/Images/OpenLetter.png" ToolTip="Select" /> </td> <td> <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" CommandName="Edit" ImageUrl="../../Content/Images/Edit.png" ToolTip="Edit" /> </td> <td> <asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="false" CommandName="Delete" ImageUrl="../../Content/Images/Trash.png" ToolTip="Delete" OnClientClick='return confirm("Are you sure you want to delete this item?");' /> </td> </tr> </table> </ItemTemplate> <EditItemTemplate> <table> <tr> <td> <asp:ImageButton ID="BtnSelect" runat="server" CommandName="Update" ImageUrl="../../Content/Images/Accept.png" ToolTip="Update" /> </td> <td> </td> <td> <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="../../Content/Images/No.png" ToolTip="Cancel" /> </td> </tr> </table> </EditItemTemplate> </asp:TemplateField> <asp:DynamicField DataField="ArticleName_EN" HeaderText="Article Name" /> <asp:DynamicField DataField="ArticleNumber" /> <asp:DynamicField DataField="AM_MANUFACTURER1" /> <asp:DynamicField DataField="AM_PRODUCT_FAMILY1" /> <asp:DynamicField DataField="AM_PRODUCT_SUBFAMILY1" /> <asp:DynamicField DataField="UsableOnOfferte" HeaderText="Usable" /> <asp:DynamicField DataField="PhasedOut" HeaderText="PO" /> </Columns> </asp:GridView> </asp:Panel> </asp:TableCell> <asp:TableCell VerticalAlign="Top"> <asp:Panel ID="DetailsPanel" runat="server"> <asp:FormView ID="FormView1" runat="server" DataSourceID="DetailsDataSource" RenderOuterTable="false" OnPreRender="FormView1_PreRender" OnModeChanging="FormView1_ModeChanging" OnItemUpdated="FormView1_ItemUpdated" OnItemInserted="FormView1_ItemInserted" OnItemDeleted="FormView1_ItemDeleted" OnItemUpdating="FormView1_ItemUpdating" OnDataBound="FormView1_DataBound"> <HeaderTemplate> <%--<table id="detailsTable" class="DDDetailsTable" cellpadding="6">--%> <table id="detailsTable" class="DDDetailsTableCustom" cellpadding="6"> </HeaderTemplate> <ItemTemplate> <tr class="td"> <td> <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" OnActiveTabChanged="TabContainer1_TabChanged" AutoPostBack="true"> <ajaxToolkit:TabPanel ID="TabPanel1" HeaderText="General" runat="server"> <ContentTemplate> <table id="detailsTable" class="DDDetailsTable" cellpadding="6" width="100%"> <tr class="td"> <td> <asp:Label ID="Label21" runat="server" Font-Bold="true">Article N°: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl9" DataField="ArticleNumber" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label31" runat="server" Font-Bold="true">Manufacturer article N°: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl5" DataField="Manufacturer_ArticleID" runat="server" Mode="ReadOnly" /> </td> </tr> <tr> <td colspan="2" style="padding: 0px;"> <asp:Label runat="server"> </asp:Label> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label35" runat="server" Font-Bold="true">EN: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl7" DataField="ArticleName_EN" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label36" runat="server" Font-Bold="true">FR: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl8" DataField="ArticleName_FR" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label37" runat="server" Font-Bold="true">NL: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl10" DataField="ArticleName_NL" runat="server" Mode="ReadOnly" /> </td> </tr> <tr> <td colspan="2" style="padding: 0px;"> <asp:Label runat="server"> </asp:Label> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label42" runat="server" Font-Bold="true">Manufacturer: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl3" DataField="AM_MANUFACTURER1" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label43" runat="server" Font-Bold="true">Product Family: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl32" DataField="AM_PRODUCT_FAMILY1" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label44" runat="server" Font-Bold="true">Product Subfamily: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl33" DataField="AM_PRODUCT_SUBFAMILY1" runat="server" Mode="ReadOnly" /> </td> </tr> <tr> <td colspan="2" style="padding: 0px;"> <asp:Label runat="server"> </asp:Label> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label26" runat="server" Font-Bold="true">Price VP Addon: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl1" DataField="Price_VP_Addon" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label27" runat="server" Font-Bold="true">Price VP Sales: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl2" DataField="Price_VP_Sale" runat="server" Mode="ReadOnly" /> </td> </tr> <tr> <td colspan="2" style="padding: 0px;"> <asp:Label runat="server"> </asp:Label> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label30" runat="server" Font-Bold="true">Min Stock: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl4" DataField="MinStock" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label ID="Label32" runat="server" Font-Bold="true">Max Stock: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl6" DataField="MaxStock" runat="server" Mode="ReadOnly" /> </td> </tr> <tr> <td colspan="2" style="padding: 0px;"> <asp:Label runat="server"> </asp:Label> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Date Created: </asp:Label> </td> <td> <asp:DynamicControl DataField="Date_Creation_AM" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Date Last Modified: </asp:Label> </td> <td> <asp:DynamicControl DataField="Date_Modified_AM" runat="server" Mode="ReadOnly" /> </td> </tr> <%--<tr class="td"> <td> <asp:Label ID="Label71" runat="server" Font-Bold="true">Navigation: </asp:Label> </td> <td> <asp:DynamicControl ID="DynamicControl21" DataField="AM_ARTICLE_RELATION1" runat="server" Mode="ReadOnly" /> | <asp:DynamicControl ID="DynamicControl11" DataField="AM_ARTICLE_RELATION" runat="server" Mode="ReadOnly" /> | <asp:DynamicControl ID="DynamicControl12" DataField="AM_ARTICLE_CONTRACT" runat="server" Mode="ReadOnly" /> </td> </tr>--%> </table> </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel5" HeaderText="..." runat="server"> <ContentTemplate> <table class="DDDetailsTable" cellpadding="6" width="100%"> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description EN: </asp:Label> </td> <td> <asp:DynamicControl DataField="ArticleDescription_EN" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description FR: </asp:Label> </td> <td> <asp:DynamicControl DataField="ArticleDescription_FR" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description NL: </asp:Label> </td> <td> <asp:DynamicControl DataField="ArticleDescription_NL" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Picture: </asp:Label> </td> <td> <asp:DynamicControl DataField="Picture1" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description Quote NL: </asp:Label> </td> <td> <asp:DynamicControl DataField="Description_Quote_NL" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description Quote FR: </asp:Label> </td> <td> <asp:DynamicControl DataField="Description_Quote_FR" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td valign="top"> <asp:Label runat="server" Font-Bold="true">Description Quote EN: </asp:Label> </td> <td> <asp:DynamicControl DataField="Description_Quote_EN" runat="server" Mode="ReadOnly" /> </td> </tr> </table> </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel2" HeaderText="Contract Info" runat="server"> <ContentTemplate> <table class="DDDetailsTable" cellpadding="6" width="100%"> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Service Hours: </asp:Label> </td> <td> <asp:DynamicControl DataField="ServiceHours" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Service Days: </asp:Label> </td> <td> <asp:DynamicControl DataField="ServiceDays" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Spare stock location: </asp:Label> </td> <td> <asp:DynamicControl DataField="SpareStockLocation" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Response Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="ResponseTime" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Intervention Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="InterventionTime" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Time to Repair: </asp:Label> </td> <td> <asp:DynamicControl DataField="TimeToRepair" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Labour Cost (€): </asp:Label> </td> <td> <asp:DynamicControl DataField="LabourCost" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Article Contracts: </asp:Label> </td> <td> <asp:Label runat="server" Font-Bold="true">Subfamily Contracts: </asp:Label> </td> </tr> <tr class="td"> <td style="padding-left: 20px;" valign="top"> <asp:Repeater ID="ContractHyperlink_ReadOnly_Repeater" runat="server" DataSourceID="Article_Contract_DataSource" OnItemDataBound="ContractHyperlink_ReadOnly_OnBind"> <ItemTemplate> <asp:HyperLink runat="server" ID="Linker" /> <br /> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblEmpty" Text="No contracts found for this article." runat="server" Visible='<%#bool.Parse((ContractHyperlink_ReadOnly_Repeater.Items.Count==0).ToString())%>'> </asp:Label> </FooterTemplate> </asp:Repeater> </td> <td style="padding-left: 20px;" valign="top"> <asp:Repeater ID="SubFamContractHyperlink_ReadOnly_Repeater" runat="server" OnItemDataBound="SubFamContractHyperlink_ReadOnly_OnBind"> <ItemTemplate> <asp:HyperLink runat="server" ID="Linker" /> <br /> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblEmpty" Text="No contracts found for this article its subfamily." runat="server" Visible='<%#bool.Parse((SubFamContractHyperlink_ReadOnly_Repeater.Items.Count==0).ToString())%>'> </asp:Label> </FooterTemplate> </asp:Repeater> </td> </tr> </table> </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel3" HeaderText="Installation Info" runat="server"> <ContentTemplate> <table class="DDDetailsTable" cellpadding="6" width="100%"> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Service Hours: </asp:Label> </td> <td> <asp:DynamicControl DataField="ServiceHours" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Service Days: </asp:Label> </td> <td> <asp:DynamicControl DataField="ServiceDays" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Preparation Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Preparation_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">HW Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_HW_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Configuration Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Configuration_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Integration Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Integration_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Initial Training Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Initial_Training_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Customisation Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Customisation_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Post Installation Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_Post_Installation_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">As Built Time: </asp:Label> </td> <td> <asp:DynamicControl DataField="Install_As_Built_Time" runat="server" Mode="ReadOnly" /> </td> </tr> <tr class="td"> <td> <asp:Label runat="server" Font-Bold="true">Article Installation Types: </asp:Label> </td> <td> <asp:Label runat="server" Font-Bold="true">Subfamily Installation Types: </asp:Label> </td> </tr> <tr class="td"> <td valign="top" style="padding-left: 20px;"> <asp:Repeater ID="InstallationHyperlink_ReadOnly_Repeater" DataSourceID="Article_Installation_DataSource" OnItemDataBound="InstallationHyperlink_ReadOnly_OnBind" runat="server"> <ItemTemplate> <asp:HyperLink runat="server" ID="Linker" /> <br /> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblEmpty" Text="No installation types found for this article." runat="server" Visible='<%#bool.Parse((InstallationHyperlink_ReadOnly_Repeater.Items.Count==0).ToString())%>'> </asp:Label> </FooterTemplate> </asp:Repeater> </td> <td valign="top" style="padding-left: 20px;"> <asp:Repeater ID="SubFamInstallationHyperlink_ReadOnly_Repeater" OnItemDataBound="SubFamInstallationHyperlink_ReadOnly_OnBind" runat="server"> <ItemTemplate> <asp:HyperLink runat="server" ID="Linker" /> <br /> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblEmpty" Text="No installation types found for this article its subfamily." runat="server" Visible='<%#bool.Parse((SubFamInstallationHyperlink_ReadOnly_Repeater.Items.Count==0).ToString())%>'> </asp:Label> </FooterTemplate> </asp:Repeater> </td> </tr> </table> </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel4" HeaderText="Suppliers" runat="server"> <ContentTemplate> <asp:GridView runat="server" ID="Article_Supplier_Gridview" AutoGenerateColumns="false" AllowPaging="true" DataSourceID="Article_Supplier_DataSource" CssClass="DDGridView" PageSize="10" RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6" DataKeyNames="ID"> <PagerStyle CssClass="DDFooter" /> <SelectedRowStyle CssClass="DDSelected" /> <EmptyDataTemplate> <asp:Table ID="Table6" runat="server" Width="100%"> <asp:TableRow> <asp:TableCell> <asp:Label ID="Label49" runat="server" Text="There are no suppliers related to this article." /> </asp:TableCell> <asp:TableCell HorizontalAlign="Right"> <asp:ImageButton ID="Btn_Add_Article_Supplier_Relation" runat="server" ImageUrl="../../Content/Images/Create.png" ToolTip="New Supplier Relation" OnClick="Btn_Add_Article_Supplier_Relation_Click" /> </asp:TableCell> </asp:TableRow> </asp:Table> </EmptyDataTemplate> <Columns> <asp:TemplateField ShowHeader="false"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="TDtesterSubs" /> <HeaderTemplate> <asp:ImageButton ID="Btn_Add_Article_Supplier_Relation" runat="server" ImageUrl="../../Content/Images/Create.png" ToolTip="New Supplier Relation" OnClick="Btn_Add_Article_Supplier_Relation_Click" /> </HeaderTemplate> <ItemTemplate> <table> <tr> <td> <asp:ImageButton ID="Article_Supplier_Edit" runat="server" CausesValidation="false" CommandName="Edit" ImageUrl="../../Content/Images/Edit.png" ToolTip="Edit" /> </td> <td> <asp:ImageButton ID="Article_Supplier_Delete" runat="server" CausesValidation="false" CommandName="Delete" ImageUrl="../../Content/Images/Trash.png" ToolTip="Delete" OnClientClick='return confirm("Are you sure you want to delete this item?");' /> </td> </tr> </table> </ItemTemplate> <EditItemTemplate> <table> <tr> <td> <asp:ImageButton ID="Article_Supplier_Update" runat="server" CommandName="Update" ImageUrl="../../Content/Images/Accept.png" ToolTip="Update" /> </td> <td> <asp:ImageButton ID="Article_Supplier_Cancel" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="../../Content/Images/No.png" ToolTip="Cancel" /> </td> </tr> </table> </EditItemTemplate> </asp:TemplateField> <asp:DynamicField DataField="AM_SUPPLIER" HeaderText="Supplier" UIHint="ForeignKey" /> <asp:DynamicField DataField="SupplierArticle" HeaderText="N°" /> <asp:DynamicField DataField="IsPreferred" HeaderText="Preferred" /> <asp:DynamicField DataField="PricePurchased_Bruto" HeaderText="PP Bruto" /> <asp:DynamicField DataField="Korting1" HeaderText="Discount" /> <asp:DynamicField DataField="Price_Cost" HeaderText="Price Cost" /> </Columns> </asp:GridView> </ContentTemplate> </ajaxToolkit:TabPanel>Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 24, 2011 07:12 AM|LINK
I've used your recursive example, but it results in eactly the same thing.
I've debugged and it finds the same grid successfully, however when adding the validator to the UpdatePanel its controls it gives the same error.
Thanks for it though, it'll be nice to use elsewhere for sure as I've been doing quite a lot of FindControl nestings elsewhere :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Childgrid custom validation
Nov 24, 2011 07:19 AM|LINK
What about trying to add a RequiredValidator control directly by dragging and dropping into the page instead of dynamically creating at code-behind?
Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 24, 2011 07:36 AM|LINK
Everytime the exact same story. This is driving me mad :s
Yannick86
Member
565 Points
366 Posts
Re: Childgrid custom validation
Nov 24, 2011 07:55 AM|LINK
Now I was trying something else:
I added a second validationsummary at the top of my page and gave it the same validationgroup as the button which saves the changed child record.
But again, it results in a web page error in IE instead of nicely showing the validation message in the summary ...
The same code as before in my entities partial class:
public partial class AM_Entities { partial void OnContextCreated() { this.SavingChanges += new EventHandler(context_SavingChanges); } private static void context_SavingChanges(object sender, EventArgs e) { foreach (ObjectStateEntry entry in ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)) { if ((entry.Entity.GetType() == typeof(AM_ARTICLE))) { AM_ARTICLE CurrentEntity = (AM_ARTICLE)entry.Entity; if (entry.State == EntityState.Added) { CurrentEntity.Date_Creation_AM = DateTime.Now; } else if (entry.State == EntityState.Modified) { CurrentEntity.Date_Modified_AM = DateTime.Now; } } if ((entry.Entity.GetType() == typeof(AM_ARTICLE_SUPPLIER))) { AM_ARTICLE_SUPPLIER CurrentEntity = (AM_ARTICLE_SUPPLIER)entry.Entity; if (entry.State == EntityState.Modified) { if (CurrentEntity.IsPreferred) { using (AM_Entities entities = new AM_Entities()) { AM_ARTICLE_SUPPLIER ExistingIsPreferredRecord = (from rec in entities.AM_ARTICLE_SUPPLIER where rec.IsPreferred select rec).FirstOrDefault(); if (ExistingIsPreferredRecord != null) { throw new ValidationException("There already is a preferred supplier for this article."); } } } } } } } }This is realllllly pissing me off now ><