Lookup edited value of a field

Hi,

I'm writing a simple business rule that checks if ClosedDt is priror to OpenDt like in the following code.

partial void OnCLOSEDTChanging(DateTime? value)

{

if (value < this._OPENDT

)

throw new ValidationException("Closed Date cannot be prior to the Open Date");

}

I want to reference the new changed value of the OpenDt field and not the value that it has prior to the edit. I have tried both this._OPENDT and this.OPENDT but they both reference the value prior to the edit.

 Any ideas?

0
msingareddy
3/27/2009 3:20:43 PM
asp.net.dynamic-data 1365 articles. 0 followers. Follow

9 Replies
441 Views

Similar Articles

[PageSpeed] 54

If you want to check several value (new values) you will need to do this in either the OnValidate for the entity or in Update i.e.

 

public partial class NWDataContext
{
    partial void UpdateCustomer(Customer instance)
    {
        // your business login for update here
        ExecuteDynamicUpdate(instance);
    }

}

OR 

[MetadataType(typeof(CustomerMD))]
public partial class Customer
{
    partial void OnValidate(ChangeAction action)
    {
        throw new NotImplementedException();
    }
}
 
Steve Big Smile

Seeking the elegant solution.
[Oh! If olny I colud tpye!]
c# Bits blog
Oh, and don't forget to mark as answer any posts that help you Big Smile
0
sjnaughton
3/27/2009 3:44:00 PM

I'm using EF and I don't see either the onValidate or Update methods defined for my entities. Are these only available to Linq to SQL?

0
msingareddy
3/27/2009 4:04:37 PM

It's a bit more involved in EF see this link: How to: Execute Business Logic When Saving Changes (Entity Framework). Also have a look at David Ebbo's session at MIX09: Microsoft ASP.NET 4.0 Data Access: Patterns for Success with Web Forms in particular the validation in the DomainService


Steve Big Smile

Seeking the elegant solution.
[Oh! If olny I colud tpye!]
c# Bits blog
Oh, and don't forget to mark as answer any posts that help you Big Smile
0
sjnaughton
3/27/2009 4:17:16 PM

See Customizing Validation for All Data Fields by Using a Partial-Class Method in the ADO.NET Entity Framework  in the MSDN article How to: Customize Data Field Validation in the Data Model

It demonstrates the EF approach to validate several fields for consistency - exactly what you want to do.


Rick -ASP.Net UE  My DD Blog  DD FAQ
0
ricka6
3/27/2009 6:24:31 PM

I have integrated the validation logic by registering the onSavingChanges event handler for the EF website. When I throw the ValidationException, it doesn't quite get displayed correctly on the UI. It shows the error message twice and also picks the wrong control to show the error message. How can I correct this?

Here is the sample code.

private static void context_SavingChanges(object sender, EventArgs e)
        {
            // Validate the state of each entity in the context
            // before SaveChanges can succeed.
            foreach (ObjectStateEntry entry in
                ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(
                EntityState.Added | EntityState.Modified))
            {
                // Find an object state entry for a SalesOrderHeader object. 
                if (!entry.IsRelationship && (entry.Entity.GetType() == typeof(Sale)))
                {
                    Sale saleToCheck = entry.Entity as Sale;

                    if (saleToCheck.CLOSEDT < saleToCheck.OPENDT)
                        throw new ValidationException("Closed Date cannot be prior to the Open Date",);
                }
            }
        }

  

0
msingareddy
3/29/2009 8:26:48 PM

Take a look at  Handling database exceptions in Dynamic Data
and let me know if that solves your problem.


Rick -ASP.Net UE  My DD Blog  DD FAQ
0
ricka6
3/30/2009 7:05:27 PM

I looked at that article on David's blog and it really doesn't help. Let me explain my issue a bit more clearly.

I'm using DDE website (3.5 SP1, VS 2008 SP1). I need to compare the values of 2 date fields in the UI and display an error message to the user if the Close Date is prior than the Open Date. Now for EF, there is no OnValidate method for me to compare the new values for the 2 fields. So I have registered an event hander for SavingChanges event and use the event handler to perform my data validations, specifically with the above date fields as an example. Although I'm able to view the changed values for these fields in the SavingChanges event handler, I cant get it to display the validation error message for the correct control. Also the error message gets displayed twice. Please see below.

1. When I throw a validationException, how does it know which control to associate the error message with? When I throw the validationException from an OnCloseDateChanging event handler, it attaches the error correctly to the control in the UI but not when the exception is thrown from the SavingChanges event handler. I'm using examples from the following link to do this.

http://msdn.microsoft.com/en-us/library/cc716714.aspx

2. Why is showing the error twice in the UI? There isn't really much that I'm doing differently here other than what I explained above.

List of validation errors
  • Closed Date cannot be prior to the Open Date
  • Closed Date cannot be prior to the Open Date

This has been a very helpful forum for issues that I stumbled upon and I'm hoping I can get past this one too. Thanks

0
msingareddy
3/30/2009 7:16:26 PM

