<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codelab Blog</title>
	<atom:link href="http://blog.codelab.co.nz/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting the screen position when visiting previous page with jQuery</title>
		<link>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/</link>
		<comments>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 13:10:43 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=373</guid>
		<description><![CDATA[The scenario This problem came while I was working on a client’s website. Take this scenario. I have a listing page (similar to a listing page from www.trademe.co.nz or www.ascent.co.nz ). They have a lot of listings. Each listing has a hyperlink going to a detail page which describes more about each listing. If you [...]]]></description>
			<content:encoded><![CDATA[<p>The scenario</p>
<p>This problem came while I was working on a client’s website. Take this scenario. I have a listing page (similar to a listing page from <a title="TradeMe" href="http://www.trademe.co.nz" target="_blank">www.trademe.co.nz</a> or <a title="Ascent Technologies" href="http://www.ascent.co.nz " target="_blank">www.ascent.co.nz </a>). They have a lot of listings. Each listing has a hyperlink going to a detail page which describes more about each listing.<br />
If you have quite a large page of listings, the user has to scroll down the page to find the listing they want to click on. The problem is, when they click on the link and go to the details page, what happens when the click back and they end up back at the top of the page again? This can be quite annoying. It would be “nice” to get the browser to go back to the previous position on the listing page.</p>
<p>The Approach</p>
<p>We achieve this but attach a click event handler to the specific a tags that we want to record the last clicked position from the user before we redirect to the next page. This means when the user goes back to the previous page they will be taken to the exact position on the page. When the click event happens we always override what was in the cookie so that we don’t end up with several pages and positions. We don’t want a user to go to another page they have been to before and set the scroll position, it should only happen to the previous page.</p>
<p>Here is the code</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var COOKIE_NAME = &quot;scroll&quot;;<br />
&nbsp;<br />
$(document).ready(function () {<br />
&nbsp; &nbsp; // Check to see if the user already has the cookie set to scroll<br />
&nbsp; &nbsp; var scrollPosition = getCookiePosition(COOKIE_NAME);<br />
&nbsp; &nbsp; if (scrollPosition.length &gt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Scroll to the position of the last link clicked<br />
&nbsp; &nbsp; &nbsp; &nbsp; window.scrollTo(0, parseInt(scrollPosition, 10));<br />
&nbsp; &nbsp; }<br />
&nbsp;<br />
&nbsp; &nbsp; // Attach an overriding click event for each link <br />
&nbsp; &nbsp; // saveScrollPosition function can be called before the user is redirected.<br />
&nbsp; &nbsp; $(&quot;a.savel&quot;).each(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; saveScrollPosition($(this));<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; });<br />
});<br />
&nbsp;<br />
// Get the offset (height from top of page and the current page url) of the link element<br />
// and save it in a cookie.<br />
function saveScrollPosition(link) {<br />
&nbsp; &nbsp; var linkTop = link.offset().top;<br />
&nbsp; &nbsp; setCookie(COOKIE_NAME, &quot;pos=&quot; + linkTop + &quot;&amp;link=&quot; + escape(window.location.pathname), 1);<br />
}<br />
&nbsp;<br />
//Trim whitespaces<br />
function trim(str) {<br />
&nbsp; &nbsp;return str.replace(/^\s+|\s+$/g, '');<br />
} <br />
// Get cookie helper function<br />
function getCookiePosition(name) {<br />
&nbsp; &nbsp; if (document.cookie.length &gt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; //Get the right cookie<br />
&nbsp; &nbsp; &nbsp; &nbsp; var cookies = document.cookie.split(&quot;;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i &lt; cookies.length; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (trim(cookies[i].split(&quot;=&quot;)[0]) == COOKIE_NAME) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the position of the &amp; sign<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var pos = cookies[i].indexOf(&quot;&amp;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pos &gt; -1) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var scrollValue = cookies[i].split(&quot;=&quot;)[2].substring(0, cookies[i].split(&quot;=&quot;)[2].indexOf(&quot;&amp;&quot;));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var link = unescape(trim(cookies[i].split(&quot;=&quot;)[3]));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //if the link is the same as the current page, then assume user wants to go back to the same position<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (link == window.location.pathname) return scrollValue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return &quot;&quot;;<br />
}<br />
&nbsp;<br />
//Method to create a new cookie<br />
function createCookie(name, value, days) {<br />
&nbsp; &nbsp; if (days) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var date = new Date();<br />
&nbsp; &nbsp; &nbsp; &nbsp; date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));<br />
&nbsp; &nbsp; &nbsp; &nbsp; var expires = &quot;; expires=&quot; + date.toGMTString();<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else var expires = &quot;&quot;;<br />
&nbsp; &nbsp; document.cookie = name + &quot;=&quot; + value + expires + &quot;; path=/&quot;;<br />
}<br />
&nbsp;<br />
// Set cookie<br />
function setCookie(name, value, expiredays) {<br />
&nbsp; &nbsp; //Remove all other cookies<br />
&nbsp; &nbsp; var cookies = document.cookie.split(&quot;;&quot;);<br />
&nbsp; &nbsp; for (var i = 0; i &lt; cookies.length; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (trim(cookies[i].split(&quot;=&quot;)[0]) == COOKIE_NAME) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createCookie(trim(cookies[i].split(&quot;=&quot;)[0]), &quot;&quot;, -1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; //Set the new cookie<br />
&nbsp; &nbsp; createCookie(name, value, expiredays);<br />
}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Fontis Paymate Module Fix for Not Passing Data Issue</title>
		<link>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/</link>
		<comments>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 03:56:29 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=370</guid>
		<description><![CDATA[I upgraded my magento from 1.4.0.1 to 1.6.1 and yes a lot of things broke especially the ability to pay using Paymate. I did some research and found a lot of people having the issue of non data being passed from Magento to Paymate to populate the fields like address, amount etc. Since there has [...]]]></description>
			<content:encoded><![CDATA[<p>I upgraded my magento from 1.4.0.1 to 1.6.1 and yes a lot of things broke especially the ability to pay using Paymate.<br />
I did some research and found a lot of people having the issue of non data being passed from Magento to Paymate to populate the fields like address, amount etc.   Since there has been no support at all? I decided to take matters into my own hands.</p>
<p>Here is the code from the file: /app/code/community/Fontis/Paymate/Model/Paymate.php<br />
replace this file with your original file Paymate.php.  As always I suggest that you back up everything!<br />
This worked for me.  Technically the issue was the code didn&#8217;t like getting the getQuote() from the checkout/session object.  Instead getting the getLastRealOrderId from checkout/session and loading a new model with the order id worked.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?php<br />
/**<br />
&nbsp;* Fontis Paymate Extension<br />
&nbsp;*<br />
&nbsp;* NOTICE OF LICENSE<br />
&nbsp;*<br />
&nbsp;* This source file is subject to the Open Software License (OSL 3.0)<br />
&nbsp;* that is bundled with this package in the file LICENSE.txt.<br />
&nbsp;* It is also available through the world-wide-web at this URL:<br />
&nbsp;* http://opensource.org/licenses/osl-3.0.php<br />
&nbsp;* If you did not receive a copy of the license and are unable to<br />
&nbsp;* obtain it through the world-wide-web, please send an email<br />
&nbsp;* to license@magentocommerce.com so one can be sent to you a copy immediately.<br />
&nbsp;*<br />
&nbsp;* @category &nbsp; Fontis<br />
&nbsp;* @package &nbsp; &nbsp;Fontis_Paymate<br />
&nbsp;* @author &nbsp; &nbsp; Lloyd Hazlett<br />
&nbsp;* @author &nbsp; &nbsp; Chris Norton<br />
&nbsp;* @copyright &nbsp;Copyright (c) 2010 Fontis Pty. Ltd. (http://www.fontis.com.au)<br />
&nbsp;* @license &nbsp; &nbsp;http://opensource.org/licenses/osl-3.0.php &nbsp;Open Software License (OSL 3.0)<br />
&nbsp;*/<br />
<br />
/**<br />
&nbsp;* Paymate payment model<br />
&nbsp;*<br />
&nbsp;* @category &nbsp; Fontis<br />
&nbsp;* @package &nbsp; &nbsp;Fontis_Australia<br />
&nbsp;*/<br />
class Fontis_Paymate_Model_Paymate extends Mage_Payment_Model_Method_Abstract<br />
{<br />
&nbsp; &nbsp; const CGI_URL = 'https://www.paymate.com/PayMate/ExpressPayment';<br />
&nbsp; &nbsp; const CGI_URL_TEST = 'https://www.paymate.com/PayMate/TestExpressPayment';<br />
&nbsp; &nbsp; const REQUEST_AMOUNT_EDITABLE = 'N';<br />
<br />
&nbsp; &nbsp; protected $_code &nbsp;= 'paymate';<br />
&nbsp; &nbsp; protected $_formBlockType = 'fontis_paymate_block_form';<br />
&nbsp; &nbsp; protected $_allowCurrencyCode = array('AUD', 'EUR', 'GBP', 'NZD', 'USD');<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; protected $_isGateway &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canAuthorize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= false;<br />
&nbsp; &nbsp; protected $_canCapture &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= true;<br />
&nbsp; &nbsp; protected $_canCapturePartial &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canRefund &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canVoid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canUseInternal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= false;<br />
&nbsp; &nbsp; protected $_canUseCheckout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= true;<br />
&nbsp; &nbsp; protected $_canUseForMultishipping &nbsp;= false;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Assign data to info model instance<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param &nbsp; mixed $data<br />
&nbsp; &nbsp; &nbsp;* @return &nbsp;Fontis_Australia_Model_Payment_Paymate<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function assignData($data)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $details = array();<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ($this-&gt;getUsername())<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $details['username'] = $this-&gt;getUsername();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (!empty($details)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;getInfoInstance()-&gt;setAdditionalData(serialize($details));<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getUsername()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this-&gt;getConfigData('username');<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; public function getUrl()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $url = $this-&gt;getConfigData('cgi_url');<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; if(!$url)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $url = self::CGI_URL_TEST;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; return $url;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get session namespace<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Fontis_Australia_Model_Payment_Paymate_Session<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getSession()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return Mage::getSingleton('paymate/paymate_session');<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get checkout session namespace<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Mage_Checkout_Model_Session<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getCheckout()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return Mage::getSingleton('checkout/session');<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get current quote<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Mage_Sales_Model_Quote<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getQuote()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this-&gt;getCheckout()-&gt;getQuote();<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getCheckoutFormFields()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $orderIncrementId = $this-&gt;getCheckout()-&gt;getLastRealOrderId();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $order = Mage::getModel('sales/order')-&gt;loadByIncrementId($orderIncrementId);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $a = $order-&gt;getShippingAddress();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $b = $order-&gt;getBillingAddress();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $currency_code = $order-&gt;getCurrencyCode();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$cost = $order-&gt;getSubtotal() - $order-&gt;getDiscountAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $cost = $order-&gt;getGrandTotal();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$shipping = $order-&gt;getShippingAmount();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$_shippingTax = $order-&gt;getShippingAddress()-&gt;getTaxAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$_billingTax = $order-&gt;getBillingAddress()-&gt;getTaxAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //$tax = sprintf('%.2f', $_shippingTax + $_billingTax);<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$cost = sprintf('%.2f', $cost + $tax);<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $fields = array(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'mid' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $this-&gt;getUsername(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'amt' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; sprintf('%.2f', $cost + $shipping),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'amt_editable'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; self::REQUEST_AMOUNT_EDITABLE,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'currency'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $currency_code,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ref' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $orderIncrementId,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_sender_email'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getEmail(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_firstname' =&gt; $b-&gt;getFirstname(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_surname' &nbsp; =&gt; $b-&gt;getLastname(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_phone' &nbsp; &nbsp; =&gt; $b-&gt;getTelephone(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_country' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getCountry(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_address1'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getStreet(1),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_address2'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getStreet(2),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_sub' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getCity(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_state' &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getRegion(), &nbsp; &nbsp; // Returns full state name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_pcode' &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getPostcode(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'return'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; Mage::getUrl('paymate/paymate/complete'),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'popup' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'N',<br />
&nbsp; &nbsp; &nbsp; &nbsp; );<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Run through fields and replace any occurrences of &amp; with the word <br />
&nbsp; &nbsp; &nbsp; &nbsp; // 'and', as having an ampersand present will conflict with the HTTP<br />
&nbsp; &nbsp; &nbsp; &nbsp; // request.<br />
&nbsp; &nbsp; &nbsp; &nbsp; $filtered_fields = array();<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach ($fields as $k=&gt;$v) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $value = str_replace(&quot;&amp;&quot;,&quot;and&quot;,$v);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $filtered_fields[$k] = &nbsp;$value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; return $filtered_fields;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function createFormBlock($name)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $block = $this-&gt;getLayout()-&gt;createBlock('paymate/paymate_form', $name)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setMethod('paymate')<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setPayment($this-&gt;getPayment())<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setTemplate('fontis/paymate/form.phtml');<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $block;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /*validate the currency code is avaialable to use for paypal or not*/<br />
&nbsp; &nbsp; public function validate()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::validate();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $currency_code = $this-&gt;getQuote()-&gt;getBaseCurrencyCode();<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (!in_array($currency_code,$this-&gt;_allowCurrencyCode)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Mage::throwException(Mage::helper('paymate')-&gt;__('Selected currency code ('.$currency_code.') is not compatabile with Paymate'));<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function onInvoiceCreate(Mage_Sales_Model_Invoice_Payment $payment)<br />
&nbsp; &nbsp; {<br />
<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function canCapture()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return true;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getOrderPlaceRedirectUrl()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Mage::getUrl('paymate/paymate/redirect');<br />
&nbsp; &nbsp; }<br />
}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When to use TempData in ASP.NET MVC</title>
		<link>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/</link>
		<comments>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 02:27:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=366</guid>
		<description><![CDATA[The problem I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the delete action so if someone attempted to modify the URL and enter a incorrect parameter [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong></p>
<p>I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the delete action so if someone attempted to modify the URL and enter a incorrect parameter into my controller, I wanted to redirect back to the previous controller and notify the user of this mistake. Take this example. I have a Product Controller and the Index Action and View lists all of the products. I have a delete action on the Product Controller which checks if the productId parameter is valid and then removes the product and redirects to the Index action using the RedirectToAction method.</p>
<p><strong>The solution</strong></p>
<p>When validating the productId, if its NOT valid simply add a new key/value to the TempData object and call the RedirectToAction method. TempData stores data for short periods of time for the current and next HTTP request. In your index view, you can check to see if your key/value pair exists and display a error message. If you refresh the page, you will notice the data from the TempData will be gone. Remember to use RedirectToAction where possible as this is more friendly with Unit Testing rather than using the HttpResponse redirect method.</p>
<p>This reference illustrates a good understanding between TempData, ViewBag and ViewData.</p>
<p><a title="Difference between ViewBag, ViewData and TempData" href="http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications" target="_blank">http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perform ASP.NET Postback using JQuery</title>
		<link>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/</link>
		<comments>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 23:47:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=363</guid>
		<description><![CDATA[Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback. Firstly, add the following JQuery/Javascript code: &#60;script&#62; &#160;function autoSubmit() &#160;{ &#160;&#60;%= ClientScript.GetPostBackEventReference(btnSaveChanges, &#34;&#34;) %&#62;; &#160;} [...]]]></description>
			<content:encoded><![CDATA[<p>Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback.</p>
<p>Firstly, add the following JQuery/Javascript code:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script&gt;<br />
<br />
&nbsp;function autoSubmit()<br />
&nbsp;{<br />
&nbsp;&lt;%= ClientScript.GetPostBackEventReference(btnSaveChanges, &quot;&quot;) %&gt;;<br />
&nbsp;}<br />
&nbsp; &nbsp; &nbsp;$(function () {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;#&lt;%= btnSaveChanges.ClientID %&gt;&quot;).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).attr(&quot;disabled&quot;, &quot;true&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoSubmit();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; &nbsp;});<br />
&lt;/script&gt;</div></div>
<p>You can inject the correct generated javascript code from using the function GetPostBackEventReference between the server tags.   Bind a click event to the ASP.NET server control which disables the button and call the autosubmit javascript function to perform a post back on the ASP.NET button control.   </p>
<p>References</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms153112.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms153112.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some useful Extension Methods</title>
		<link>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/</link>
		<comments>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 10:45:59 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=358</guid>
		<description><![CDATA[Back to basics&#8230; A couple of useful Extension methods if you are checking if a string is a valid integer or decimal. public static bool IsInteger(this string value) { if (String.IsNullOrEmpty(value)) return false; Int32 tmpNo; return Int32.TryParse(value, out tmpNo); } public static bool IsDecimal(this string value) { if (String.IsNullOrEmpty(value)) return false; Decimal tmpNo; return Decimal.TryParse(value, [...]]]></description>
			<content:encoded><![CDATA[<p>Back to basics&#8230;</p>
<p>A couple of useful Extension methods if you are checking if a string is a valid integer or decimal.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public static bool IsInteger(this string value)<br />
{<br />
if (String.IsNullOrEmpty(value)) return false;<br />
Int32 tmpNo;<br />
return Int32.TryParse(value, out tmpNo);<br />
}<br />
<br />
<br />
public static bool IsDecimal(this string value)<br />
{<br />
if (String.IsNullOrEmpty(value)) return false;<br />
Decimal tmpNo;<br />
return Decimal.TryParse(value, out tmpNo);<br />
}</div></div>
<p>To implement the Extension Methods:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var myString = &quot;10.5&quot;;<br />
<br />
if (myString.IsDecimal())<br />
<br />
{<br />
<br />
//Do something<br />
<br />
}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Areas and ASP.NET MVC Routes Tip</title>
		<link>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/</link>
		<comments>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 10:21:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Coding Practices]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=354</guid>
		<description><![CDATA[Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error &#8220;Multiple types were found that match the controller named ‘Home’.&#8221;. This is because ASP.NET MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and [...]]]></description>
			<content:encoded><![CDATA[<p>Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error <strong><em>&#8220;Multiple types were found that match the controller named ‘Home’.&#8221;</em></strong>. This is because ASP.NET MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and sees conflicts with duplicate controller names.<br />
Simple solution is to associate the namespace with the routes you are registering. Take the example below:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// global.asax route<br />
routes.MapRoute(<br />
&quot;Default&quot;, // Route name<br />
&quot;{controller}/{action}/{id}&quot;, // URL with parameters<br />
new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }, // Parameter defaults<br />
new string[] { &quot;MyApplication.Controllers&quot; } // Controller Namespace<br />
);<br />
?<br />
// Area Registration Route<br />
context.MapRoute(<br />
MyArea_default,<br />
&quot;MyArea/{controller}/{action}/{id}&quot;,<br />
new { action = &quot;Index&quot;, id = UrlParameter.Optional },<br />
new string[] { &quot;MyApplication.Areas.MyArea.Controllers&quot; }<br />
);</div></div>
<p>Credit to <a href="http://steve.testasoftware.com/?p=40">Steve Testa</a>, Thanks!.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OrderBy making null records come last Entity Framework and Linq</title>
		<link>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/</link>
		<comments>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 11:45:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=352</guid>
		<description><![CDATA[Ever want to sort your result set but make sure the records with a null sorting column appear last? See the example below var results = (from x in EntityObjectContext.MyTable &#160; &#160; &#160; &#160; &#160; &#160; &#160; select x &#160; &#160; &#160; &#160; &#160; &#160; &#160; into grp &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Ever want to sort your result set but make sure the records with a null sorting column appear last?<br />
See the example below</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var results = (from x in EntityObjectContext.MyTable<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select x<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; into grp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select new<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mydata = grp,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myid = grp.id,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysortingentity = grp.mysortingentity<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;).OrderBy(x =&gt; sortingcolumn == null).ThenBy(x =&gt; x.mysortingentity.Name).ThenBy(x =&gt; x.myid);</div></div>
<p>Watch this space, this can easily be transformed into a Extension Method.  Check out this link <a href="http://tahirhassan.blogspot.com/2010/06/linq-to-sql-order-by-nulls-last.html">http://tahirhassan.blogspot.com/2010/06/linq-to-sql-order-by-nulls-last.html</a>, this Extension method works for LinqToSQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Elmah and MVC 3 Error Handling</title>
		<link>http://blog.codelab.co.nz/2011/07/12/elmah-and-mvc-3-error-handling/</link>
		<comments>http://blog.codelab.co.nz/2011/07/12/elmah-and-mvc-3-error-handling/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 09:57:56 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=348</guid>
		<description><![CDATA[I came into an issue where I have Elmah configured on a ASP.NET MVC 3 website. I notice that the errors were not getting logged or emailed as per my configuration settings in web.config. I found that MVC3 Error Handling was handling all the errors before Elmah could handle the error and report it correctly. [...]]]></description>
			<content:encoded><![CDATA[<p>I came into an issue where I have Elmah configured on a ASP.NET MVC 3 website. I notice that the errors were not getting logged or emailed as per my configuration settings in web.config.<br />
I found that MVC3 Error Handling was handling all the errors before Elmah could handle the error and report it correctly.</p>
<p>This link was very helpful:</p>
<p><a title="Elmah and MVC 3" href="http://thecodersperspective.posterous.com/how-to-get-elmah-and-mvc3-error-handling-to-p">http://thecodersperspective.posterous.com/how-to-get-elmah-and-mvc3-error-handling-to-p</a></p>
<p>Also when using Elmah on a production environment, its a good idea to lock down the permissions for the elmah.axd handler so only users in a particular role have access to this file. (Assuming that your website is using forms authentication and role provider)</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;&lt;location path=&quot;elmah.axd&quot;&gt;<br />
&nbsp; &nbsp; &lt;system.web&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;authorization&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;allow roles=&quot;Administrators&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;deny users=&quot;*&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;/authorization&gt;<br />
&nbsp; &nbsp; &lt;/system.web&gt;<br />
&nbsp; &lt;/location&gt;</div></div>
<p>And also make sure that this setting is set to false so its not available to remote users.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;security allowRemoteAccess=&quot;0&quot; /&gt;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/07/12/elmah-and-mvc-3-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Max number of words in textarea using jQuery</title>
		<link>http://blog.codelab.co.nz/2011/06/07/max-number-of-words-in-textarea-using-jquery/</link>
		<comments>http://blog.codelab.co.nz/2011/06/07/max-number-of-words-in-textarea-using-jquery/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 00:23:30 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=345</guid>
		<description><![CDATA[Here is a little code snippet to set a maximum of words in a text area element. This could be turned into a jQuery function or refactored to be better reused, but there is a sample just to get you going. $('textarea').keyup(function () { &#160; &#160; &#160; &#160; &#160; &#160; var wordArray = this.value.split(/[\s\.\?]+/); //Split [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little code snippet to set a maximum of words in a text area element.</p>
<p>This could be turned into a jQuery function or refactored to be better reused, but there is a sample just to get you going.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$('textarea').keyup(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var wordArray = this.value.split(/[\s\.\?]+/); //Split based on regular expression for spaces<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var maxWords = 5; //max number of words<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var total_words = wordArray.length; //current total of words<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var newString = &quot;&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Roll back the textarea value with the words that it had previously before the maximum was reached<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (total_words &gt; maxWords+1) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (var i = 0; i &lt; maxWords; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newString += wordArray[i] + &quot; &quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.value = newString;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; });</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/06/07/max-number-of-words-in-textarea-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using UserControl.RenderControl()</title>
		<link>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/</link>
		<comments>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 22:08:15 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=341</guid>
		<description><![CDATA[Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose? Firstly, here is the code to render the html from a user control to a string builder object: &#160; &#160;Dim sb As New StringBuilder() &#160; &#160;Using sw As New StringWriter(sb) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose?</p>
<p>Firstly, here is the code to render the html from a user control to a string builder object:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;Dim sb As New StringBuilder()<br />
&nbsp; &nbsp;Using sw As New StringWriter(sb)<br />
&nbsp; &nbsp; &nbsp; Using htmlTw As New HtmlTextWriter(sw)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim ucUserControl As UCUserControl = LoadControl(&quot;myUserControl.ascx&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Visible = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Display() 'This is a custom method to do some processing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .RenderControl(htmlTw)<br />
&nbsp; &nbsp; &nbsp; End Using<br />
&nbsp; &nbsp;End Using</div></div>
<p>Secondly, make sure that you set <em><strong>enableEventValidation=&#8221;false&#8221;</strong></em> on the page you are generating the html from.   You will get an error if this is enabled.   You could extend this futher by adding a boolean variable to the page and only disabling Event Validation while rending the control.</p>
<p>Thirdly, override the <em><strong>VerifyRenderingInServerForm</strong></em> method and make it doing &#8220;nothing&#8221;.   If you do not do this, you will get an error saying that you have no form sever tag in your user control.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Public Overrides Sub VerifyRenderingInServerForm(control As System.Web.UI.Control)<br />
'Do nothing<br />
End Sub</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

