Wednesday, December 25, 2013

Using Htmlframe tag instead of Iframe tag

I recently was working on a project where I had to use an Iframe. This Iframe would get querystring parameters and pass it to the associated page in the Iframe. Now, if your using a standard .aspx page, you won't need this tip. This tip if for people that are using Iframes in their controls. Since controls use System.Web.UI.UserControl and not the standard System.Web.UI.Page that pages use. You won't be able to use the standard Iframe tag. Instead you'll need to use the server Iframe version. Before using this server tag, you'll need to add the snippet below to your web.config in the controls section. Then add the following snippet in your control. Hope this was helpful!  
 <controls>
      <add assembly="System.Web" namespace="System.Web.UI.HtmlControls"
tagprefix="asp"/>   </controls>

 <asp:HtmlIframe frameborder="0" height="650" id="myiframe" name="myiframe" runat="server" src="prefcontent.aspx" width="400">
</asp:HtmlIframe>

Monday, September 23, 2013

Converting WordPress from Windows to Apache Server Error

Recently I was working with a charity that had a WordPress site running on a Windows server.  The owner decided to change it to an Apache server.  After the conversion he noticed that none of his child pages where linking.  It displayed a very vague error which could have most people changing things they don't need to touch.  In the snippet below, you'll see the code that needs to be changed in your root .htaccess file.  You can basically copy the whole thing and paste it over what's currently in that file.  Happy Coding! ☺

 
# BEGIN WordPress
ErrorDocument 404 /index.php?error=404
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Monday, July 8, 2013

How to Send an Email With App Setting in Web Config File.

A few years ago I was thinking about converting some of my settings to be accessed in one place. The other day a happened to run across this example that displays exactly how I approached it back then.  The problem was, back then there wasn't the resources available like there are today.  This example is strait to the point and will get you on the right path.  You can also incorporate any additional settings like this example into your config file as well. CODE EXAMPLE
Happy Coding!!!! ☺

Monday, July 1, 2013

Creating a JQuery Alert for a Specific Date or Date Range

Recently, one of my clients needed an alert to display changes to one of their processes. They needed it to display every time a user visited the page until it reached a specific date. In the example below I've created a basic Javascript function that allows you to enter a start date, end date and return type. For example, after you've added your start and end date you want to either put in weeks, days, hours, minutes or seconds into the interval property. Next, create a JQUERY function that will call the datediff and display an alert dialog with the content you've assigned which in this case is a div that has an id of "alertDate".
//START HEAD SECTION
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet"></link>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script>
function datediff(fromDate, toDate, interval) {
   var second = 1000, minute = second * 60, hour = minute * 60, 
   day = hour * 24,week = day * 7;
   fromDate = new Date(fromDate);
   toDate = new Date(toDate);
   var timediff = toDate - fromDate;
   if (isNaN(timediff)) return NaN;
   switch (interval) {
   case "years": return toDate.getFullYear() - fromDate.getFullYear();
   case "months": return ((toDate.getFullYear() * 12 + toDate.getMonth())
   -
   (fromDate.getFullYear() * 12 + fromDate.getMonth()));
   case "weeks": return Math.floor(timediff / week);
   case "days": return Math.floor(timediff / day);
   case "hours": return Math.floor(timediff / hour);
   case "minutes": return Math.floor(timediff / minute);
   case "seconds": return Math.floor(timediff / second);
   default: return undefined;
  }
 }

$(function () {
   var curDate = new Date();
   var alertDate = new Date();
   alertDate.setDate(alertDate.getDate() + 
   datediff(curDate, alertDate, 'days'));

    if (alertDate.toDateString() >= curDate.toDateString()) {
                
      $("#alertMsg").dialog({
      height: 500,
      width: 650,
      modal: true
    });
   }
});
</script>
//END HEAD SECTION

//START BODY SECTION
<div id="alertMsg" style="background-color: #f5fa64;" title="IMPORTANT NOTIFICATION!!">
<h2 style="font-size: 30px; margin: 0; text-align: center;">
ATTENTION!!</h2>
This is a custom alert that will continue to display until the current date time is greater or equal to 
            the current date time.
        </div>
//END BODY SECTION

Saturday, May 18, 2013

When to comment your code

The other day I was browsing through some of the organizations I follow on twitter when I stumbled across this post from Ardalis.com.  This is a great article for programmers just getting starting as well as season professionals.  It gives you a great insight about when its the proper time to add comments to your code.  I think there are times that programmers in general struggle with whether or not it's the proper time to comment code.  I believe the main reason maybe that most of us think we write clean code or our naming convention is second to none.  Personally, I try to only comment in complex situations where I absolutely need to describe a function or procedure to perhaps give myself or another programmer an idea so he/she knows what's going on.  The thing to remember is that, what makes since to you may not make since to the programmer that follows behind you.  Also, know one likes coming in on a project where every other line is commented or there are giant paragraphs that start with some thing like, "// Dear maintainer:".  On top of that, it's also extremely irritating at lease to me when there's code that was added three plus years old and the code itself is actually not in the project anymore.  Anyway, below is the link to the article, hope it helps you or anyone else needing some clarification or understanding when and/or where not to add comments into an application.  Happy coding!!!  Article Link