Have you debugged your event handler to see if it is called twice?


Steve Big Smile

Seeking the elegant solution.
[Oh! If olny I colud tpye!]
c# Bits blog
Oh, and don't forget to mark as answer any posts that help you Big Smile
0
sjnaughton
3/30/2009 11:03:45 PM

Hey Steve,

He copy/pasted the exact same problem in this post - which he solved. I asked him to create another thread (one hopefully) with his next problem.


Rick -ASP.Net UE  My DD Blog  DD FAQ
0
ricka6
3/30/2009 11:21:04 PM
Reply:

Similar Artilces:

dynamic data: how to change default field value on edit/insert
Hi, how can i change the value when in edit/insert item mode. for example, i have a list (name, updatedby), when i click on edit or insert, i want to change the updatedby value to who edited/inserted the record. Hi Ferds, have a look at these: On Marcin's blog Dynamic Data Futures 6/25 update posted and on my blog DynamicData Default Values in ForegnKey_Edit & other FieldTemplates Hope this helps Steve Seeking the elegant solution.[Oh! If olny I colud tpye!]c# Bits blogOh, and don't forget to mark as answer any posts that help you Thanks, i was able to do it by creating a...

Set service field value in Dynamic Data
In my project many tables are linked to aspnet_Application table by ApplicationId foreign key. I don't want the users to view or edit it, so how can I preset this value programmatically before the insert query is executed? I still have scaffolding enabled for this column (in order for DD to generate the right sql script) but I'm hiding this column/field in all my edit/list/insert pages. So ideally I'm looking for a place to inject my code right before DynamicInsert is executed for any table in my LinqToSql class. Thanks You can hide the column with [Scaffold(false)] and then...

Ref:How to edit when I have a lookup field in Data Grid
http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=dgEdit hi the above link will show how to make edit when all columns in the DG are text. What about when I have a column that is a lookup like , state_id . If someone has a complete demo to show how to do the edit, I really thanks him/her AlNew to Asp.net Hi Al This one has worked very well for me: Article Hopefully it'll work for you just as well. Jeff ...

is it possible to make tabs with a repeater that shows a data field to display and has a selected data field for the value?
I am trying to make a database drive menu that when a user clicks a tab it populates a checkbox list on the web page based on that tab selected.  I know I can do this with a bullet list but I am trying to create a nice horizontal color tabbed menu.  Can this be done using a repeater control or is there another way that may or may not be easier? my repeater code: <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSourceTypeList"><HeaderTemplate><table border="1" class="repeater"><tr>&...

Passing a data field value to a variable using ADO.NET
Hi, I’m already able to connect to a data base and to show a table content using a GridView, but I would like to test a manual way, like we just did it using the past ADO, giving a field value to a variable. In ADO we just did it:   strVariable = TABLE(“FIELD”),   But I have been trying to find something similar with ADO.NET, but every example I found show the data table using ASP Controls or instructions to display the information:   Any Help, Please?   Thanks. You can dig in to the data like this (gets 3rd row, 4th column): strVariable = MyTable.Rows[2].Item...

Issue using computed field with Mid function as the data value for dddw edit style
Converting from PB 9 to PB 11.1. Found an issue (am in the process of raising a case) that I simplified below. Quite odd cosidering that Mid(colA, 1, 3) and Left(colA, 3) should be identical. We have a dropdowndatawindow that has a code value (s_code - len 8) and a description. We create a computed column on the code value as Mid(s_code, 1, 3). We then have another datawindow that has a code column (s_code3 - len 3). We place a dropdowndatawindow edit style on the column and point it to the dropdowndatawindow above. We indicate the display column should be the description a...

Dynamic Data Field Order and Visibility of Fields
This is my first post to this forum. I have been experimenting with a slightly tweaked version of the Northwind database, upsized to SQL Server 2008. I created a new Dynamic Data project in Visual Web Developer 2008 Express Edition, added a "LINQ to SQL" data class, and added the following tables: Category Customer SalesOrder Product OrderDetail The build works fine, and I get all the expected (VB) code and pages, and by default I have used DynamicDataRoute("{table}/{action}.aspx") Unlike David Ebbo's MIX08 presentation, the, Product...

Dynamic Data And Ado.Net Data Service
Hi,I'm wondering if it is possible to mix up Dynamic Data and Ado.Net Data Service.I have found no information on google yet.Thanks for your replies, Hasan Yes you will be able to have a look at the Preview on Codeplext here the new Domain Service will allow this sort of thing see David Ebbo's and Nukhil Kothari's sessions at mix09 Microsoft ASP.NET 4.0 Data Access: Patterns for Success with Web Forms .NET RIA Services - Building Data-Driven Applications with Microsoft Silverlight and Microsoft ASP.NETSteve Seeking the elegant solution.[Oh! If olny I colud tpye!]c# Bits...

