Skip to main content

Posts

Showing posts from 2014

How to find index of an item in JavaScript Object Array?

Recently while working I came across a scenario. I had to find index of a particular item on given condition from a JavaScript object array. In this post we will see how to find index of object from JavaScript array of object. Let us assume we have a JavaScript array as following, Related :   Allow only characters in textbox using javascript in asp.net var studentsArray =[ {  "rollnumber": 1, "name": "dj", "subject": "physics" }, { "rollnumber": 2, "name": "krishna", "subject": "biology" }, { "rollnumber": 3, "name": "amit", "subject": "chemistry" },  ]; Now if we have a requirement to select a particular object in the array.  Let us assume that we want to find index of student with name Tanmay. We can do that by iterating through the array and comparing value at the given key. function functiontofindIndexByKeyValu

EF error: OriginalValues cannot be used for entities in the Added state

Problem : OriginalValues cannot be used for entities in the Added state I was working on a repository and came across an interesting, cryptic error that resulted from a fairly simple operation: Saving the changes. Without getting into code details (which are  irrelevant to the point), the call to the following statement failed: Context.SaveChanges(); The error message read: OriginalValues cannot be used for entities in the Added state When saving new entries to a SQL Server database using the Entity Framework, I came across the following exception error: OriginalValues cannot be used for entities in the Added state There may be a number of reasons why the exception was raised but I found that in my case I had to check the data I was trying to save to make sure that values were specified for all the fields and that the fields were in the ranges required by the SQL Server database. Here is a list of the checks I had to implement before writing the data to the database us

jNotify Example for Disply animated boxes (information, errors, success) in asp.net

jNotify : Disply animated boxes (informations, errors, success) in just one line of code jNotify  can display information boxes in just one line of code in asp.net . Three kind of boxes are allowed :  information, success and failure. The whole box is entirely skinnable with css. For example, you could use it for a mail being successfully sent or a validation error of a form , or alert message . Previous post  Show jQuery UI Dialog Popup Window from Server Side ( Code Behind ) in ASP.Net First download  JNotify from GitHub   Implementations   Add links to master page , copy images into your folder  <link href="Styles/jNotify.jquery.css" rel="stylesheet" type="text/css" />   <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>   <script src="Scripts/jNotify.jquery.min.js" type="text/javascript"></script> Master page look like