Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Wednesday, 26 June 2013

Knockout (or any javascript) Intellisense not working if move script file locations

I found while playing around with Knockout.js, that my Visual Studio Intellisense wasn’t working. This turned out to be because I had formatted my Scripts folder, and moved standard Javascript libraries into another folder.

This meant that Visual Studio couldn’t find my _references.js file.

At first I added the following to the @Scripts Section in my .vbhtml file;

   1: @Code 
   2:  
   3:        If (False) Then
   4:  
   5:            @<script src="/Scripts/lib/knockout-2.2.1.debug.js" type="text/javascript"></script>
   6:                
   7:        End If
   8:              
   9: End Code
Where the If (False) code forces the compiler to ignore the file when publishing.


But this would end up being silly if I had lots of files. So, I had a quick look around and found a couple of useful answers on Stack Overflow;


http://stackoverflow.com/a/12016530/1305169 and
http://stackoverflow.com/a/12628049/1305169


Where, basically, you need to add a reference to your new _references.js file to the Intellisense list options in Visual Studio;



  • In Visual Studio, go to Tools > Options > Text Editor > Javascript > Intellisense > References
  • In the “Add a reference to current group”, type in the relative path to your _references.js file (for me this was “~/Scripts/lib/_references.js”

Hey presto, you should now have working intellisense!

Wednesday, 1 May 2013

SSRS 2008 R2 Reports are blank in Chrome

I stumbled across this apparently well documented problem today, where my SSRS 2008R2 Report was showing up fine in IE, but blank in Chrome;

http://stackoverflow.com/questions/5968082/ssrs-2008-r2-reports-are-blank-in-safari-and-chrome

It seems as though the main Div Tag uses IE compatible only Overflow styles, which Chrome doesn’t interpret well.

I found a nice blog post here which explained how to work around this issue;

http://grumpydba.blogspot.co.uk/2012/02/sql-2008-r2-report-doesnt-show-on.html

The Short and curlies of it are;

Connect to your Reporting Services server, and find the relevant ReportingServices.js file - this will probably be somewhere like "C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager\js\ReportingServices.js", or on a 64 bit machine, "C:\Program Files (x86)\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager\js\ReportingServices.js"


First up, take a copy of this file - let's not be silly here and assume this is a 100% foolproof solution!
Next, edit this file in notepad. Do a quick search for PageLoad, to ensure no-one else has already hacked applied this fix, then jump to the bottom of the existing text.
Simply append the following code:

function pageLoad() 
{
    var element = document.getElementById("ctl31_ctl10");
    if (element)
    {
        element.style.overflow = "visible";
    } 
}


Save the file, and restart Reporting Services - you should now find that Chrome displays your reports again.


You’ll need to find the correct ElementId, by viewing the Source of the report in Chrome. If you search for “VisibleReportContent”, you should find something like “VisibleReportContentctl31_ctl09”. Where the “ctl31_ctl09” is the ElementID you’re looking for!

Monday, 21 January 2013

Forcing html Input element to Numeric Only Input

While developing a shopping cart function for a client, I needed to restrict the user to entering numbers only in an Input field

I came across this handy post;

http://www.itjungles.com/javascript/how-to-use-javascript-to-force-numeric-value-in-textbox

Basically, we need to add the following function to the JavaScript section;

function isNumericKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) 
    {
        return false;
    }
    else
    {
        return true;
    }
}    


We then add the the following to your input element;


onkeypress="return isNumericKey(event)"


Hey Presto! You have a numeric only Input Element!