Archive for the ‘ASP.NET’ Category

Call Repeater ItemCommand event manually from outside the repeater

February 6, 2018 Leave a comment

Following is the code to call repeater item command event manually

Private Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click

For i = 0 To rptPlayers.Items.Count – 1

Dim tItem As RepeaterItem = rptPlayers.Items(i)

Dim tButton As ImageButton = ptPlayers.Items(i).FindControl(“imgAdd”)

Dim tEvents As New System.Web.UI.WebControls.CommandEventArgs(tButton.CommandName, tButton.CommandArgument)

Dim rpt As New RepeaterCommandEventArgs(tItem, tButton, tEvents)

rptPlayers_ItemCommand(tButton, rpt)


End Sub

Categories: ASP.NET

Telerik ORM : Row not found: GenericOID@ OptimisticVerificationException

January 12, 2018 Leave a comment

This kind of error occurred When DataAccess tries to update the row in the database which has the original values for the fields that have changed.

The reason the update fails is that the artificial columns added at runtime are nullable but the CLR property which these columns are mapped to are all non-nullable. Ex – bit column is mapped to Boolean CLR property.

The generated UPDATE statement tries to find a row with the CLR default value i.e 0 but the value in the column is NULL.

I have updated the method that maps the artificial properties as follows –

var propType = Type.GetType(property.PropertyType);
propType = GetNullableType(propType);
var primitivePropertyConfiguration = myConfig.HasArtificialPrimitiveProperty(property.PropertyName,propType).HasFieldName(property.PropertyName);

Here I check if the Type of the field is a value type and if it is, then I create a nullable CLR type instead of the non-nullable type.

The helper method used is as below

public static Type GetNullableType(Type type)
if (type.IsValueType)
Type nullable = typeof(Nullable);
return nullable.MakeGenericType(new[] { type });
return type;

Hope this help !

Categories: ASP.NET

Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping For jQuery in .Net

December 18, 2017 Leave a comment

Getting below error after using RequiredFieldValidator for textbox

Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping For jQuery in .Net

In this post I am trying to explain solution for the above error.

Sample Code :

<asp:TextBox ID=”txtName” runat=”server”></asp:TextBox>
<asp:RequiredFieldValidator ID=”reqName” runat=”server” Display=”Dynamic” ControlToValidate=”txtName”  Text=”*” Style=”color: red”></asp:RequiredFieldValidator>
<asp:Button ID=”btnSubmit” Text=”Submit” runat=”server” OnClick=”btnSubmit_Click” />


Now add key for Unobtrusive under web.config file <appSettings> tag as following code.


<compilation debug=”true” targetFramework=”4.5″ />
<httpRuntime targetFramework=”4.5″ />
    <add key=”ValidationSettings:UnobtrusiveValidationMode” value=”None” />



Microsoft.VisualStudio.Editor.Implementation.EditorPackage’ package did not load correctly: Visual Studio 2012

November 26, 2017 Leave a comment

The Problem

When starting Visual Studio …

  • … by loading a solution file, no windows display and the Solution Explorer remains empty.
  • … you get a bunch of error messages thrown in your face.
  • … you can only add text in the editor, not remove it.
  • … some other strange, unexplainable thing prevents you from using Visual Studio as you normally would.



The Solution

If you are having one of the issues above and neither restarting Visual Studio or rebooting your machine helps, then there is a large change your Component Model Cache is corrupt and you need to delete that folder using following steps

So, here is how you fix it:

  1. Close Visual Studio (if you haven’t done so already out of despair)
  2. Open a file explorer window and navigate to your AppData folder. You can get there by:
    1. In the search bar, type %APPDATA%/.. and press enter
    2. Alternatively, navigate to C:\Users\\AppData
  3. Go into Local\Microsoft\VisualStudio\<version> where <version> is 12.0 for Visual Studio 2013.
  4. Delete the ComponentModelCache folder.

Hope it helps !


Kendo grid error : kendo.all.min.js:12 Uncaught TypeError: e.slice is not a function

