<?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>C#, jQuery, .NET, MVC, nHibernate, MySQL</title>
	<atom:link href="http://www.billsternberger.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.billsternberger.net</link>
	<description></description>
	<lastBuildDate>Sat, 23 Jul 2011 20:01:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Dynamically add options to dropdown list using jQuery</title>
		<link>http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/</link>
		<comments>http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 14:12:03 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=315</guid>
		<description><![CDATA[This post is going to be a fun little exercise, and is a technique that used to carry some overhead (in terms of postbacks and viewstate) back in the day. The objective is to provide users with a dropdownlist containing pre-selected options &#8211; but allow them to add their own options, and persist those options [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-add-dropdownlist-option-using-jquery%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-add-dropdownlist-option-using-jquery%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-add-dropdownlist-option-using-jquery%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This post is going to be a fun little exercise, and is a technique that used to carry some overhead (in terms of postbacks and viewstate) back in the day. The objective is to provide users with a dropdownlist containing pre-selected options &#8211; but allow them to add their own options, and persist those options back to the database.</p>
<p>Ingredients:<br />
1 &#8211; dropdownlist<br />
1 &#8211; textbox<br />
2 &#8211; divs<br />
3 &#8211; links<br />
3 &#8211; jquery functions<br />
1 &#8211; controller method</p>
<p>First we will create our html form. So far there is nothing controversial here, we are simply creating one div to hold the dropdownlist and the &#8220;add&#8221; link, and another div to hold the textbox and save/cancel links. To keep it simple, we are going to make this a color list:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;div id=&quot;FavoriteColorsList&quot;&gt;
&lt;select name=&quot;FavoriteColor&quot; id=&quot;FavoriteColor&quot; style=&quot;width:350px;&quot;&gt;
&lt;option value=&quot;&quot;&gt; Choose your favorite color&lt;/option&gt;
&lt;option value=&quot;Red&quot;&gt;Red&lt;/option&gt;
&lt;option value=&quot;Blue&quot;&gt;Blue&lt;/option&gt;
&lt;option value=&quot;Green&quot;&gt;Green&lt;/option&gt;
&lt;/select&gt;
&lt;a href=&quot;#&quot; onclick=&quot;AddCustomFavoriteColor(); return false;&quot;&gt;add my color&lt;/a&gt;
&lt;/div&gt;

&lt;div id=&quot;CustomFavoriteColorform&quot; style=&quot;display:none;&quot;&gt;
&lt;input type=&quot;text&quot; id=&quot;CustomFavoriteColor&quot; name=&quot;customFavoriteColor&quot; style=&quot;width:250px;&quot;&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;#&quot; onclick=&quot;SaveCustomFavoriteColor(); return false;&quot;&gt;save&lt;/a&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;#&quot; onclick=&quot;CancelCustomFavoriteColor(); return false;&quot;&gt;cancel&lt;/a&gt;
&lt;/div&gt;
</pre>
<p>The expected behavior is to show the dropdown initially, and then once the user clicks the &#8220;add my color&#8221; link, to hide the dropdown div, and then display the textbox div. To make this happen, we have three jquery functions that are called from the links:</p>
<pre class="brush: csharp; title: ; notranslate">

function AddCustomFavoriteColor() {
    $(&quot;#FavoriteColorsList&quot;).hide(&quot;fast&quot;);
    $(&quot;#CustomFavoriteColorform&quot;).show(&quot;fast&quot;);
    $(&quot;#CustomFavoriteColor&quot;).val(&quot;&quot;);
    $(&quot;#CustomFavoriteColor&quot;).focus();
}

function CancelCustomFavoriteColor() {
    $(&quot;#CustomFavoriteColor&quot;).val(&quot;&quot;);
    $(&quot;#FavoriteColorsList&quot;).show(&quot;fast&quot;);
    $(&quot;#CustomFavoriteColorform&quot;).hide(&quot;fast&quot;);
}

function SaveCustomFavoriteColor() {
    var opt = &quot;&lt;option value='&quot; + $(&quot;#CustomFavoriteColor&quot;).val() + &quot;'&gt;&quot; + $(&quot;#CustomFavoriteColor&quot;).val() + &quot;&lt;/option&gt;&quot;;

    $('#FavoriteColor').append(opt)
    $(&quot;#FavoriteColor&quot;).val($(&quot;#CustomFavoriteColor&quot;).val());

    $.post(&quot;/[YOUR-CONTROLLER]/[YOUR-METHOD]&quot;, { FavoriteColor: $(&quot;#CustomFavoriteColor&quot;).val() },
        function(data) {
            $(&quot;#CustomFavoriteColor&quot;).val(&quot;&quot;);
            $(&quot;#FavoriteColorsList&quot;).show(&quot;fast&quot;);
            $(&quot;#CustomFavoriteColorform&quot;).hide(&quot;fast&quot;);
        });
}
</pre>
<p>The last part is the server-side code to persist the saved value to the database. That is where you need to make sure you have some level of security, ideally something greater than what <a target="_blank" href="http://www.dailymail.co.uk/news/article-2003393/How-Citigroup-hackers-broke-door-using-banks-website.html" onclick="pageTracker._trackPageview('/outgoing/www.dailymail.co.uk/news/article-2003393/How-Citigroup-hackers-broke-door-using-banks-website.html?referer=');">citibank</a> rolled out.</p>
<p>Below is a video clip of the code in action:</p>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/IRoe_ss_s5M?hl=en&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<div class="shr-publisher-315"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Store images on Flickr using Flickrnet.dll and ASP.NET MVC</title>
		<link>http://www.billsternberger.net/asp-net-mvc/store-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/store-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 20:49:57 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[flickrnet.dll]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=313</guid>
		<description><![CDATA[For one of my recent projects I had to use Flickr as an image repository, so this code just shows how I was able to do that with the help of the fantastic Flickrnet.dll library. You can download the latest Flickrnet library here: http://flickrnet.codeplex.com/. You can also download the article&#8217;s full working Flickr demo code. [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fstore-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fstore-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fstore-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>For one of my recent projects I had to use Flickr as an image repository, so this code just shows how I was able to do that with the help of the fantastic Flickrnet.dll library. You can download the latest Flickrnet library here: <a href="http://flickrnet.codeplex.com/" onclick="pageTracker._trackPageview('/outgoing/flickrnet.codeplex.com/?referer=');">http://flickrnet.codeplex.com/</a>. You can also download the article&#8217;s full working <a href="http://bit.ly/fDr1Ss" onclick="pageTracker._trackPageview('/outgoing/bit.ly/fDr1Ss?referer=');">Flickr demo code</a>.</p>
<h2>Getting Started</h2>
<p>Before we dive into the MVC portion, you have to make sure you have installed the flickrnet.dll file, referenced it, and added the appropriate web.config elements. </p>
<h3>configSections element</h3>
<p>Append the following element after the default sectionGroup:<br />
<code>&lt;section name="flickrNet" type="FlickrNet.FlickrConfigurationManager,FlickrNet"/&gt;</code></p>
<p>And setup your database connection strings</p>
<h3>Flickrnet element</h3>
<p>Add the following element before the appSettings element:<br />
<code>&lt;flickrNet apiKey="YOUR_API_KEY" secret="YOUR_SECRET" cacheDisabled="true"/&gt;</code></p>
<h3>appSettings element</h3>
<p>Add the following keys to the appSettings element:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;add key=&quot;FlickrAuthtoken&quot; value=&quot;YOUR_FROB/TOKEN&quot; /&gt;
&lt;add key=&quot;FlickrUserId&quot; value=&quot;YOUR_USERID&quot;/&gt;
</pre>
<p><a href="http://www.billsternberger.net/wp-content/uploads/2010/03/webconfig-settings.png"><img src="http://www.billsternberger.net/wp-content/uploads/2010/03/webconfig-settings-300x153.png" alt="" title="webconfig-settings" width="300" height="153" class="aligncenter size-medium wp-image-319" /></a><br/><center>Click on the thumbnail for a larger view</center><br/><br/></p>
<p>That is all you need to do in web.config. You get your apikey and secret through flickr. An awesome article off the flickrnet.codeplex site covers how to get your FROB/Token: <a href="http://blogs.msdn.com/coding4fun/archive/2006/11/22/1126978.aspx" onclick="pageTracker._trackPageview('/outgoing/blogs.msdn.com/coding4fun/archive/2006/11/22/1126978.aspx?referer=');">http://blogs.msdn.com/coding4fun/archive/2006/11/22/1126978.aspx</a>. </p>
<h2>Database Setup</h2>
<p>The images are going to be uploaded to Flickr, but we are going to keep references to the images in the database for later retrieval. Here is the table script if you are using MySQL:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE  `sampledb`.`Image` (
  `ImageID` int(11) NOT NULL AUTO_INCREMENT,
  `ImageURL` varchar(250) DEFAULT NULL,
  `Tags` varchar(150) DEFAULT NULL,
  `FlickrID` varchar(50) DEFAULT NULL,
  `ImageURLThumbnail` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`ImageID`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
</pre>
<p>or if you are using SQL Server:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE  [SampleDB].[dbo].[Image] (
  ImageID int NOT NULL IDENTITY,
  ImageURL varchar(250) DEFAULT NULL,
  Tags varchar(150) DEFAULT NULL,
  FlickrID varchar(50) DEFAULT NULL,
  ImageURLThumbnail varchar(250) DEFAULT NULL,
  PRIMARY KEY (ImageID)
);
</pre>
<p>Once the database is setup, all we have left is the code for uploading, storing, and retrieving the images.</p>
<h2>Uploading Images into Flickr</h2>
<p>This part is easier than you think. We start out with a typical upload form. For this sample we are going to only have a file input control and a textbox to store our tags:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;form method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; id=&quot;form1&quot; action=&quot;/Home/Index&quot;&gt;
        &lt;b&gt;Image&lt;/b&gt;&lt;br /&gt;
        &lt;input type=&quot;file&quot; name=&quot;NewImageName&quot; id=&quot;NewImageName&quot; /&gt;
        &lt;br /&gt;&lt;br /&gt;
        &lt;b&gt;Tags&lt;/b&gt;&lt;br /&gt;
        &lt;input type=&quot;text&quot; name=&quot;NewImgTags&quot; id=&quot;NewImgTags&quot; /&gt;
        &lt;br /&gt;
        &lt;input type=&quot;submit&quot; value=&quot;Upload&quot; /&gt;
    &lt;/form&gt;
</pre>
<p>Nothing controversial there, moving on to the controller is where we find the meat. The first thing the controller needs is a reference to the Flirckrnet.dll and to System.Configuration, so you add your using statements:</p>
<blockquote><p>
using FlickrNet;<br />
using System.Configuration;
</p></blockquote>
<p>Next up is creating the Index post method. Here, we reference the Flickrnet object and upload the photo. At this point, Flickr takes the image, and depending upon the size and dimensions, will resize it into any of five different sizes: square, thumbnail, small, medium, and large. </p>
<p>We then loop through the different sizes Flickr sends back, and store the thumbnail and large image urls into our table. Below is part of the controller method that uploads the image, and then loops through the sizes. You can <a href="http://bit.ly/fDr1Ss" onclick="pageTracker._trackPageview('/outgoing/bit.ly/fDr1Ss?referer=');">download a full working sample here</a>.</p>
<pre class="brush: csharp; title: ; notranslate">
var flickr = new Flickr
{
    AuthToken = ConfigurationManager.AppSettings[&quot;FlickrAuthtoken&quot;]
};

//
//  Upload the image, title, tags, security settings
//
var flickr_id = flickr.UploadPicture(file.InputStream, ImageTitle, ImageDescription, ImageTags, IsPublic,IsFamily,IsFriends);

//
//  Loop through links to resized images up on flickr
//  and store in the database
//
var flickrPhotos = flickr.PhotosGetSizes(flickr_id);

Image newImage = new Image();
newImage.FlickrID = flickr_id.ToString();

//
//  I only care about the thumbnail and the large image, but
//  you can store all of them (when applicable)
//
for (int i = 0; i &lt; flickrPhotos.SizeCollection.Length; i++)
{
    switch (flickrPhotos.SizeCollection[i].Label)
    {
        case &quot;Square&quot;:
            break;
        case &quot;Thumbnail&quot;:
            newImage.ImageURLThumbnail = flickrPhotos.SizeCollection[i].Source;
             break;
        case &quot;Small&quot;:
             break;
        case &quot;Medium&quot;:
             break;
        case &quot;Large&quot;:
             newImage.ImageURL = flickrPhotos.SizeCollection[i].Source;
             ViewData[&quot;NewUrl&quot;] = flickrPhotos.SizeCollection[i].Source;
             break;
    }
}

newImage.Tags = ImageTags;
newImage.CreateAndFlush();
</pre>
<p>The code sample then sends the large image url from Flickr back down to the browser to preview. Below is a video of the code in action:</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Pvqt8REJ948&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Pvqt8REJ948&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<div class="shr-publisher-313"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/store-images-on-flickr-using-flickrnet-dll-and-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Update textbox with ASP.NET, MVC, jQuery</title>
		<link>http://www.billsternberger.net/asp-net-mvc/update-textbox-with-asp-net-mvc-jquery/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/update-textbox-with-asp-net-mvc-jquery/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 15:45:23 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[update textbox with jquery]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=304</guid>
		<description><![CDATA[This post arrives to you today from the awesome Hotel Dunn Inn in beautiful San Jose, Costa Rica! Best. Beds. Ever. It was time to clear the brain and work on some pet projects, and of course code. In this sample we will look at updating values in textboxes, and then notifying the user of [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fupdate-textbox-with-asp-net-mvc-jquery%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fupdate-textbox-with-asp-net-mvc-jquery%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fupdate-textbox-with-asp-net-mvc-jquery%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This post arrives to you today from the awesome <a href="http://www.hoteldunninn.com" onclick="pageTracker._trackPageview('/outgoing/www.hoteldunninn.com?referer=');">Hotel Dunn Inn</a> in beautiful San Jose, Costa Rica! Best. Beds. Ever. It was time to clear the brain and work on some pet projects, and of course code. </p>
<p>In this sample we will look at updating values in textboxes, and then notifying the user of the results. The scenario would be having an Excel-style grid where the user can tab from field to field saving cell values with the onchange event.</p>
<h2>Adding References</h2>
<p>For this exercise, you just need a reference to the jquery library:</p>
<pre class="brush: csharp; title: ; toolbar: false; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
1

&lt;h2&gt;Setting up the Html Form&lt;/h2&gt;
We are going to add three textboxes--each with an onchange event--along with a div to hold the result. In real life, the 1, 2, and 3 values would be the item IDs.

1
    &lt;div id=&quot;resultmessage&quot; style=&quot;width:550px;&quot;&gt;&lt;/div&gt;
    Textbox 1&lt;br /&gt;
    &lt;input type=&quot;text&quot; name=&quot;textbox1&quot; id=&quot;textbox1&quot; onchange=&quot;Update('1',this.value);&quot; /&gt;
    &lt;br /&gt;&lt;br /&gt;
    Textbox 2&lt;br /&gt;
    &lt;input type=&quot;text&quot; name=&quot;textbox2&quot; id=&quot;textbox2&quot; onchange=&quot;Update('2',this.value);&quot; /&gt;
    &lt;br /&gt;&lt;br /&gt;
    Textbox 3&lt;br /&gt;
    &lt;input type=&quot;text&quot; name=&quot;textbox3&quot; id=&quot;textbox3&quot; onchange=&quot;Update('3',this.value);&quot; /&gt;
    &lt;br /&gt;&lt;br /&gt;
</pre>
<p>Whenever a user tabs off each box, it will trigger and update to the database. To do that, we add a jQuery function. The function is simple: </p>
<ul>
<li style='color:red;'>Use jQuery $.post to send the text change to your controller method</li>
<li style='color:blue;'>Check the result from the controller</li>
<li style='color:green;'>Display the success or error message</li>
</ul>
<p>Below is the entire function:</p>
<pre class="brush: csharp; title: ; notranslate">
function Update(id, val) {
            $.post(&quot;/ControllerName/UpdateTextbox&quot;,
            {
                ID: id,
                Value: val
            },
            function(data) {
                &lt;div style='color:blue;'&gt;var myObject = eval('(' + data + ')');
                var saveresult = myObject;&lt;/div&gt;
                if (saveresult != &quot;&quot;) {
                    $(&quot;#resultmessage&quot;).html(&quot;&lt;div style='display:block; background-color: Red; color: White; font-size: 18px; font-weight: bold; padding: 10px 10px 10px 10px;'&gt;Oops! &quot; + saveresult)
                    $(&quot;#resultmessage&quot;).show('slow');
                    setTimeout(&quot;$('#resultmessage').hide('slow');&quot;, 2500);
                }
                else {
                    $(&quot;#resultmessage&quot;).html(&quot;&lt;div style='display:block; background-color: Green; color: White; font-size: 18px; font-weight: bold; padding: 10px 10px 10px 10px;'&gt;Saved!&quot;)
                    $(&quot;#resultmessage&quot;).show('slow');
                    setTimeout(&quot;$('#resultmessage').hide('slow');&quot;, 2500);
                }
            });
        }
</pre>
<p>The final piece is a method in a controller&#8211;which is pretty vanilla&#8211;with one minor twist: instead of an ActionResult, we are going to use a JsonResult:</p>
<pre class="brush: csharp; title: ; notranslate">
    public JsonResult UpdateTextbox(string ID, string Value)
    {
        //This is where you would update the database
        string result = (Value.ToLower().StartsWith(&quot;r&quot;)) ? &quot;ID doesn't exist&quot; : &quot;&quot;;
        return Json(result);
    }
</pre>
<p>Below is a little video clip of the sample in action.</p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/v_URah1t7Yo&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/v_URah1t7Yo&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
<div class="shr-publisher-304"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/update-textbox-with-asp-net-mvc-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check username availability with jQuery, ASP.NET MVC, C#</title>
		<link>http://www.billsternberger.net/asp-net-mvc/check-username-availability-with-jquery-asp-net-mvc-c/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/check-username-availability-with-jquery-asp-net-mvc-c/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 04:12:44 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[AJAX username availability]]></category>
		<category><![CDATA[check username availability jquery]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=297</guid>
		<description><![CDATA[This post shows how to add dynamic username availability lookup to an ASP.NET MVC view, using jQuery and C#. There are three parts to the solution: the html form, jQuery function, and the controller. Html form This part is pretty simple: a textbox for the username field with an onchange event, a div to hold [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fcheck-username-availability-with-jquery-asp-net-mvc-c%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fcheck-username-availability-with-jquery-asp-net-mvc-c%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fcheck-username-availability-with-jquery-asp-net-mvc-c%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This post shows how to add dynamic username availability lookup to an ASP.NET MVC view, using jQuery and C#. There are three parts to the solution: the html form, jQuery function, and the controller.</p>
<h2>Html form</h2>
<p>This part is pretty simple: a textbox for the username field with an onchange event, a div to hold the lookup results, and a lookup button.<br />
<br/></p>
<pre class="brush: csharp; title: ; notranslate">
    &lt;h3&gt;Username&lt;/h3&gt;
    &lt;%= Html.TextBox(&quot;Username&quot;, &quot;&quot;, new { @onchange = &quot;CheckAvailability()&quot; })%&gt;
    &lt;div style=&quot;display:inline;&quot; id=&quot;usernamelookupresult&quot;&gt;&lt;/div&gt;&lt;br/&gt;
    &lt;input type=&quot;button&quot; value=&quot;Check Availability&quot; onclick=&quot;CheckAvailability()&quot; /&gt;
&lt;/code&gt;
</pre>
<h2>jQuery Username Lookup</h2>
<p>This is where the magic happens. Well, nothing really magical, just a jQuery call to a controller, passing in the username value. In the example below, the function processing the result looks for a 0 to indicate the username is available. You can modify that to be whatever you want.<br />
<br/><br/></p>
<pre class="brush: csharp; title: ; notranslate">
    function CheckAvailability() {
        $.post(&quot;/Home/CheckAvailability&quot;,
        { Username: $(&quot;#Username&quot;).val()},
            function(data) {
                var myObject = eval('(' + data + ')');
                var newid = myObject;
                if (newid == 0) {
                    $(&quot;#usernamelookupresult&quot;).html(&quot;&lt;font color='green'&gt;Available :-D&lt;/font&gt;&quot;)
                }
                else {
                    $(&quot;#usernamelookupresult&quot;).html(&quot;&lt;font color='red'&gt;Taken :-(&lt;/font&gt;&quot;)
                }
        });
    }
</pre>
<h2>Controller</h2>
<p>This is where your business logic lives, and is where the lookup occurs. For this exercise, we are keeping it simple, but you can see where to add your database lookup.<br />
<br/><br/></p>
<pre class="brush: csharp; title: ; notranslate">
    public ActionResult CheckAvailability(string Username)
    {
            int Taken = 0;
            //  This is where you add your database lookup
            if (Username == &quot;username&quot;)
            {
                Taken = 1;
            }
            return Json(Taken);
    }
</pre>
<p><a href="http://bit.ly/cPVNct" style="font-size:14px;" onclick="pageTracker._trackPageview('/outgoing/bit.ly/cPVNct?referer=');">Download Sample Application</a></p>
<p>Below is a quick clip to show the code from the downloadable sample in action:</p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/QdxKL3dqUlo&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/QdxKL3dqUlo&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
<div class="shr-publisher-297"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/check-username-availability-with-jquery-asp-net-mvc-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Latitude and Longitude Lookup with jQuery, C#, ASP.NET MVC</title>
		<link>http://www.billsternberger.net/asp-net-mvc/latitude-and-longitude-lookup-with-jquery-c-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/latitude-and-longitude-lookup-with-jquery-c-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 22:41:39 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[latitude longitude lookup]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=277</guid>
		<description><![CDATA[I recently had a requirement for a mapping application that required me to pass in longitude and latitude coordinates. It wasn&#8217;t realistic to have the user look those values up, so I had to figure out a way to automatically lookup the coordinates given a zip code. There are tons of pay services (some of [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Flatitude-and-longitude-lookup-with-jquery-c-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Flatitude-and-longitude-lookup-with-jquery-c-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Flatitude-and-longitude-lookup-with-jquery-c-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>I recently had a requirement for a mapping application that required me to pass in longitude and latitude coordinates. It wasn&#8217;t realistic to have the user look those values up, so I had to figure out a way to automatically lookup the coordinates given a zip code.</p>
<p>There are tons of pay services (some of which I use), but for this project needed something free. I stumbled on <a href="http://www.geonames.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.geonames.org/?referer=');">http://www.geonames.org/</a> which has a great service. You can see their webservice documentation here: <a href="http://www.geonames.org/export/web-services.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.geonames.org/export/web-services.html?referer=');">http://www.geonames.org/export/web-services.html</a>.</p>
<p>Ok, let&#8217;s get started:</p>
<h2>Web form</h2>
<p>These are the input fields we will use to perform the lookup. We are going to have three textboxes, one which has an onchange event.</p>
<pre class="brush: csharp; title: ; notranslate">
    Zip Code&lt;br/&gt;
    &lt;%= Html.TextBox(&quot;Zip&quot;, &quot;&quot;, new { @onchange = &quot;LookupCoordinates(this.value)&quot; })%&gt;
    &lt;br/&gt;&lt;br/&gt;
    Latitude: &lt;%= Html.TextBox(&quot;Lat&quot;) %&gt;,
    Longitude:&lt;%= Html.TextBox(&quot;Lon&quot;) %&gt;
</pre>
<h2>jQuery Function</h2>
<p>This function is responsible for looking up the latitude and longitude coordinates, and populating the results into the textboxes. Note that I&#8217;m wiring in US as the country below. The country is an optional parameter, when entered gives you more relevant results. Otherwise you are going to have to write some kind of loop.</p>
<pre class="brush: csharp; title: ; notranslate">
    function LookupCoordinates(zip) {
            $.post(&quot;/Home/LookupCoordinates&quot;,
            { Zip: zip, Country: &quot;US&quot; },
            function(data) {
                var result = eval('(' + data + ')');
                var coordinates = result.split(&quot;,&quot;);
                $(&quot;#Lat&quot;).val(coordinates[0]);
                $(&quot;#Lon&quot;).val(coordinates[1]);
            });
        }
</pre>
<h2>Call Geonames.org</h2>
<p>In this sample, the call to geonames.org is wired into the controller. In real life, you probably want to wrap it in some kind of helper or service class. There are a few using statements you will need:</p>
<blockquote><p>
    using System.IO;<br />
    using System.Net;<br />
    using System.Xml;
</p></blockquote>
<p>The above namespaces are important because we are going to make a WebRequest, and then parse the Xml results. The webservice method we are going to call is:</p>
<p><code>http://ws.geonames.org/postalCodeSearch?postalcode=78702&amp;maxRows=10&amp;country=US</code></p>
<p>Since we know the Zip and the Country, we should in theory only get 1 result. Below is a screenshot of the elements returned for our 78702 search (Austin):</p>
<p><a href="http://www.billsternberger.net/wp-content/uploads/2010/02/latitude-longitude-lookup-austin-tx.png"><img src="http://www.billsternberger.net/wp-content/uploads/2010/02/latitude-longitude-lookup-austin-tx-249x300.png" alt="" title="latitude-longitude-lookup-austin-tx" width="249" height="300" class="alignnone size-medium wp-image-278" /></a></p>
<p>Onto the method:</p>
<pre class="brush: csharp; title: ; notranslate">
    public ActionResult LookupCoordinates(string Zip, string Country)
    {
        string Lat = &quot;&quot;;
        string Lon = &quot;&quot;;
        string PostUrl = &quot;http://ws.geonames.org/postalCodeSearch?postalcode=&quot; + Zip + &quot;&amp;maxRows=10&amp;country=&quot; + Country;
        WebResponse webResponse = webRequest.GetResponse();
        if (webResponse == null)
        { }
        else
        {
            StreamReader sr = new StreamReader(webResponse.GetResponseStream());
            string Result = sr.ReadToEnd().Trim();
            if (Result != &quot;&quot;)
            {
                // Load the response into an XML doc
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(Result);
                //  Navigate to latitude node
                XmlNodeList name = xdoc.GetElementsByTagName(&quot;lat&quot;);
                if (name.Count &gt; 0)
                {
                    Lat = name[0].InnerText;
                }
                //  Navigate to longitude node
                name = xdoc.GetElementsByTagName(&quot;lng&quot;);
                if (name.Count &gt; 0)
                {
                     Lon = name[0].InnerText;
                }
            }
        }
        return Json(Lat + &quot;,&quot; + Lon);
    }
</pre>
<p>From there, the method returns the latitude and longitude in a comma separated string, the javascript call splits the results and populates each respective text box. Below is a video preview &#8211; really short, really lame, but you get to see the code in action:</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Wjwfn3cAtxo&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Wjwfn3cAtxo&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<div class="shr-publisher-277"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/latitude-and-longitude-lookup-with-jquery-c-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How to configure AdSense for Parked Domains</title>
		<link>http://www.billsternberger.net/google/how-to-configure-adsense-for-parked-domains/</link>
		<comments>http://www.billsternberger.net/google/how-to-configure-adsense-for-parked-domains/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 20:19:45 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[parked domain]]></category>
		<category><![CDATA[setup adsense]]></category>
		<category><![CDATA[turn parked domains into cash]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=262</guid>
		<description><![CDATA[If you&#8217;re anything like me, you probably have about 100 domains registered, doing nothing but putting money in godaddy&#8217;s pocket. I&#8217;ve been playing around with AdSense, and found some great documentation which shows how to configure your parked domains to use google&#8217;s AdSense instead. Without further adieu, here are the steps: AdSense for Domains After [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fgoogle%2Fhow-to-configure-adsense-for-parked-domains%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fgoogle%2Fhow-to-configure-adsense-for-parked-domains%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fgoogle%2Fhow-to-configure-adsense-for-parked-domains%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>If you&#8217;re anything like me, you probably have about 100 domains registered, doing nothing but putting money in godaddy&#8217;s pocket. I&#8217;ve been playing around with AdSense, and found some great documentation which shows how to configure your parked domains to use google&#8217;s AdSense instead. Without further adieu, here are the steps:</p>
<h2>AdSense for Domains</h2>
<p>After logging into your AdSense account, click the &#8220;AdSense Setup&#8221; tab, then the &#8220;Get Ads&#8221; link, and finally, click the &#8220;AdSense for Domains&#8221; link.</p>
<p><img class="alignnone size-full wp-image-263" title="setup-adsense-click-domains-step-1" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-click-domains-step-1.png" alt="" width="589" height="502" /></p>
<h2>Add your Domains</h2>
<p>This one is pretty easy. Click the &#8220;Add new domains&#8221; link to reach the add domains page.</p>
<p><img class="alignnone size-full wp-image-264" title="setup-adsense-click-add-new-domain-step-2" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-click-add-new-domain-step-2.png" alt="" width="485" height="333" /></p>
<p>From here, Google gives you two options:</p>
<ol>
<li>Manually type in all the domains you want to park (up to 1500)</li>
<li>Upload a CSV file containing your domains</li>
</ol>
<p><img class="alignnone size-full wp-image-265" title="setup-adsense-add-domains-step-3" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-add-domains-step-3.png" alt="" width="660" height="485" /></p>
<p><em>Very Important: Make sure you select your language, and then click the &#8220;Add domain(s)&#8221; button.</em></p>
<p>Once you have added your domains, you need to make DNS changes to point all those domains to google. To pull this off, you need:</p>
<ul>
<li>Your unique pub id</li>
<li>A record and CNAME values</li>
</ul>
<p>Google gives you both, and appears on the next screen after you Add your domains:</p>
<p><img class="alignnone size-full wp-image-266" title="setup-adsense-get-publisher-id-step-4" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-get-publisher-id-step-4.png" alt="" width="781" height="438" /></p>
<h2>Updating DNS Entries</h2>
<p>I&#8217;m currently on godaddy, so all my screen shots are from my account. Google does have step-by-step for other hosts like enom, register.com, 1and1, network solutions, yahoo, etc.</p>
<p>Updating with godaddy is pretty easy, whether you have 1 domain or 1500. All you have to do is apply the changes to one domain, and then bulk copy the settings to the other domains.</p>
<h3>Making CNAME and A record changes to initial domain</h3>
<p>From your domain manager, select the initial domain you want to change, and then scroll to the &#8220;Total DNS&#8221; section and click the &#8220;Total DNS Control&#8221; link.</p>
<p>Once you see the screen containing all the A, CNAME, and MX settings, click the edit icon (paper with pencil) in the CNAME&#8217;s &#8220;www&#8221; row. When the following popup opens, change the &#8220;Points To Host Name&#8221; to be your unique pub id from the AdSense page.</p>
<p><img class="alignnone size-full wp-image-267" title="setup-adsense-add-host-name-step-5" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-add-host-name-step-5.png" alt="" width="810" height="292" /></p>
<p>Click the &#8220;Ok&#8221; button, and then click the &#8220;Add New A Record&#8221; button. When the popup window opens, the IP address should point to 216.239.32.21. Repeat that for the other three IP addresses:</p>
<ul>
<li>216.239.34.21</li>
<li>216.239.36.21</li>
<li>216.239.38.21</li>
</ul>
<p><img class="alignnone size-full wp-image-268" title="setup-adsense-final-settings-step-6" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-final-settings-step-6.png" alt="" width="840" height="239" /></p>
<p>After adding all the IP addresses, now comes the fun part:</p>
<h3>Bulk Copy DNS Settings</h3>
<p>Godaddy actually makes this pretty easy. All you have to do is:</p>
<p>1. Click the &#8220;Copy&#8221; button, the following screen will pop up:</p>
<p><img class="alignnone size-full wp-image-269" title="setup-adsense-bulk-copy-settings-step-7" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-bulk-copy-settings-step-7.png" alt="" width="541" height="221" /><br />
2. Check the box next to all the domains you want receiving AdSense.</p>
<p>3. Check each box BELOW the above popup (yeah, not the best UI choice) next to the new entries (all the A Record @ rows and the CNAMES www row):</p>
<p><img class="alignnone size-full wp-image-270" title="setup-adsense-bulk-copy-settings-2-step-8" src="http://www.billsternberger.net/wp-content/uploads/2010/02/setup-adsense-bulk-copy-settings-2-step-8.png" alt="" width="454" height="198" /></p>
<p>4. Click the &#8220;Copy Records&#8221; button in the window listing all the domain names.</p>
<h2>Hurry up and wait</h2>
<p>After completing the domain registrar step, you just have to wait around for two things:</p>
<p>1. The DNS changes to propagate</p>
<p>2. Godaddy to approve your sites</p>
<p>When I did it for about 30 or so domains, the whole process took a total of 30 minutes, but your time may vary.</p>
<div class="shr-publisher-262"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/google/how-to-configure-adsense-for-parked-domains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced Auto-Complete with jQuery, MVC, and thumbnail pictures</title>
		<link>http://www.billsternberger.net/asp-net-mvc/advanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/advanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 19:37:03 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ajax autocomplete mvc]]></category>
		<category><![CDATA[asp.net mvc jquery json autocomplete]]></category>
		<category><![CDATA[autocomplete step by step code in jquery using c#]]></category>
		<category><![CDATA[autosuggest]]></category>
		<category><![CDATA[suggestion list]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=259</guid>
		<description><![CDATA[This post extends an earlier post I wrote for a basic auto complete/auto suggest textbox. In this version, we are going to return a list of our favorite social media websites, by adding a new method to the prior post&#8217;s controller which allows thumbnail pictures to appear in the auto-suggest list. New MVC Controller Method [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fadvanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fadvanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fadvanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This post extends an earlier post I wrote for a basic <a href="http://www.billsternberger.net/asp-net-mvc/auto-complete-using-mvc-jquery/">auto complete/auto suggest</a> textbox.</p>
<p>In this version, we are going to return a list of our favorite social media websites, by adding a new method to the prior post&#8217;s controller which allows thumbnail pictures to appear in the auto-suggest list. </p>
<h2>New MVC Controller Method</h2>
<p>We are going to create another JsonResult method in the controller to lookup the websites. For demo purposes, we are going to hardcode the list. In real life, you probably will be pulling the list from a database, which is covered in the earlier post.</p>
<pre class="brush: csharp; title: ; notranslate">
public JsonResult GetWebsites(string searchString)
        {
            StringBuilder sb = new StringBuilder();

            //
            //  Creating a static list here for demo purposes. In your system, you probably
            //  will have images generated from the database, disk, flickr, etc.
            //
            List&lt;string&gt; sites = new List&lt;string&gt;();
            sites.Add(&quot;Blogger&quot;);
            sites.Add(&quot;Delicious&quot;);
            sites.Add(&quot;Digg&quot;);
            sites.Add(&quot;Facebook&quot;);
            sites.Add(&quot;Flickr&quot;);
            sites.Add(&quot;FriendFeed&quot;);
            sites.Add(&quot;Friendster&quot;);
            sites.Add(&quot;LinkedIn&quot;);
            sites.Add(&quot;MySpace&quot;);
            sites.Add(&quot;StumbleUpon&quot;);
            sites.Add(&quot;Technorati&quot;);
            sites.Add(&quot;Twitter&quot;);
            sites.Add(&quot;Yahoo&quot;);
            sites.Add(&quot;Yelp&quot;);
            sites.Add(&quot;YouTube&quot;);

            for (int i = 0; i &lt; sites.Count; i++)
            {
                if (sites[i].ToLower().StartsWith(searchString.ToLower()))
                {
                    string ImageUrl = &quot;/images/&quot; + sites[i].ToString() + &quot;.png&quot;;
                    sb.Append(&quot;&lt;li onClick=\&quot;fill('&quot; + sites[i].ToString() + &quot;');\&quot;&gt;&lt;img src=\&quot;&quot; + ImageUrl + &quot;\&quot; border=\&quot;0\&quot;&gt;&amp;nbsp;&quot; + sites[i].ToString() + &quot;&lt;/li&gt;&quot;);
                }
            }
            return Json(sb.ToString());
        }
</pre>
<p>The big addition is adding the <code>&lt;img&gt;</code> tag into the list item value, that&#8217;s it :-) Now for tweaking the jquery function from the <a href="http://www.billsternberger.net/asp-net-mvc/auto-complete-using-mvc-jquery/">orinigal post</a> to call the new method:</p>
<pre class="brush: csharp; title: ; notranslate">
function lookup(inputString) {
    $.post(“/LookupCode/GetWebsites”, { searchString: “” + inputString + “”},
    function(data) {
        var myObject = eval(‘(‘ + data + ‘)’);
        if (data.length &gt; 0) {
        $(“#suggestions”).show();
        $( “#autoSuggestionsList”).html(‘&lt;ul&gt;’ + myObject + ‘&lt;/ul&gt;’);
        }
    });
}
</pre>
<p>You can download the fully-function code project here: </p>
<p><a href="http://www.billsternberger.net/asp-net-mvc/asp-net-mvc-sample-application/">Download Sample Application</a></p>
<p>Below is a video clip of the sample in action:</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/9UF1Kh4I_Dg&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6&#038;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/9UF1Kh4I_Dg&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6&#038;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<div class="shr-publisher-259"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/advanced-auto-complete-with-jquery-mvc-and-thumbnail-pictures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Import CSV or Tab Delimited Data with C#, ASP.NET MVC</title>
		<link>http://www.billsternberger.net/asp-net-mvc/import-csv-or-tab-delimited-data-with-c-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/import-csv-or-tab-delimited-data-with-c-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 14:26:39 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[asp.net mvc import csv]]></category>
		<category><![CDATA[c# load csv]]></category>
		<category><![CDATA[import csv file to database table asp .net]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=257</guid>
		<description><![CDATA[In this sample we are going to take a different approach to importing data from the traditional file upload method. This sample has a textarea and a button. Users will open their .csv or .txt file, copy the contents, paste them into the textarea, and submit. Setting up the form This part is pretty basic: [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fimport-csv-or-tab-delimited-data-with-c-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fimport-csv-or-tab-delimited-data-with-c-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fimport-csv-or-tab-delimited-data-with-c-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>In this sample we are going to take a different approach to importing data from the traditional file upload method. This sample has a textarea and a button. Users will open their .csv or .txt file, copy the contents, paste them into the textarea, and submit. </p>
<h2>Setting up the form</h2>
<p>This part is pretty basic:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;textarea id=&quot;bulkcsvlist&quot; name=&quot;bulkcsvlist&quot; rows=&quot;20&quot; cols=&quot;105&quot;&gt;&lt;/textarea&gt;
&lt;input type=&quot;submit&quot; value=&quot;Upload File&quot; /&gt;
</pre>
<h2>Create import method</h2>
<p>This sample shows the basics of parsing and adding the records,  which assumes is uploading into a Contact table, with the first two fields in the row being FirstName and LastName respectively. You probably want to bake in your security checks and data validation. </p>
<pre class="brush: csharp; title: ; notranslate">
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadAll(FormCollection f)
{
    string bulkcsvlist = f[&quot;bulkcsvlist&quot;].ToString();

    //
    //    Split the rows into an array
    //
    string[] rows = bulkcsvlist.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

    for (int i = 0; i &lt; rows.Length; i++)
    {
        //
        //    Split the tab separated fields (comma separated split commented)
        //
        //string[] dr = rows[i].Split(new  char[] {','});
        string[] dr = rows[i].Split(new char[] { '\t' });

        //
        //    Add Contact for current row
        //
        if (dr.Length &gt; 0)
        {
                Contact c = new Contact();
                c.FirstName = dr[0].ToString();
                c.LastName = dr[1].ToString();
                c.CreateAndFlush();
                c = null;
        }
    }
}
</pre>
<p>Normally I&#8217;ll throw each successful add into a List<> so whoever is uploading can validate the records look right or do any post-upload polishing, and the errors into a ViewData to display so the user can fix whatever needs fixing.</p>
<p>If you want a working sample, let me know!</p>
<div class="shr-publisher-257"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/import-csv-or-tab-delimited-data-with-c-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC sample application</title>
		<link>http://www.billsternberger.net/asp-net-mvc/asp-net-mvc-sample-application/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/asp-net-mvc-sample-application/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 20:37:47 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[sample application]]></category>
		<category><![CDATA[sample project]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=232</guid>
		<description><![CDATA[Below is a fully functional asp.net mvc sample application project. Go ahead a download it, play with it, make suggestions, extend, etc. If you have any suggestions for improvements, just drop me a line or leave a comment. The sample project assumes you have Visual Studio 2008 installed, the rest of the dlls and javascript [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fasp-net-mvc-sample-application%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fasp-net-mvc-sample-application%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fasp-net-mvc-sample-application%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>Below is a fully functional asp.net mvc sample application project. Go ahead a download it, play with it, make suggestions, extend, etc. If you have any suggestions for improvements, just drop me a line or leave a comment.</p>
<p>The sample project assumes you have Visual Studio 2008 installed, the rest of the dlls and javascript files are included in the download (nHibernate, ActiveRecord, jQuery, plugins). Also included are scripts to create the sample table schema for both SQL Server and MySQL.</p>
<p>The following mvc sample projects are included:</p>
<ul>
<li>Auto-Complete Using jQuery</li>
<li>Add a Row to a HTML Table</li>
<li>Dual Listbox in jQuery</li>
<li>TinyMCE Samples</li>
<li>Advanced Auto-Complete with jQuery, MVC, and thumbnail pictures</li>
<li>Check username availability</li>
</ul>
<p><em>IMPORTANT:</em> You need to set the username and password for your database in the web.config file for the project to work.</p>
<div style="width:500px; border: solid 3px #e4e4e4; background-color: #f4f4f4; padding: 10px 10px 10px 10px;text-align:center">
<a href='http://bit.ly/cPVNct' style="font-size:24px; font-weight: bold; color:#336699" onclick="pageTracker._trackPageview('/outgoing/bit.ly/cPVNct?referer=');">Download Sample Application Now</a>
</div>
<p>Below is a video showing the sample in action:</p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/h9wR3YQfdr4&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/h9wR3YQfdr4&#038;hl=en_US&#038;fs=1&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
<div class="shr-publisher-232"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/asp-net-mvc-sample-application/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamically populate dropdownlist  in ASP.NET MVC</title>
		<link>http://www.billsternberger.net/asp-net-mvc/dynamically-populate-dropdownlist-in-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/dynamically-populate-dropdownlist-in-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 15:01:31 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[dropdownlist]]></category>
		<category><![CDATA[dynamically populate dropdownlist]]></category>
		<category><![CDATA[HttpContext.Request.IsAjaxRequest]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=221</guid>
		<description><![CDATA[There are a few different ways to dynamically populate a dropdownlist in MVC: you could use a classic ASP old school loop with a bunch of response.writes, you can store the list&#8217;s collection into ViewData and use an html helper, or you can use jquery. We&#8217;ll look at samples for each way. Populate dropdownlist with [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fdynamically-populate-dropdownlist-in-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fdynamically-populate-dropdownlist-in-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fdynamically-populate-dropdownlist-in-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>There are a few different ways to dynamically populate a dropdownlist in MVC: you could use a classic ASP old school loop with a bunch of response.writes, you can store the list&#8217;s collection into ViewData and use an html helper, or you can use jquery. We&#8217;ll look at samples for each way.</p>
<h2>Populate dropdownlist with response.writes</h2>
<p>We will start out with the least elegant solution, but it does work nonetheless. So this is the code inside your view:</p>
<pre class="brush: csharp; title: ; notranslate">
        &lt;select id=&quot;ID&quot; name=&quot;ID&quot;&gt;
            &lt;%
             Contact[] contacts = Contact.FindAll();
             for(int i=0; i &lt; contacts.length;i++){ %&gt;
             &lt;option value=&quot;\&amp;quot;&amp;quot;&quot;&gt;&quot; + contacts[i].FullName + &quot;&lt;/option&gt;
             &lt;% } %&gt;
        &lt;/select&gt;
</pre>
<h2>Populate dropdownlist with ViewData</h2>
<p>This method is better, and is baked right into MVC. The downside is you can only use it in MVC, and involves using ViewData (detailed <a href="http://weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx" onclick="pageTracker._trackPageview('/outgoing/weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx?referer=');">ViewData definition</a>), the View and the Controller. First we prepare the Controller:</p>
<pre class="brush: csharp; title: ; notranslate">
public ActionResult Index()
{
    Contact[] contacts = Contact.FindAll();
    ViewData[&quot;Contacts&quot;] = new SelectList(contacts,&quot;ID&quot;,&quot;FullName&quot;, &lt;span style=&quot;color:red;&quot;&gt;[Selectedvalue]&lt;/span&gt;);
    return View();
}
</pre>
<p><span style="color:red;">Selectedvalue</span> &#8211; this optional parameter can be used to select a specific value, useful if you are displaying a form in edit mode.</p>
<p>The last part is binding the ViewData contents to a dropdownlist in the View:</p>
<pre class="brush: csharp; title: ; notranslate">
    &lt;%= Html.DropDownList(&quot;Contacts&quot;) %&gt;
</pre>
<h2>Populate dropdownlist with jQuery</h2>
<p>This is the most flexible of the three, and can be used in web forms, php, MVC, etc. This method involves a jquery call in javascript:</p>
<pre class="brush: csharp; title: ; notranslate">
    &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
        $(function() {
            $.getJSON(&quot;YOURPATH/Contact/ContactList&quot;, function(data) {
                var items = &quot;&lt;option selected&gt;&lt;/option&gt;&quot;;
                $.each(data, function(i, item) {
                    items += &quot;&lt;option value='&quot; + item.Value + &quot;'&gt;&quot; + item.Text + &quot;&lt;/option&gt;&quot;;
                });
                $(&quot;#ContactID&quot;).html(items);
        });
    &lt;/script&gt;
</pre>
<p>The above function calls the ContactList method, which returns a ListItem collection. You then loop through the result, and add the options. Finally, the html contents of the dropdownlist are set. The MVC method that returns the contact list looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
        public ActionResult OrganizationList()
        {
            Contact[] contacts = Contact.FindAll();
            if (HttpContext.Request.IsAjaxRequest())
            {
                return Json(new SelectList(contacts, &quot;ID&quot;, &quot;FullName&quot;));
            }
            return View(contacts);
        }
</pre>
<div class="shr-publisher-221"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/dynamically-populate-dropdownlist-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>TinyMCE samples with ASP.NET MVC</title>
		<link>http://www.billsternberger.net/asp-net-mvc/tinymce-samples-with-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/tinymce-samples-with-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:35:30 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[customize tinymce toolbar]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[readonly]]></category>
		<category><![CDATA[TinyMCE]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=210</guid>
		<description><![CDATA[After using Telerik&#8217;s RadEditor control for years with all my asp.net web form applications, I found myself looking for a javascript alternative when I moved up to MVC. Having paid top dollar for RadEditor (which is a fine product!) and never used TinyMCE, I couldn&#8217;t imagine something free could be that good. Well it is! [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Ftinymce-samples-with-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Ftinymce-samples-with-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Ftinymce-samples-with-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>After using Telerik&#8217;s RadEditor control for years with all my asp.net web form applications, I found myself looking for a javascript alternative when I moved up to MVC. Having paid top dollar for RadEditor (which is a fine product!) and never used TinyMCE, I couldn&#8217;t imagine something free could be that good. Well it is! And really easy to use&#8211;whether in c#, vb, php, etc.&#8211;plus no nasty viewstate to bloat your page.</p>
<p><a href="http://bit.ly/cPVNct" onclick="pageTracker._trackPageview('/outgoing/bit.ly/cPVNct?referer=');">You can download code samples here</a>.</p>
<h2>Downloading files</h2>
<p>The first step is visiting the TinyMCE website and downloading the files: <a href="http://tinymce.moxiecode.com/download.php" target="_blank" onclick="pageTracker._trackPageview('/outgoing/tinymce.moxiecode.com/download.php?referer=');">http://tinymce.moxiecode.com/download.php</a>. Make sure you select the &#8220;jQuery package&#8221; link.</p>
<p>Extract the zip file, and copy the actual script files (tinymce\jscripts directory) into a folder in your project. I typically have a scripts folder, and create a &#8220;tiny_mce&#8221; subdirectory to hold the files.</p>
<h2>Setting references</h2>
<p>If you have a master page, just add the following line into the top of the master page:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;&lt;%=Url.Content(&quot;~/scripts/tiny_mce/tiny_mce.js&quot;) %&gt;&quot;&gt;&lt;/script&gt;
</pre>
<p>Otherwise add the same line to the top of each page that will use the TinyMCE editor. Next, you initialize the textareas to use TinyMCE. The following javascript snippet initializes every textarea on the page (or every single page if added in the master page) using the defaults:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;

tinyMCE.init({
mode: &quot;textareas&quot;,
theme: &quot;advanced&quot;
});
</pre>
<p>We will dive deeper into configuring the available buttons.</p>
<h2>Samples</h2>
<h3>TinyMCE in a dialog</h3>
<p>One common need is allowing users to edit text in a modal window. Combining jQuery&#8217;s dialog (<a title="jquery modal dialog without the x button" href="http://www.billsternberger.net/asp-net-mvc/jquery-modal-dialog-without-the-x-button/">http://www.billsternberger.net/asp-net-mvc/jquery-modal-dialog-without-the-x-button/</a>) with TinyMCE is a simple and elegant solution.</p>
<p>First, initialize the dialog and add the click event to show the editor:</p>
<pre class="brush: csharp; title: ; notranslate">
$(function() {
$(&quot;#texteditorform&quot;).dialog({
height: 300,
width: 520,
autoOpen: false
});
});

function ShowModalEditor() {
$(&quot;#texteditorform&quot;).dialog('open');
}
</pre>
<p>Next, add the button to show the editor:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;a onclick=&quot;ShowModalEditor()&quot; href=&quot;#&quot;&gt;Show modal text editor&lt;/a&gt;
</pre>
<p>Next, create the dialog div with the textarea inside:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;div title=&quot;Text Editor&quot; id=&quot;texteditorform&quot;&gt;
Add something below:&lt;br /&gt;
&lt;textarea rows=&quot;5&quot; cols=&quot;25&quot; id=&quot;modalTextarea&quot;&amp;gt;&amp;lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;
&lt;input type=&quot;button&quot; onclick=&quot;CloseModalEditor()&quot; value=&quot;Save&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;
</pre>
<h3>Toggle TinyMCE editor and textarea</h3>
<p>Occasionally you may want to allow users to toggle between the advanced editor and the regular textarea. There is a simple function to pull this off. First, add the javascript function to handle the toggling:</p>
<pre class="brush: csharp; title: ; notranslate">
function toggleEditor(id) {
if (!tinyMCE.get(id)) {
tinyMCE.execCommand('mceAddControl', false, id);
}
else {
tinyMCE.execCommand('mceRemoveControl', false, id);
}
}
</pre>
<p>Next, add a button that will allow the user to toggle:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;a href=&quot;#&quot; onclick=&quot;javascript:toggleEditor('toggleTextarea');&quot;&gt;Toggle&lt;/a&gt;
</pre>
<h3>Validate input value</h3>
<p>To validate the user input of a TinyMCE-enabled editor, the standard jqeuery $(&#8220;#field&#8221;).val() method won&#8217;t work.  Instead, you need to use a TinyMCE method instead:</p>
<pre class="brush: csharp; title: ; notranslate">
var theValue = tinyMCE.get('valueTextarea').getContent();
</pre>
<h3>Make TinyMCE editor Read Only</h3>
<p>Should you need to initialize a TinyMCE editor as readonly, all you have to do is add a line to the init:</p>
<pre class="brush: csharp; title: ; notranslate">
$(function() {
$(&quot;#texteditorform&quot;).dialog({
&lt;span style=&quot;color: #0000ff;&quot;&gt;readonly: true&lt;/span&gt;
});
});
</pre>
<h2>Customize TinyMCE Editor buttons</h2>
<h3>Include underline, copy, paste, and other formatting options in toolbar</h3>
<p>Customizing which buttons appear on the toolbar is really easy, below are some sample configurations. Setting and aligning the buttons are done in theme_advanced properties.</p>
<pre class="brush: csharp; title: ; notranslate">
tinyMCE.init({
mode: &quot;textareas&quot;,
theme: &quot;advanced&quot;,
plugins: &quot;style,iespell,searchreplace,contextmenu,paste,html&quot;,

//  Theme options #1
theme_advanced_buttons1: &quot;bold,italic,underline,formatselect,cut,copy,paste,pastetext,pasteword&quot;,
theme_advanced_buttons2: &quot;fontselect,fontsizeselect,|,link,unlink,code&quot;,
theme_advanced_buttons3: &quot;justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist&quot;,
theme_advanced_buttons4: &quot;&quot;,

//Theme options #2
theme_advanced_buttons1: &quot;bold,italic,underline,formatselect,cut,copy,paste,|,fontselect,fontsizeselect&quot;,
theme_advanced_buttons2: &quot;&quot;,

// Align and place toolbar
theme_advanced_toolbar_location: &quot;top&quot;,
theme_advanced_toolbar_align: &quot;left&quot;,
theme_advanced_resizing: true,
readonly: false
});
</pre>
<p>The above are the two standard configurations I use. To view a full list of buttons, <a href="http://tinymce.moxiecode.com/examples/full.php" target="_blank" onclick="pageTracker._trackPageview('/outgoing/tinymce.moxiecode.com/examples/full.php?referer=');">click here</a>.</p>
<div class="shr-publisher-210"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/tinymce-samples-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery Modal Dialog without the x button</title>
		<link>http://www.billsternberger.net/asp-net-mvc/jquery-modal-dialog-without-the-x-button/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/jquery-modal-dialog-without-the-x-button/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 16:56:36 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[guest registration form]]></category>
		<category><![CDATA[jquery modal dialog]]></category>
		<category><![CDATA[remove x from jquery dialog]]></category>

		<guid isPermaLink="false">http://www.billsternberger.net/?p=200</guid>
		<description><![CDATA[Found myself wanting to provide a modal dialog (preferably in jQuery of course!) to gate first-time page visitors. The requirements were: On page load, display modal dialog with a form to request basic contact information Disable the &#8220;esc&#8221; key to force the user to enter the info or click a &#8220;no thanks&#8221; button Hide the [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fjquery-modal-dialog-without-the-x-button%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fjquery-modal-dialog-without-the-x-button%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fjquery-modal-dialog-without-the-x-button%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>Found myself wanting to provide a modal dialog (preferably in jQuery of course!) to gate first-time page visitors. The requirements were:</p>
<ul>
<li>On page load, display modal dialog with a form to request basic contact information</li>
<li>Disable the &#8220;esc&#8221; key to force the user to enter the info or click a &#8220;no thanks&#8221; button</li>
<li>Hide the x which appears in the dialog</li>
</ul>
<p>My approach was using the jQuery dialog, $.post to send the contact information to my controller and then hide the modal dialog. We can do this in three easy steps:</p>
<h2>Configure jQuery dialog</h2>
<p>The jQuery dialog has some nifty properties out of the box to handle things like, disabling the esc key, displaying the modal dialog on page load, along with the usual suspects: style, size, resizing. Here is what my call looks like, with our special properties highlighted in blue:</p>
<pre class="brush: csharp; title: ; notranslate">
$(function() {
$(&quot;#registrationform&quot;).dialog({
height: 470,
width: 520,
resizable: false,
&lt;span style=&quot;color: #0000ff;&quot;&gt;autoOpen&lt;/span&gt;: true,
&lt;span style=&quot;color: #0000ff;&quot;&gt;modal&lt;/span&gt;: true,
&lt;span style=&quot;color: #0000ff;&quot;&gt;closeOnEscape&lt;/span&gt;: false
});
});
1

&lt;h2&gt;Hide the dialog's x button&lt;/h2&gt;
The dialog shows a x in the top right corner by default, and there are no properties to hide it. The best way I found is using some old fashioned CSS:

1
&lt;style&gt;
.ui-dialog .ui-dialog-titlebar-close { display: none; }
&lt;/style&gt;
</pre>
<p>So that is all it takes to set the dialog to display on page load and prevent users from escaping out or closing the form. Next is sending the results back to the server, which is pretty simple using $.post.</p>
<h2>Post back to the server and process results</h2>
<p>First, you need to handle a button&#8217;s click event, and have some logic to process the result. I primarily develop in ASP.NET MVC, but you could very easily use this technique in PHP, Ruby, etc. Here is the function:</p>
<pre class="brush: csharp; title: ; notranslate">
function Register() {
$.post(&quot;/Contact/RegisterGuest&quot;,
{
FirstName: $(&quot;#FirstName&quot;).val(),
LastName: $(&quot;#LastName&quot;).val(),
Email: $(&quot;#Email&quot;).val(),
Phone: $(&quot;#Phone&quot;).val()
},
function(data) {
Result = eval('(' + data + ')');

if (Result == &quot;&quot;) {
$('#registrationform').dialog('close');
$(&quot;#registrationform&quot;).hide(&quot;fast&quot;);
$(&quot;#result&quot;).show(&quot;fast&quot;);
}
else {
$(&quot;#errorblock&quot;).html(&quot;&lt;ul&gt;&quot; + Result + &quot;&lt;/u&gt;&quot;);
}
});
}
</pre>
<p>Breaking down the function, we&#8217;re posting to the RegisterGuest method for the Contact controller, with the FirstName, LastName, Email, and Phone fields, and processing the result. Typically I&#8217;ll return any errors in listitem tags, so an empty Result means no errors occurred on the server-side. If the Result variable is empty, we hide the dialog and show whatever was hidden. Otherwise we set the html value for a pre-defined div to be the error list.</p>
<div class="shr-publisher-200"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/jquery-modal-dialog-without-the-x-button/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use jQuery to change a form&#8217;s action url</title>
		<link>http://www.billsternberger.net/asp-net-mvc/use-jquery-to-change-a-forms-action-url/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/use-jquery-to-change-a-forms-action-url/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 21:43:29 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[form action url]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=198</guid>
		<description><![CDATA[This is another quick and dirty post, more for future reference when I need to access this snippet again! The scenario is if you have one form on a page, but want to change the target on the fly for whatever reason. Here are the two magical lines:]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fuse-jquery-to-change-a-forms-action-url%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fuse-jquery-to-change-a-forms-action-url%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fuse-jquery-to-change-a-forms-action-url%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This is another quick and dirty post, more for future reference when I need to access this snippet again! The scenario is if you have one form on a page, but want to change the target on the fly for whatever reason. Here are the two magical lines:</p>
<pre class="brush: csharp; title: ; notranslate">
$(&quot;form&quot;).attr(&quot;action&quot;, &quot;/ControllerName/Method&quot;);
$(&quot;form&quot;).submit();
</pre>
<div class="shr-publisher-198"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/use-jquery-to-change-a-forms-action-url/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Export to Excel or CSV from ASP.NET MVC with C#</title>
		<link>http://www.billsternberger.net/asp-net-mvc/export-to-excel-or-csv-from-asp-net-mvc-with-c/</link>
		<comments>http://www.billsternberger.net/asp-net-mvc/export-to-excel-or-csv-from-asp-net-mvc-with-c/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 20:45:38 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[c# csv]]></category>
		<category><![CDATA[Export to Excel]]></category>
		<category><![CDATA[nhibernate excel export]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=196</guid>
		<description><![CDATA[Since programming way back in the Classic ASP days, at some point a client always wants to export an html grid into an Excel grid. In c#, that need didn&#8217;t disappear, but got a lot easier with GridView and the HtmlTextWriter. Finally reached that point in my ASP.NET MVC programming world, and quite frankly, am [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fexport-to-excel-or-csv-from-asp-net-mvc-with-c%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fexport-to-excel-or-csv-from-asp-net-mvc-with-c%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fasp-net-mvc%2Fexport-to-excel-or-csv-from-asp-net-mvc-with-c%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>Since programming way back in the Classic ASP days, at some point a client always wants to export an html grid into an Excel grid. In c#, that need didn&#8217;t disappear, but got a lot easier with GridView and the HtmlTextWriter. Finally reached that point in my ASP.NET MVC programming world, and quite frankly, am surprised it took this long, for this same need! But I digress. To pull this off, all we are really going to do is add an export method to a controller, most of which will look very familiar to asp.net web forms.</p>
<h2>Add using statements</h2>
<p><code>using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.IO;</code></p>
<p>We are going to use our dear old friend the GridView from web forms as a placeholder for our data, which is why we need the second using statement.</p>
<h2>Create Controller Method</h2>
<p>This one is pretty easy, consisting of three parts:</p>
<ul>
<li>Creating the GridView placeholder</li>
<li>Binding the query results to the GridView placeholder</li>
<li>Dumping the results back to the browser</li>
</ul>
<p>This example queries all contacts that have not unsubscribed, but you can imagine how easy it is to extend.<br />
<code>var contacts = Contact.FindAll();<br />
var grid = new System.Web.UI.WebControls.GridView();</p>
<p>grid.DataSource = from contact in contacts<br />
where contact.Unsubscribe == false<br />
select new<br />
{<br />
ContactID = contact.ID,<br />
FullName = contact.FullName,<br />
Email = contact.Email<br />
};<br />
grid.DataBind();</p>
<p>Response.ClearContent();<br />
Response.AddHeader("content-disposition", "attachment; filename=YourFileName.xls");<br />
Response.ContentType = "application/excel";<br />
StringWriter sw = new StringWriter();<br />
HtmlTextWriter htw = new HtmlTextWriter(sw);<br />
grid.RenderControl(htw);<br />
Response.Write(sw.ToString());<br />
Response.End();</code></p>
<p>That&#8217;s it!</p>
<div class="shr-publisher-196"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/asp-net-mvc/export-to-excel-or-csv-from-asp-net-mvc-with-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Import CSV file to MySQL</title>
		<link>http://www.billsternberger.net/mysql/import-csv-file-to-mysql/</link>
		<comments>http://www.billsternberger.net/mysql/import-csv-file-to-mysql/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 16:10:22 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[asp.net mvc c# nhibernate import excel]]></category>
		<category><![CDATA[asp.net mvc import csv]]></category>
		<category><![CDATA[c# load csv]]></category>
		<category><![CDATA[CSV Import]]></category>
		<category><![CDATA[import csv file to mysql]]></category>
		<category><![CDATA[MySQL Query Browser]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=165</guid>
		<description><![CDATA[Importing data into one of your MySQL tables is really easy using the Load Data command. In this exercise we will look at importing a comma separated list of countries into our Country table. Below is the script you would run in your MySQL Query Browser (or phpMyAdmin tool): Now we&#8217;ll break down a couple [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fmysql%2Fimport-csv-file-to-mysql%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fmysql%2Fimport-csv-file-to-mysql%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fmysql%2Fimport-csv-file-to-mysql%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>Importing data into one of your MySQL tables is really easy using the Load Data command. In this exercise we will look at importing a comma separated list of countries into our Country table. Below is the script you would run in your MySQL Query Browser (or phpMyAdmin tool):</p>
<pre class="brush: sql; title: ; notranslate">
LOAD DATA LOCAL INFILE '&lt;span style=&quot;color: #0000ff;&quot;&gt;c:/samples/countrylist.csv&lt;/span&gt;'
INTO TABLE &lt;span style=&quot;color: #0000ff;&quot;&gt;Country
&lt;span style=&quot;color: #000000;&quot;&gt;IGNORE 1 LINES&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;/code&gt;
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(&lt;span style=&quot;color: #0000ff;&quot;&gt;Value,    Description,    ActiveFlag,    SequenceID&lt;/span&gt;);
</pre>
<p>Now we&#8217;ll break down a couple of the lines above in more detail.</p>
<h3>LOAD DATA LOCAL INFILE</h3>
<p>The Load Data Infile statement loads in rows from your text file into the table specified in the next line (INTO TABLE). Above you&#8217;ll notice I inlcuded the LOCAL option. This means the file will be read locally from your PC, and you have two additional options for identifying the location:</p>
<ol>
<li>Full Path &#8211; include the entire path including the file name, but instead of using a backslash, use a forward slash (like above).</li>
<li>Relative Path &#8211; just include the file name. Note: make sure the .csv file is in the same directory as your MySQL Query Browser.</li>
</ol>
<p>If you do not include the LOCAL option, then the .csv file must be on the server. Like the LOCAL option, if you include the full path, it is pretty simple, the specified path must exist on the server. If you use the relative path, the plot thickens. There are two ways to identify the location:</p>
<ol>
<li>./countrylist.csv &#8211; the leading ./ is treated as a reference to the server&#8217;s data directory.</li>
<li>countrylist.csv &#8211; is read from the default database&#8217;s directory. What that means is if your default database is called PrimaryDatabase, and you want to upload the countrylist.csv file into a database called CountryDatabase (yeah, I know the sample names are lame!), you would have to modify the INTO statement like this:
<p>INTO TABLE CountryDatabase.Country</li>
</ol>
<h3>IGNORE 1 LINES</h3>
<p>This statement is typically used when you have a header record, if you have no header, you can leave it out.</p>
<h3>FIELDS TERMINATED BY</h3>
<p>This is the character that delimits each field. In the code snippet above, I&#8217;m using a comma. If you had a tab-delimited file, you would use &#8216;\t&#8217; instead of the comma.</p>
<h3>LINES TERMINATED BY</h3>
<p>The TERMINATED BY portion is one of two options, and happens to be the option I always happen to take. This specifies the row delimiter. By default, it is the standard \n, although you could use \r\n. If you don&#8217;t specify TERMINATED BY, you and specify STARTING BY. What this does is allows you to prefix any row with a string of characters. For example, you could have the following statement:</p>
<blockquote><p>LINES STARTED BY &#8216;pre_&#8217;</p></blockquote>
<p>And then three rows of data that looks like this:</p>
<blockquote><p>pre_&#8221;Joe&#8221;,&#8221;Smith&#8221;,1<br />
pre_&#8221;Keith&#8221;,&#8221;Booth&#8221;,2<br />
&#8220;Gary&#8221;,&#8221;Williams&#8221;,3</p></blockquote>
<p>Only the first two rows would import because they have the pre_ STARTED BY prefix.</p>
<p>The last line is the list of fields . If you leave out that line, your file is expected to have a field for each column in the target table. If you are only importing a subset of the columns, then you need to specify the columns so the importer can properly map the data.</p>
<div class="shr-publisher-165"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/mysql/import-csv-file-to-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft and Google jQuery CDN Link</title>
		<link>http://www.billsternberger.net/jquery/microsoft-and-google-jquery-cdn-link/</link>
		<comments>http://www.billsternberger.net/jquery/microsoft-and-google-jquery-cdn-link/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:43:14 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[Content Delivery Network]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=162</guid>
		<description><![CDATA[So what is a Content Delivery Network (CDN)? In a nutshell, a CDN is a network of computers strategically placed around the world that serve up cached content to users. The content types include images, videos, style sheets, and in this case,  script libraries. As you can imagine, your pages will load faster when browsers [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fmicrosoft-and-google-jquery-cdn-link%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fmicrosoft-and-google-jquery-cdn-link%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fmicrosoft-and-google-jquery-cdn-link%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>So what is a Content Delivery Network (CDN)?</p>
<p>In a nutshell, a CDN is a network of computers strategically placed around the world that serve up cached content to users. The content types include images, videos, style sheets, and in this case,  script libraries. As you can imagine, your pages will load faster when browsers are downloading these objects from a server closer to them than from one central location half way across the globe.</p>
<p>When it comes to jquery, there are two main CDNs I&#8217;ll reference in projects: Microsoft&#8217;s and Google&#8217;s. Adding a reference to either CDN is really easy. All you have to do is add one of the following lines into your page header.</p>
<p>Microsoft&#8217;s jQuery CDN reference:</p>
<blockquote><p>&lt;script src=&#8221;http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>Google&#8217;s jQuery CDN reference:</p>
<blockquote><p>&lt;script src=&#8221;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>That&#8217;s it!</p>
<div class="shr-publisher-162"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/jquery/microsoft-and-google-jquery-cdn-link/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ActiveRecord ICriterion Search Example (c#)</title>
		<link>http://www.billsternberger.net/nhibernate/activerecord-icriterion-search-example-c/</link>
		<comments>http://www.billsternberger.net/nhibernate/activerecord-icriterion-search-example-c/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 05:07:22 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ICriterion]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=152</guid>
		<description><![CDATA[In this post we are going to search using ICriterion to filter and sort the results. The only pre-requisite is that you properly configure your nHibernate environment, and like all my other code samples, know c#. This one is pretty easy, first we are going to set the required references: Then we are going to [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fnhibernate%2Factiverecord-icriterion-search-example-c%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fnhibernate%2Factiverecord-icriterion-search-example-c%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fnhibernate%2Factiverecord-icriterion-search-example-c%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>In this post we are going to search using ICriterion to filter and sort the results. The only pre-requisite is that you properly <a href="http://billsternberger.net/2009/12/using-nhibernate-castle-activerecord-and-asp-net-mvc-together/" onclick="pageTracker._trackPageview('/outgoing/billsternberger.net/2009/12/using-nhibernate-castle-activerecord-and-asp-net-mvc-together/?referer=');">configure your nHibernate environment</a>, and like all my other code samples, know c#.</p>
<p>This one is pretty easy, first we are going to set the required references:</p>
<pre class="brush: csharp; title: ; toolbar: false; notranslate">
using NHibernate;
using NHibernate.Criterion;
</pre>
<p>Then we are going to define the ICriterion array. In this example, were are going to search for contacts that:</p>
<ul>
<li>Belonging to the logged on owner (OwnerID variable).</li>
<li>LastName starts with some string entered by the user (LastNameValue variable)</li>
<li>Were added after a specific date chosen by the user (StartDate variable)</li>
</ul>
<p>For the LastName like search, nHibernate gives us some options in the MatchMode enum: Anywhere, End, Exact, Start. In the snippet below, you will notice I went with Start.</p>
<p>Finally, we are going to sort the results by LastName, then FirstName.</p>
<pre class="brush: csharp; title: ; notranslate">
ICriterion[] query = {
Expression.Eq(&quot;OwnerID&quot;, OwnerID),
Expression.Like(&quot;LastName&quot;,LastNameValue,MatchMode.Start),
Expression.Ge(&quot;CreationDate&quot;,StartDate) };

Order[] order = {
Order.Asc(&quot;LastName&quot;),
Order.Asc(&quot;FirstName&quot;)};

Contact[] results = contact.FindAll(order, query);
</pre>
<p>That&#8217;s it!</p>
<p>Related articles:</p>
<ul>
<li>Performing an <a href="../2009/12/nhibernate-icriterion-query-wc/">ActiveRecord SimpleQuery</a> search</li>
</ul>
<div class="shr-publisher-152"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/nhibernate/activerecord-icriterion-search-example-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 jQuery Functions and Plugins (Part II)</title>
		<link>http://www.billsternberger.net/jquery/top-10-jquery-functions-and-plugins-part-ii/</link>
		<comments>http://www.billsternberger.net/jquery/top-10-jquery-functions-and-plugins-part-ii/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 04:37:17 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[$.post]]></category>
		<category><![CDATA[curvycorners]]></category>
		<category><![CDATA[lightbox]]></category>
		<category><![CDATA[Top 10]]></category>
		<category><![CDATA[watermark]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=125</guid>
		<description><![CDATA[The following is the second part of a set of jQuery shortcuts I use at some point on a daily basis. If you missed part I, you can see them here. 5. Lightbox 2 Why do I like this? It is simple to integrate and very elegant looking. Need to group images together so the [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Ftop-10-jquery-functions-and-plugins-part-ii%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Ftop-10-jquery-functions-and-plugins-part-ii%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Ftop-10-jquery-functions-and-plugins-part-ii%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>The following is the second part of a set of jQuery shortcuts I use at some point on a daily basis. If you missed part I, you can see them <a title="Top 10 jQuery Functions and Plugins (Part I)" href="http://billsternberger.net/2010/01/top-10-jquery-functions-and-plugins/" target="_self" onclick="pageTracker._trackPageview('/outgoing/billsternberger.net/2010/01/top-10-jquery-functions-and-plugins/?referer=');">here</a>.</p>
<p>5. Lightbox 2</p>
<p>Why do I like this? It is simple to integrate and very elegant looking. Need to group images together so the user can page through a gallery? No problem! adding a rel= lightbox tag to any pictures on a page automatically groups the images instantly.</p>
<p>Read more here: <a href="http://www.lokeshdhakar.com/projects/lightbox2/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.lokeshdhakar.com/projects/lightbox2/?referer=');">http://www.lokeshdhakar.com/projects/lightbox2/</a></p>
<p>4. $.post</p>
<p>$.post is another powerful function that allows you to do a http post to the server and get back a response which you can then parse and do something with. You can check out my <a href="http://billsternberger.net/2010/01/auto-complete-using-mvc-jquery/" onclick="pageTracker._trackPageview('/outgoing/billsternberger.net/2010/01/auto-complete-using-mvc-jquery/?referer=');">$.post example</a> where I use $.post in conjunction with MVC and a JsonResult.</p>
<p>Read more here: <a href="http://docs.jquery.com/Ajax/jQuery.post" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.jquery.com/Ajax/jQuery.post?referer=');">http://docs.jquery.com/Ajax/jQuery.post</a></p>
<p>3. Watermark</p>
<p>The old <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/TextBoxWatermark/TextBoxWatermark.aspx" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.asp.net/AJAX/AjaxControlToolkit/Samples/TextBoxWatermark/TextBoxWatermark.aspx?referer=');">AJAX Control Toolkit</a> had a decent textbox watermark control, but when I moved from WebForms to MVC, wanted to find a better jQuery solution. This plugin is simply awesome. It covers everything from your basic textbox watermark to multi-line watermarks for textareas to dynamic watermarks to WebKit support.</p>
<p>Read more here: <a href="http://code.google.com/p/jquery-watermark/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jquery-watermark/?referer=');">http://code.google.com/p/jquery-watermark<br />
</a></p>
<p>2. Curvycorners</p>
<p>This is more for style, it helps out programmers like me that can make things look &#8220;not ugly&#8221; and that&#8217;s about it. Using some good old-fashioned javascript, you can turn a boring div into a sleek looking table.</p>
<p>Read more here: <a href="http://www.curvycorners.net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.curvycorners.net/?referer=');">http://www.curvycorners.net/</a></p>
<p>1. Dialog</p>
<p>This awesome wrapper can be found on the jquery.com website in their UI section. You can style and customize a dialog/popup to autoopen when the page loads, display modal, close on escape, allow resizing, etc. It seems that every application I develop needs some type of advanced confirm box, and the dialog always bails me out. A more advanced use of the dialog can be in conjunction with an html table to perform a quick edit for a grid, which will be the subject of a future post.</p>
<p>Read more here: <a href="http://jqueryui.com/demos/dialog/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/jqueryui.com/demos/dialog/?referer=');">http://jqueryui.com/demos/dialog/</a></p>
<p>Hope you found this post useful! If there are any others you like feel free to share below.</p>
<div class="shr-publisher-125"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/jquery/top-10-jquery-functions-and-plugins-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codesmith Templates for nHibernate and ASP.NET MVC</title>
		<link>http://www.billsternberger.net/activerecord/codesmith-templates-for-nhibernate-and-asp-net-mvc/</link>
		<comments>http://www.billsternberger.net/activerecord/codesmith-templates-for-nhibernate-and-asp-net-mvc/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 19:30:31 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Codesmith]]></category>
		<category><![CDATA[.cst]]></category>
		<category><![CDATA[CodeSmith Templates]]></category>
		<category><![CDATA[MVC codesmith c#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=143</guid>
		<description><![CDATA[Reason #52356 I love using Castle&#8217;s ActiveRecord is that CRUD is automatically handled for you, which is a major time saver. I&#8217;m always looking for any edge to speed up the development process or automate redundant tasks, and that little drive led me to Codesmith Tools. What&#8217;s so cool about Codesmith? The fact that once [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Factiverecord%2Fcodesmith-templates-for-nhibernate-and-asp-net-mvc%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Factiverecord%2Fcodesmith-templates-for-nhibernate-and-asp-net-mvc%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Factiverecord%2Fcodesmith-templates-for-nhibernate-and-asp-net-mvc%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>Reason #52356 I love using <a href="http://www.billsternberger.net/category/activerecord/">Castle&#8217;s ActiveRecord</a> is that CRUD is automatically handled for you, which is a major time saver. I&#8217;m always looking for any edge to speed up the development process or automate redundant tasks, and that little drive led me to <a href="http://www.codesmithtools.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.codesmithtools.com/?referer=');">Codesmith Tools</a>. What&#8217;s so cool about Codesmith? The fact that once you define a table &#8212; and all major databases are supported &#8212; clicking a single button can generate your class file, controller methods, stored procedures, or views.</p>
<p>I started using Codesmith with ASP.NET web forms, and when I first migrated to ASP.NET MVC, was unclear how/where to incorporate Codesmith into this new MVC environment. Well it was easier than I thought! Below I&#8217;m going to break down the Codesmith template file (.cst) I use to generate my ActiveRecord classes, which is done in c#:</p>
<h2>Codesmith template references</h2>
<p>The following section appears at the top of the template:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;%@ CodeTemplate Language=&quot;C#&quot; TargetLanguage=&quot;C#&quot; Description=&quot;Generates a very simple business object.&quot; %&gt;
&lt;%@ Property Name=&quot;SourceTable&quot; Type=&quot;SchemaExplorer.TableSchema&quot; Category=&quot;Context&quot; Description=&quot;Table that the object is based on.&quot; %&gt;
&lt;%@ Property Name=&quot;Namespace&quot; Type=&quot;System.String&quot; Default=&quot;&quot; Optional=&quot;False&quot; Category=&quot;MethodInfo&quot; %&gt;
&lt;%@ Assembly Name=&quot;SchemaExplorer&quot; %&gt;
&lt;%@ Assembly Name=&quot;System.Data&quot; %&gt;
&lt;%@ Import Namespace=&quot;SchemaExplorer&quot; %&gt;
&lt;%@ Import Namespace=&quot;System.Data&quot; %&gt;
</pre>
<p>The most important rows to notice are the second and third. The SourceTable property tells Codesmith that you are going to choose a table which the rest of the code will reference. The Namespace property, which is tagged as optional, is simply a property I made up. In the code below, you will see how it is used. It is just a placeholder for the template, and you can have as many as you want.</p>
<h2>Codesmith template</h2>
<p>The next section is the template itself. It will look just like Classic ASP or MVC. In a nutshell, it is a block of text, with Codesmith markup appearing in between <% %> tags.</p>
<p>First we add the using namespaces our c# repository file will need to reference:</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Criterion;
using Castle.ActiveRecord;
</pre>
<p>Since this is an ActiveRecord class, and we use ICriterion for our queries, we include the NHibernate and ActiveRecord references. Next up is our namespace wrapper. You&#8217;ll notice the markup that references the Namespace property at the top of the page:</p>
<pre class="brush: csharp; title: ; notranslate">
namespace &lt;%= Namespace %&gt;
{
</pre>
<p>Whatever you type into the textbox will pop in between the tags. Next up is the real meat: the class definition. You&#8217;ll notice all the ActiveRecord attributes above each property, as well as some methods, and finally the closing } for the namespace:</p>
<pre class="brush: csharp; title: ; notranslate">
[ActiveRecord(&quot;&lt;%= GetClassName(SourceTable) %&gt;&quot;)]
public class &lt;%= GetClassName(SourceTable) %&gt; : ActiveRecordBase&lt;&lt;%= GetClassName(SourceTable) %&gt;&gt;
{
public &lt;%= GetClassName(SourceTable) %&gt;()
{
}

#region Properties
&lt;% for (int i = 0; i &lt; SourceTable.PrimaryKey.MemberColumns.Count; i++) { %&gt;

[PrimaryKey(PrimaryKeyType.Native, &quot;&lt;%= SourceTable.PrimaryKey.MemberColumns[i].Name %&gt;&quot;)]
public &lt;%= GetCSharpVariableType(SourceTable.PrimaryKey.MemberColumns[i]) %&gt; &lt;%= SourceTable.PrimaryKey.MemberColumns[i].Name %&gt; { get; set; }

&lt;% } %&gt;
&lt;% for (int i = 0; i &lt; SourceTable.NonPrimaryKeyColumns.Count; i++) { %&gt;
[Property]
public &lt;%= GetCSharpVariableType(SourceTable.NonPrimaryKeyColumns[i]) %&gt; &lt;%= GetPropertyName(SourceTable.NonPrimaryKeyColumns[i]) %&gt; { get; set; }

&lt;% if (i &lt; SourceTable.NonPrimaryKeyColumns.Count - 1) Response.Write(&quot;\r\n&quot;); %&gt;
&lt;% } %&gt;
#endregion

#region Methods
public static void DeleteAll()
{
DeleteAll( typeof(&lt;%= GetClassName(SourceTable) %&gt;) );
}

public static &lt;%= GetClassName(SourceTable) %&gt;[] Find(ICriterion[] query, Order[] order)
{
return &lt;%= GetClassName(SourceTable) %&gt;.FindAll(order, query);
}
#endregion
}
}
</pre>
<p>The final section is a series of functions used by the template which extracts class names, database column types from the table, etc.:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;script runat=&quot;template&quot;&gt;

public string GetPropertyName(ColumnSchema column)
{
string propertyName = column.Name;

if (propertyName == column.Table.Name + &quot;Name&quot;) return &quot;Name&quot;;
if (propertyName == column.Table.Name + &quot;Description&quot;) return &quot;Description&quot;;

if (propertyName.EndsWith(&quot;TypeCode&quot;)) propertyName = propertyName.Substring(0, propertyName.Length - 4);

return propertyName;
}

public string GetCSharpVariableType(ColumnSchema column)
{
if (column.Name.EndsWith(&quot;TypeCode&quot;)) return column.Name;

switch (column.DataType)
{
case DbType.AnsiString: return &quot;string&quot;;
case DbType.AnsiStringFixedLength: return &quot;string&quot;;
case DbType.Binary: return &quot;byte[]&quot;;
case DbType.Boolean: return &quot;bool&quot;;
case DbType.Byte: return &quot;byte&quot;;
case DbType.Currency: return &quot;decimal&quot;;
case DbType.Date: return &quot;DateTime&quot;;
case DbType.DateTime: return &quot;DateTime&quot;;
case DbType.Decimal: return &quot;decimal&quot;;
case DbType.Double: return &quot;double&quot;;
case DbType.Guid: return &quot;Guid&quot;;
case DbType.Int16: return &quot;short&quot;;
case DbType.Int32: return &quot;int&quot;;
case DbType.Int64: return &quot;long&quot;;
case DbType.Object: return &quot;object&quot;;
case DbType.SByte: return &quot;sbyte&quot;;
case DbType.Single: return &quot;float&quot;;
case DbType.String: return &quot;string&quot;;
case DbType.StringFixedLength: return &quot;string&quot;;
case DbType.Time: return &quot;TimeSpan&quot;;
case DbType.UInt16: return &quot;ushort&quot;;
case DbType.UInt32: return &quot;int&quot;;
case DbType.UInt64: return &quot;ulong&quot;;
case DbType.VarNumeric: return &quot;decimal&quot;;
default:
{
return &quot;__UNKNOWN__&quot; + column.NativeType;
}
}
}

public string GetClassName(TableSchema table)
{
if (table.Name.EndsWith(&quot;s&quot;))
{
return table.Name.Substring(0, table.Name.Length - 1);
}
else
{
return table.Name;
}
}
&lt;/script&gt;
</pre>
<p>When executed, the above code creates your class file, ready for copying and pasting into your project, and fully crud-enabled. A brilliant little feature Codesmith includes is a running counter of how many lines of code it has generated for you, along with the ability to set your hourly rate and however many lines of code you can manually generate per hour, so you can see your ROI.</p>
<div class="shr-publisher-143"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/activerecord/codesmith-templates-for-nhibernate-and-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamically Changing the iframe src in jQuery</title>
		<link>http://www.billsternberger.net/jquery/dynamically-changing-the-iframe-src-in-jquery/</link>
		<comments>http://www.billsternberger.net/jquery/dynamically-changing-the-iframe-src-in-jquery/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 23:22:08 +0000</pubDate>
		<dc:creator>bill sternberger</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://billsternberger.net/?p=138</guid>
		<description><![CDATA[This little function allows you to dynamically change the content of an iframe, using jQuery and javascript. It is perfect if you have a single page where you want to preview other websites without navigating away. To pull this off, you need a textbox, a link, and an iframe: Next we add the javascript: And [...]]]></description>
			<content:encoded><![CDATA[<!-- Start LikeButtonSetTop --><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-changing-the-iframe-src-in-jquery%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-changing-the-iframe-src-in-jquery%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fwww.billsternberger.net%2Fjquery%2Fdynamically-changing-the-iframe-src-in-jquery%2F'></a></div><div style="clear: both; min-height: 1px; height: 2px; width: 100%;"></div><!-- End LikeButtonSetTop --><p>This little function allows you to dynamically change the content of an iframe, using jQuery and javascript. It is perfect if you have a single page where you want to preview other websites without navigating away. To pull this off, you need a textbox, a link, and an iframe:</p>
<pre class="brush: csharp; title: ; notranslate">
Enter website url below:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;http://www.google.com&quot; name=&quot;ifrmSite&quot; id=&quot;ifrmsite&quot;/&gt; &lt;a href=&quot;#&quot; onclick=&quot;Navigate()&quot;&gt;Navigate&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;iframe name=&quot;iframe1&quot; id=&quot;iframe1&quot; src=&quot;http://www.google.com&quot; width=&quot;600&quot; height=&quot;700&quot; scrolling=&quot;auto&quot;&gt;
&lt;/iframe&gt;
</pre>
<p>Next we add the javascript:</p>
<pre class="brush: csharp; title: ; notranslate">
function Navigate() {
var newurl = $('#ifrmSite').val();
$('#iframe1').attr('src', newurl);
window.frames[&quot;iframe1&quot;].location.reload();
}
</pre>
<p>And we&#8217;re done!</p>
<div class="shr-publisher-138"></div><!-- Start LikeButtonSetBottom --><!-- End LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.billsternberger.net/jquery/dynamically-changing-the-iframe-src-in-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

