Answered by:
Problem using onchanging with foreign key field

Question
-
User-701335235 posted
Hi All
Hope you can help. I'm trying to setup validation using the onchanging field event. The field I'm trying to validate is a foreign key field and thus a drop down menu. I tried various variation of IF statements with no joy so I removed them in order to simulate an error. My test event code is:
partial void On<fieldname>StaffOutChanging(int? value)
{
throw new ValidationException("Please select from the menu");
}</fieldname>On clicking Update rather than getting a message near the field saying "Please select from the menu" I get the following error:
Failed to set one or more properties on type StockItem. Please select from the menu
What am I doing wrong? I use onchanging with a non foriegn key text field and that works fine.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.UI.WebControls.LinqDataSourceValidationException: Failed to set one or more properties on type StockItem. Please select from the menu
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[LinqDataSourceValidationException: Failed to set one or more properties on type StockItem. Please select from the menu]
System.Web.UI.WebControls.LinqDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) +465701
System.Web.UI.WebControls.LinqDataSourceView.BuildUpdateDataObjects(Object table, IDictionary keys, IDictionary values, IDictionary oldValues) +212
System.Web.UI.WebControls.LinqDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +231
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +907
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +704
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Thanks in advance.
mrveryboring
Tuesday, December 2, 2008 11:17 AM
Answers
-
User-797310475 posted
Hi, this is a known issue with DynamicValidator and the ForeignKey_Edit template. Please see this thread from more details and a workaround: http://forums.asp.net/p/1287649/2488951.aspx#2488951.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2008 3:06 PM
All replies
-
User645151313 posted
I think the problem is that v1 of Dynamic Data didn't include a DynamicValidator control in the ForeignKey_Edit.ascx field template. Try adding the markup below to the bottom of the ASCX file.
<asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="droplist" ControlToValidate="DropDownList1" Display="Dynamic" />
Tuesday, December 2, 2008 12:23 PM -
User-1005219520 posted
Try throwing from the OnXXChanged event (in stead of the OfXXChanging). I'll try to repro. Updates don't have the problem delete's have with the markup incorrectly containing "causesValidation=false".
Tuesday, December 2, 2008 12:24 PM -
User-797310475 posted
Hi, this is a known issue with DynamicValidator and the ForeignKey_Edit template. Please see this thread from more details and a workaround: http://forums.asp.net/p/1287649/2488951.aspx#2488951.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2008 3:06 PM -
User-701335235 posted
Thanks for the suggestions I'll give them a whirl.
Wednesday, December 3, 2008 4:27 AM