Figer's Technology Consulting |

Resolve VS 2010 script debugging and IE 10

If you are getting an error Attached the Script debugger to process failed after installing IE 10  you need to run this script using CMD in administrator mode.


regsvr32.exe "%ProgramFiles(x86)%\Common Files\Microsoft Shared\VS7Debug\msdbg2.dll

.NET - Calling Web API functions directly

To get around the default .NET Web API GET calls (http://localhost:10305/api/ISS/?strUser=myusername&strPass=mypassword) where you only specify parameters and not the function name, add this code snippet to  your Global.asax.vb file: 

Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{action}", defaults:=New With {Key .action = "get"})
routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{action}", defaults:=New With {Key .action = "post"})
End Sub

Then you can make a call that looks like this: http://localhost:10305/api/ISS/LoginFunction?strUser=myusername&strPass=mypassword This is just an example, don't ever send a username and password like this!

Update Wordpress base URLs in MySQL

UPDATE wp_options SET option_value = replace(option_value, 'http://oldurl.com', 'http://newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://oldurl.com','http://newurl.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://oldurl.com', 'http://newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://oldurl.com','http://newurl.com');

Using Google Docs Forms to validate email addreses, capture them and redirect to your site

I wanted to allow the user to hit index.html and if it was the first time visiting the site, they'd have to type in their email address (which I was validating with Javascript), then redirecting to an agreement page, otherwise if they had been there before based on a cookie I had created redirect them immediately to inner_index.html. The Problem: Google Docs don't want you to redirect after the form is submitted, Google docs don't play very nicely with IE when you try to implement work arounds.

The Solution:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png" type="image/x-icon">
<title>Title</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>
<body onload="checkCookie()" dir="ltr" itemscope itemtype="http://schema.org/CreativeWork/FormObject"><meta itemprop="name" content="Email Capture Form">
<meta itemprop="thumbnailUrl" content="https://docs.google.com/spreadsheet/formthumb?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ">
<meta itemprop="embedUrl" content="https://docs.google.com/spreadsheet/embeddedform?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ">
<meta itemprop="faviconUrl" content="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png">
<div>
<div><script type="text/javascript">var submitted_jljnpsrw=false;function
checkRequiredFields_jljnpsrw(requiredFields)
{
var errorMessage='Required field left blank.';
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.getElementById('entry_0').value;
if (reg.test(address) == false)
{
alert("Not a valid e-mail address");
return false;
}
for(var x in requiredFields)
{
var fieldNum=requiredFields[x];
if(document.getElementById('entry_'+fieldNum))
{
if(!document.getElementById('entry_'+fieldNum).value.length)
{
alert(errorMessage);
document.getElementById('entry_'+fieldNum).focus();
return false;
}
}
else if(document.getElementById('group_'+fieldNum+'_1'))
{
var counter=1;
var selected=false;
while(document.getElementById('group_'+fieldNum+'_'+counter))
{
if(document.getElementById('group_'+fieldNum+'_'+counter).checked)
{
selected=true;
}
counter++;
}
if(document.getElementById('other_option:'+fieldNum))
{
if(document.getElementById('other_option:'+fieldNum).checked)
{
selected=true;
if(!document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).value.length)
{
alert(errorMessage);
document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).focus();
return false;
}
}
}
if(!selected)
{
alert(errorMessage);
document.getElementById('group_'+fieldNum+'_1').focus();
return false;
}
}
}
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*365);
document.cookie = "33poemsEmail=BeenHere;expires="+expire.toGMTString();
return true;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function checkCookie()
{
var email=getCookie("33poemsEmail");
if (email!=null && email!="")
{
window.location = "inner_index.html";
}
}
</script>
<p>Title</p>
<p>Sub-Title</p>
<div id="description">
<div>
<p><span>T</span>his is where you put the description</p>
<iframe name="hidden_iframe_jljnpsrw" id="hidden_iframe_jljnpsrw" style="display:none;" onload="if(submitted_jljnpsrw){window.location='foc.html';}"></iframe><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ&amp;ifq" method="post" target="hidden_iframe_jljnpsrw" onsubmit="if(checkRequiredFields_jljnpsrw([0])){submitted_jljnpsrw=true;}else{return false;}" id="ss-form">
<br>
<div>
<div><div>
<label for="entry_0"></label>
<div>Please enter your email address to enter the site<br></div>
<div><input type="text" name="entry.0.single" value="" id="entry_0"><input type="submit" name="submit" value="Submit"></div>
</div></div></div>
<br>
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<div><div>
</div></div></form>
<script type="text/javascript">
(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i = 0; i < numDivs; i++) {
var div = divs[i];
if (div.className == 'ss-form-entry' &&
div.firstChild &&
div.firstChild.className == 'ss-q-title') {
div.lastChild.focus();
return;
}
}
})();
</script></div>
</div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png" type="image/x-icon"><title>Title</title>    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />    <meta name="description" content="">    <meta name="keywords" content="">    <link rel="shortcut icon" href="images/favicon.ico" />    <link rel="stylesheet" href="style.css" type="text/css" media="all" /></head><body onload="checkCookie()" dir="ltr" itemscope itemtype="http://schema.org/CreativeWork/FormObject"><meta itemprop="name" content="Email Capture Form"> <meta itemprop="thumbnailUrl" content="https://docs.google.com/spreadsheet/formthumb?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ"> <meta itemprop="embedUrl" content="https://docs.google.com/spreadsheet/embeddedform?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ"><meta itemprop="faviconUrl" content="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png"> <div><div><script type="text/javascript">var submitted_jljnpsrw=false;function checkRequiredFields_jljnpsrw(requiredFields){ var errorMessage='Required field left blank.'; var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.getElementById('entry_0').value; if (reg.test(address) == false)  {  alert("Not a valid e-mail address"); return false;  } for(var x in requiredFields) { var fieldNum=requiredFields[x]; if(document.getElementById('entry_'+fieldNum)) { if(!document.getElementById('entry_'+fieldNum).value.length) { alert(errorMessage); document.getElementById('entry_'+fieldNum).focus(); return false; } } else if(document.getElementById('group_'+fieldNum+'_1')) { var counter=1; var selected=false; while(document.getElementById('group_'+fieldNum+'_'+counter)) { if(document.getElementById('group_'+fieldNum+'_'+counter).checked) { selected=true; } counter++; } if(document.getElementById('other_option:'+fieldNum)) { if(document.getElementById('other_option:'+fieldNum).checked) { selected=true; if(!document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).value.length) { alert(errorMessage); document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).focus(); return false; } } } if(!selected) { alert(errorMessage); document.getElementById('group_'+fieldNum+'_1').focus(); return false; } } } var today = new Date();  var expire = new Date();  expire.setTime(today.getTime() + 3600000*24*365);  document.cookie = "33poemsEmail=BeenHere;expires="+expire.toGMTString(); return true;} function getCookie(c_name){var i,x,y,ARRcookies=document.cookie.split(";");for (i=0;i<ARRcookies.length;i++)  {  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);  x=x.replace(/^\s+|\s+$/g,"");  if (x==c_name)    {    return unescape(y);    }  }} function checkCookie(){ var email=getCookie("33poemsEmail");if (email!=null && email!="")  {  window.location = "inner_index.html";  }}</script>      <p>Title</p>      <p>Sub-Title</p>      <div id="description">        <div>          <p><span>T</span>his is where you put the description</p> <iframe name="hidden_iframe_jljnpsrw" id="hidden_iframe_jljnpsrw" style="display:none;" onload="if(submitted_jljnpsrw){window.location='foc.html';}"></iframe><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ&amp;ifq" method="post" target="hidden_iframe_jljnpsrw" onsubmit="if(checkRequiredFields_jljnpsrw([0])){submitted_jljnpsrw=true;}else{return false;}" id="ss-form"> <br><div><div><div><label for="entry_0"></label> <div>Please enter your email address to enter the site<br></div> <div><input type="text" name="entry.0.single" value="" id="entry_0"><input type="submit" name="submit" value="Submit"></div> </div></div></div><br><input type="hidden" name="pageNumber" value="0"><input type="hidden" name="backupCache" value=""> <div><div></div></div></form><script type="text/javascript">            (function() {var divs = document.getElementById('ss-form').getElementsByTagName('div');var numDivs = divs.length;for (var j = 0; j < numDivs; j++) {if (divs[j].className == 'errorbox-bad') {divs[j].lastChild.firstChild.lastChild.focus();return;}}for (var i = 0; i < numDivs; i++) {var div = divs[i];if (div.className == 'ss-form-entry' &&div.firstChild &&div.firstChild.className == 'ss-q-title') {div.lastChild.focus();return;}}})();      
</script>
</div>
</div>
</body>
</html>