November 13, 2017 Leave a comment

Getting Uncaught TypeError: e.slice is not a function error message while binding kendo grid with data using controller action method

Following is the sample code for View and Controller action

View :

$(function () {
height: 400,
dataSource: {
serverPaging: true,
serverFiltering: true,
serverSorting: true,
pageSize: 10,
transport: {
read: “Employee/Read”,
contentType: “application/json”,
type: “POST”
schema: {
data: “Data”,
total: “Total”,

columns: [
{ field: “Salary”, format: “{0:c}”, width: “150px” },
{ field: “EmployeeName”, width: “150px” },
{ field: “SalaryColor”, width: “100px” },
{ command: “destroy”, title: “Delete”, width: “110px” }

editable: true, // enable editing
pageable: true,
sortable: true,
filterable: true,
toolbar: [“create”, “save”, “cancel”], // specify toolbar commands
parameterMap: function (options) {
return kendo.stringify(options);

Controller Read Action :

public ActionResult Read(int take, int skip, IEnumerable<Sort> sort, Kendo.DynamicLinq.Filter filter)
SalesERPDAL salesDal = new SalesERPDAL();

var result = salesDal.Employees.OrderBy(p => p.FirstName)
.Select(p => new EmployeeViewModel
EmployeeName = p.FirstName,
Salary = “5000”,
SalaryColor = “yellow”
}).ToDataSourceResult(take, skip, sort, filter);

return Json(result,JsonRequestBehavior.AllowGet);

Problem is in above code we are passing whole result instead of only Data part of result should be passed.

return Json(result.Data,JsonRequestBehavior.AllowGet);

Hope this help !

Categories: ASP.NET Tags: , , ,

AngularJS With Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

November 7, 2017 1 comment

When trying to POST json to web api server using $http its returning the following error

Response for preflight has invalid HTTP status code 405


MVC web api: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

Following is the solution for above problem


I installed Cors in my project using nu-get command line

Install-Package Microsoft.AspNet.WebApi.Cors

and added the following code in WebApiConfig.cs file from App_Start folder.

var enableCorsAttribute = new EnableCorsAttribute("*",
                          "Origin, Content-Type, Accept",
                          "GET, PUT, POST, DELETE, OPTIONS");

and removed the following from the web config

<remove name="X-Powered-By" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Accept, Content-Type, Origin" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />

EF code first – Model compatibility cannot be checked because the database does not contain model metadata

October 10, 2017 Leave a comment

This suggests that migration table is out of sync (even if your data isn’t), and that’s been part of the db schema now (since 4.3 I think – under system tables).

There could be many reasons and ways to experience that error , but most of the time…

The problematic part is some combination of manually backing/restoring the full database with code changes alongside – I’m not entirely certain as to why always.

In short, even if Db-s are the same migration table data might not be – and hash comparison may fail (still full restore sounds like good enough – but you have ‘two sides’).

What works for me is to use
Update-Database -Script

That creates a script with a ‘migration difference’,
which you can manually apply as an SQL script on the target server database (and you should get the right migration table rows inserted etc.).

If that still doesn’t work – you can still do two things…

a) remove the migration table (target – under system tables) – as per comments in there – that should fail back to previous behavior and if you’re certain that your Db-s are the same – it’s just going to ‘trust you’,

b) as a last resort I used – make a Update-Database -Script of the full schema (e.g. by initializing an empty db which should force a ‘full script’),
find the INSERT INTO [__MigrationHistory] records,
just run those, insert them into the database,
and make sure that your databases – and code match,

that should make things run in sync again.

(disclaimer: this is not a bullet proof to work at all times, you may need to try a few things given your local scenarios – but should get you in sync)

Also this will work

I found the code will work by changing

static LaundryShopContext()
new DropCreateDatabaseIfModelChanges<LaundryShopContext>());

static LaundryShopContext()
new DropCreateDatabaseAlways<LaundryShopContext>());