adsense

Thursday, January 22, 2015

Asp.net Closing child windows from JavaScript

These maybe situations where we use some of the additional information displayed  using window.open() method. It can cause issue if we keep these open widows when dealing with different user logins within the system.

The solution is to store all opened windows in an Javascript array and close them on logout or navigation to other links or menu options.

 var openWindows = new Array();

function OpenWindow(url){
          
            openWindows.push(window.open(url));
        }


We can use the window.onbeforeunload event to close the opened windows as shown below.

   window.onbeforeunload = function () {
            closeWindows();
        };


 function closeWindows() {
            for (i = 0; i < openWindows .length; i++) if (openWindows [i] && !openWindows[i].closed)
                openWindows[i].close();
        }

Cheers
Samitha

Friday, January 16, 2015

SQL Server check nemeric

There can be situations where you want to check whether a field is a numeric or not. SQL Server provides ISNUMERIC() function to achieve that purpose as shown below.


SELECT case when IsNumeric(cmp) = 1
       then cast(cmp as int)
       else 0 end   FROM Transactions)

This can be easily included in a where clause as follows

select * from Transactions 
where (case when IsNumeric(cmp) = 1
       then cast(
cmp as int)
       else 0 end) >= 7

 
Cheers
Samitha