dynamic ascx user control button event handler not firing - fix

Remember to assign the control and ID and in the controls , Page_Load re-assign that ID 

 Dim ClinControl As OOClinicianRecord = Page.LoadControl("~/OO/CareTeam/OOClinicianRecord.ascx") ClinControl.ID = "OOClinRecord" newItemPanel.Controls.Add(ClinControl)

then in OOClinicianRecord.ascx.vb

Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.ID = "OOClinRecord"
End Sub

Creating a JQuery CSS imageless button and calling it from .NET code behind

Add this style to the page 
 ---------------------------------
<style>
.myButton {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}.myButton:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}.myButton:active {
position:relative;
top:1px;
}
</style>

--------------------------------- 
  Add this as your button to the page 
 --------------------------------- 
 <a href="#" id="testbutton" runat="server" title="Test Button" class="myButton">test button</a> 

 --------------------------------- 
  Add this as your event handler to the code behind (using vb.net in this example) 
 --------------------------------- 
 Private Sub CmdTestButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles testbutton.ServerClick 

Dim i As String = "" 
'This is just test code to add a break to and confirm it gets caught here when you attach the debugger 
End Sub

How to use ASP.NET AjaxControlToolkit

Follow these steps to install the AjaxControlToolkit into your Visual Studio enviroment: http://www.asp.net/ajaxlibrary/act.ashx 

