Google+ Peter Bromberg's .NET Blog | All Things Programming

Peter Bromberg's .NET Blog All Things Programming

How to Ensure that jQuery is only loaded once

26. July 2016 13:50 by admin in ASP.NET, C#, Jquery

Often we have pages and master pages and "bundles" that load scripts like jQuery and we can't always be sure that a particular page already has it loaded. Here is a script that will only inject jQuery into a page if it has not already been loaded:

<HTML>
<HEAD>

<!-- comment or uncomment next line to test it out --->
<script src='https://code.jquery.com/jquery-3.1.0.min.js'></script>

<script>

// Only do anything if jQuery isn't defined

if (typeof jQuery == 'undefined') {

function getScript(url, success) {

var script = document.createElement('script');

    script.src = url;

var head = document.getElementsByTagName('head')[0],done = false;

// Attach handlers for all browsers

script.onload = script.onreadystatechange = function() {

if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {

done = true;

// callback function provided as param

success();

script.onload = script.onreadystatechange = null;

head.removeChild(script);

};

};

head.appendChild(script);

};

 

getScript('https://code.jquery.com/jquery-3.1.0.min.js', function() {

if (typeof jQuery=='undefined') {

// Super failsafe

} else {

alert("We Loaded it!");

// jQuery loaded 

}

});

 

} else { 

// jQuery was already loaded

alert("jQuery is Already Loaded!");

// Run your jQuery Code

};

</script>

</HEAD>

<BODY>

</BODY>

 

</HTML>

 

How to Use OrmLite's SelectMulti Feature

10. July 2016 15:07 by admin in

 using (var db = new SqlConnection(ConfigurationManager.ConnectionStrings["TEST"].ConnectionString))

            {

                db.Open();

                OrmLiteConfig.DialectProvider = SqlServer2012OrmLiteDialectProvider.Instance;

                OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase();

 

                var q = db.From<Customer>()

                       .Join<Customer, Order>((cust,ord)=>cust.CustomerID==ord.CustomerID)

                       .Join<Order,Order_Detail >((ord,orddet)=>ord.OrderID==orddet.OrderID);

                var results = db.SelectMulti<Customer, Order_Detail, Order>(q);

   }

How To Fix "Unable to access the IIS Metabase" error when loading Web Application in Visual Studio

23. May 2016 06:58 by admin in

When you see:

<Path to Project> : error  : The Web Application <Project Name> is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.

There is an easy fix:

Browse to C:\Windows\System32\inetsrv and then double-click the “config” directory. You should get this warning dialog:

 

Click Continue, then do the same for the C:\Windows\System32\inetsrv\config\export directory and the other directories in C:\Windows\System32\inetsrv

This should fix the issue and you will be able to load the project.

 

 

Convert DataTable to List<T>

15. March 2016 13:39 by admin in

 DataTable dt = ds.Tables[0];

             var   sponsorids  = dt.Rows.OfType<DataRow>().Select(dr => (int) dr["AccountID"]).ToList();

                return sponsorids;