Thursday, December 14, 2017

How to solve “WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jQuery. Please add a ScriptResourceMapping named jQuery(case-sensitive)”


Error: “WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jQuery. Please add a ScriptResourceMapping named jQuery(case-sensitive)



This error comes when we use RequiredFieldValidator control on any other server control in asp.et web applictaion. We can solve this error by enabling pre 4.5 validation mode by adding an appsetting key in web.config.



 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>



What happened when we add this key?


Adding this key specifies how ASP.NET globally enables the built-in validator controls to use unobtrusive JavaScript for client-side validation logic. As said here

Remarks: If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic. If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.




Tuesday, December 5, 2017

Using PowerShell to list COM+ application and the identity on which they run

Blow PowerShell script will list down the com+ application running on your machine and the identity on which they run

$comAdmin = New-Object -com ("COMAdmin.COMAdminCatalog.1")
$applications = $comAdmin.GetCollection("Applications")
$applications.Populate()
foreach ($application in $applications)
{
    $application.Value("Name") + " " + $application.Value("Identity")
}


How to convert a josn array to object array in JavaScript.


To accomplish the same we could get use of the $.map function



Below code snippet will convert  the json in jsondata variable to JavaScript array



You can see the result in the console screen of browser.

var o = [{"Rating":"Negative","Value":1.0},{"Rating":"Neutral","Value":1.0},{"Rating":"Postive","Value":3.0}];

var arr = $.map(o, function(el) { return [[el.Rating,el.Value]]; })

console.log(arr)

https://jsfiddle.net/92e03nqu/

Asp.net MVC how to populate dropdown list with numbers

Below Razor code will populate a dropdown with  numbers  from 1 to 10


@Html.DropDownListFor(=> m.BookRetensionDays, Enumerable.Range(1, 10).Select(rd => new SelectListItem { Text = rd.ToString(), Value = rd.ToString() }))