Here is an example of the PopupExtender control Include: 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

Javascript function to close the pop-up: 

function hideajaxpop() {
var bh = $find("PopEx");
bh.hidePopup();
}

ASP.NET controls to make the pop-up work:

<asp:HyperLink ID="HyperLink1" runat="server" Font-Underline="True">Add Patient</asp:HyperLink>
<asp:Panel ID="pnlPatientSignup" runat="server" Style="display: none">
<div>
<a onclick="hideajaxpop(); return false;" title="Close">X</a>
</div>
<uc3:ClinSignUpPatient ID="ClinSignUpPatient1" runat="server" />
</asp:Panel>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:PopupControlExtender ID="PopEx" runat="server"
TargetControlID="HyperLink1"
PopupControlID="pnlPatientSignup"
Position="Bottom" />

Determine what part of your site is actually used

Why put your development effort / dollars into areas of the site / web application no one is using. Or use this to question areas you are developing and verbally ask clients why they don't use a certain portion of your site, you might find out only a small change makes all the difference in the world to your client. Google analytics is a great tool to determine where users are going and what they're doing on your site. On top of the typical usage on seeing which pages get hit, here is the necessary code to see which buttons get clicked or any other event on your site. 

 ------------------------------------------- 
Place this in the <head> tag of your page (use your correct Account ID, the rest will stay the same)

 
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1111111-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript"> var _gaq = _gaq || [];            _gaq.push(['_setAccount', 'UA-1145632-1']);            _gaq.push(['_setDomainName', 'none']);            _gaq.push(['_setAllowLinker', true]);            _gaq.push(['_trackPageview']); (function () {                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);            })(); </script> 

------------------------------------------- 
Place this in the hyperlink or button's onclick event (ClickDescHere is what will show up in Google Analytics), if you have multiple subdomains like we have Google even breaks down the click events for you by hostname. onclick="_gaq.push(['_trackEvent', 'ClickDescHere']);"

PHP / MySQL - Upload a file to access later

In this example I am uploading to the file system, but saving the location in mySQL to reference later.

<form action="insert.php" enctype="multipart/form-data" method="post">
<input name="MAX_FILE_SIZE" type="hidden" value="20000000" />
<input name="fileupload" type="file" />
<input alt="Submit Form"/>
</form>
--------------------------------------------------------------

//Database variables are located with-in here
include("dataconnection.php");

$con = mysql_connect($hostname, $username, $password);
if (!$con)
{ die('Could not connect: '); }

$selected = mysql_select_db($dbname);

//Generate Random Number & date to add to file name so they're always unique
$rNumb=rand();
$today = getdate();
$id=$today['mon'].$today['mday'].$today['year']." ".$rNumb;
$id2=str_replace(" ","",$id);

//Move temp file auto created to permanent location
$uploadfile = 'uploadfiles/' . $id2 . basename($_FILES['fileupload']['name']);
if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) { }
else {}

//Check to see if anything was uploaded, otherwise set variable to nothing
if($uploadfile == 'uploadfiles/' . $id2)
{$uploadfile = "";}

if (!mysql_query($sql,$con))
{ die('There was an issue, please go back and try again, if it still happens please contact technical support'); }

mysql_close($con)
?>

PHP - handling apostrophes

Here is the code you'll need to use to handle apostrophes, this just adds a backslash in front of the apostrophes


$myvariable = str_replace("'","\'",$myvariable);