Dynamic Data over ADO.NET Data Service
I would like to create a dynamic data web site that does not have a database connection to the underlying database, but instead accesses the data through an ADO.NET data service.  Is this possible?  Thanks,Dennis If you look at the Dynamic Data Futures solution on CodePlex, it has an early version of something that does that.  Also, see this thread. thanks,David David,  That's exactly what I was looking for.  However, I am running into a problem when I try to develop my own dynamic data client site.  I created a dynamic data web site, added a referenc...

Dynamic Data with ADO.NET Data Services
Is it currently possible to use Dynamic Data with ADO.NET Data Services? I've had a play with this to see if this would work but I didnt have much luck. I ran the datasvcutil.exe against my service (which is a  ADO.NET Data Services on a LINQ to SQL model) but I ended up with a "The context type 'Entities.NorthwindDataContext' is not supported" message.  It seems to make sense that these technologies would work together...is there something else I am missing? Perhaps this functionality isn't supported yet? Thanks, Craig Hi Cr...

Dynamically Creating GridView Columns + Enabling Insert, Edit, Delete + DropDownLists, DatePickers for Data bound fields.
Hello all,I have read through several articles in the Web and found the help I needed to understand how to ask my question here. I am building a simple a Web User Control (planning to make it a real control in the future)  that will support all the features I mentioned in this post's title. So let's me explain the problem. Originally I just wanted to insert a DropDownList inside the current editing cell of a GridView. The idea is to populate the DropDownList with the only data that is meaningful for that field so I can provide a better experience for the users. Fine, many examples show ...

Modify default (1 database field per row) rendering for DetailsView Control in Details, Edit, Insert Pages in a Dynamic Data WebSite
Hi, DetailsView control on Edit, Insert, Details pages render the data as a HTML table with only 2 columns (1 column for the column name and the other for its database value). I would like to modify this default behaviour of the DetailsView control to render atleast 2 database fields per row to capture some of the real estate on the right side of the page. Any suggestions are higly appreciated.  -Mahipal     You could use custome pages or have a look at this articles of mine here: Custom PageTemplates Part 1 - Custom PageTemplates with Ajax Control Toolkit Tabs ...

Dynamic Data with ADO.NET Data Services #2
I'm using the DynamicData Futures Preview 2 DLL's to create an n-tier Dynamic Data website using ADO.Net Data Services.I'm trying to add Many-to-Many relationship support using David Ebbo's article as a basis, but it would appear that the client-side model generated by DataSvcUtil.exe (Add Service Reference....) doesn't contain enough information to identify Many-to-Many relationships?For example, I have Contacts and Regions joined through a ContactRegion table.  EF models this correctly on the server and DataServices exposes it correctly - With a Contact having a Re...

Dynamic Data with ASPNET Data Service-Nullable Fields
 Hi,Firstly if this has been asked before, my apologies, but the forum search feature seems to be on holiday or strike today I have downloaded the  Dynamic Data Futures samples and am looking at the Dynamic Data site using the ASPNET Data Services provider and I have a stupid question/problem:Problem: All fields seem to be being treated as required, even if they are nullable??Example:Open the DD site, navigate to the Suppliers Table, click edit, make no changes, then click update. You get a validation message for each blank field saying that it is required.Checking the schema (edm...

Web resources about - Lookup edited value of a field - asp.net.dynamic-data

Lookup A Cell Phone Number Dot Com
Lookup cell phone numbers by name or reverse lookup cell phone number to find name and address.

DNS Lookup - Everything to do with DNS, DDNS, and Free Services
December 23, 2011 admin DDNS , Dynamic Dns , 0 There are about a billion dynamic dns vanity hostnames available, so it is a very difficult exercise ...

Pet Microchip Lookup - Powered by AAHA
Instructions: Enter the microchip ID above and click "Submit". Enter only the 9, 10 or 15 character microchip number, with no punctuation or ...

Publishers List - Welcome to Publisher Lookup UK.
Many people find it difficult to access the world of books. Whether through dyslexia, visual impairment or motor difficulties, thousands of ‘would ...

Lookup table - Wikipedia, the free encyclopedia
In computer science , a lookup table is an array that replaces runtime computation with a simpler array indexing operation. The savings in terms ...

Voter Lookup
Mail to: Tarrant County Elections office, 2700 Premier St., Ft. Worth, Tx 76111 or fax to 817-831-6475, Attn: Web Opt-out.

Cell Phone Lookup Emporium - Home
Cell Phone Lookup Emporium Home Free Cell Phone Lookup Resource Connections We have spent some considerable time identifying websites with valuable ...

DNS Lookup
Without DNS (domain name system) we would not be able to use our favourite websites such as Facebook and Twitter, nor would we be able to check ...

Facebook Adds 25 New Preferred Developer Consultants, Improves PDC Lookup Tool
... number of developers in the PDC Directory to 90. It also added expertise filters to a newly launched version of the Preferred Developer Lookup ...

Search Twitter - LOOKUP
Sign in Sign up Search Refresh emyri d. @ LookUP_itsMoine 24m love and hip hop tonight 😁 View details · Martin Miles @ martincmiles 34m This ...

Resources last updated: 1/10/2016 9:55:37 PM