<?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>Dot Net Thoughts &#187; JQuery</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Image cropping in ASP.Net with JQuery</title>
		<link>http://www.dotnetthoughts.net/2009/12/07/image-cropping-in-asp-net-with-jquery/</link>
		<comments>http://www.dotnetthoughts.net/2009/12/07/image-cropping-in-asp-net-with-jquery/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:29:02 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=655</guid>
		<description><![CDATA[Yesterday I got a chance to explore Jcrop &#8211; the jQuery Image Cropping Plugin. You can get more details about JCrop from here. It is nice JQuery plugin to Crop photos. Here is a simple implementation of JCrop with ASP.Net and C#, which will upload a File to webserver, allows the user to crop and [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I got a chance to explore Jcrop &#8211; the jQuery Image Cropping Plugin. You can get more details about JCrop from <a href="http://deepliquid.com/content/Jcrop.html" target="_blank" >here</a>. It is nice JQuery plugin to Crop photos. Here is a simple implementation of JCrop with ASP.Net and C#, which will upload a File to webserver, allows the user to crop and save it back to the server. <em>This is POC code. Make sure you validate all the inputs from end users.</em></p>
<p>Implementation</p>
<p>For the implementation first download the JQuery plugin from the  <a href="http://deepliquid.com/content/Jcrop_Download.html" target="_blank">deepliquid download page</a>. Extact it. Open the JS folder, and add reference of the scripts (jquery.Jcrop.min.js and jquery.min.js) files to the web application. Also Open the CSS folder and link the style sheet (jquery.Jcrop.css) to the ASPX Page. I am using Hidden fields to get the width, height, X, and Y values from the JCrop. </p>
<pre class="brush: jscript;">
function crop() {
    jQuery(function() {
        jQuery('#&lt;%= PicCropImage.ClientID %&gt;').Jcrop({
            onSelect: updateValues, //this function will be invoked when the user completes his selection
            aspectRatio: 1  //Setting aspectRatio: 1 will allow user to draw rectangle with aspectratio.
        });
    });
    //Updating the values of the Hidden fields from the output of crop.
    function updateValues(img) {
        document.getElementById('&lt;%= positionx.ClientID %&gt;').value = img.x;
        document.getElementById('&lt;%= positiony.ClientID %&gt;').value = img.y;
        document.getElementById('&lt;%= positionx1.ClientID %&gt;').value = img.x2;
        document.getElementById('&lt;%= positiony1.ClientID %&gt;').value = img.y2;
        document.getElementById('&lt;%= sizew.ClientID %&gt;').value = img.w;
        document.getElementById('&lt;%= sizeh.ClientID %&gt;').value = img.h;
    }
}
</pre>
<p>And in the server side I am taking the values from the Hidden fields and drawing a new image using the values and saving it in the File System.</p>
<pre class="brush: csharp;">

//Getting the Filename of the Image displayed.
string fileName = Server.MapPath(this.PicCropImage.ImageUrl);
using (Bitmap sourceImage = new Bitmap(fileName, true))
{
    Rectangle destinationArea = new Rectangle(0, 0,
        int.Parse(this.sizew.Value), int.Parse(this.sizeh.Value));
    Rectangle sourceArea =
        new Rectangle(int.Parse(this.positionx.Value), int.Parse(this.positiony.Value),
        int.Parse(this.sizew.Value), int.Parse(this.sizeh.Value));
    using (Bitmap newBitmapImage = new Bitmap(destinationArea.Right, destinationArea.Bottom))
    {
        using (Graphics graphicsImage = Graphics.FromImage(newBitmapImage))
        {
            //Setting the Graphics properties
            graphicsImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphicsImage.CompositingQuality = CompositingQuality.HighQuality;
            graphicsImage.SmoothingMode = SmoothingMode.HighQuality;
            graphicsImage.DrawImage(sourceImage, destinationArea, sourceArea, GraphicsUnit.Pixel);
            IntPtr hbitMap = newBitmapImage.GetHbitmap();
            using (Image image = Image.FromHbitmap(hbitMap))
            {
                //Saving the Image to file system.
                image.Save(Path.Combine(Path.GetDirectoryName(fileName),
                    string.Concat(&quot;Cropped_&quot;, Path.GetFileName(fileName))), ImageFormat.Jpeg);
            }
        }
    }
}
</pre>
<p>Thats it. You are ready for cropping with JCrop and ASP.Net.<br />
Happy Cropping <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/12/07/image-cropping-in-asp-net-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple AutoSuggest Textbox using JQuery</title>
		<link>http://www.dotnetthoughts.net/2009/04/20/simple-autosuggest-textbox-using-jquery/</link>
		<comments>http://www.dotnetthoughts.net/2009/04/20/simple-autosuggest-textbox-using-jquery/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 08:02:54 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[AutoSuggest]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery AutoSuggest]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=262</guid>
		<description><![CDATA[Few months back, one of my colleague from UI team, introduced JQuery to me, our purpose was to show some nice dialog boxes using JQuery. After some time I moved in to some Windows projects. And now I am back in web development, few days back I got a task to implement a Auto suggest [...]]]></description>
			<content:encoded><![CDATA[<p>Few months back, one of my colleague from UI team, introduced JQuery to me, our purpose was to show some nice dialog boxes using JQuery. After some time I moved in to some Windows projects. And now I am back in web development, few days back I got a task to implement a Auto suggest textbox for US Cities. Initialy I was planning to implement it via ASP.Net AJAX, then I thought about simple<br />
implementations. After some googling I found one solution, I modified the code slightly, and implemented it in a Custom user control.</p>
<p>Here is the C# custom control (AutoSuggestTextBox) code.</p>
<pre class="brush: csharp;">

[DefaultProperty(&quot;Text&quot;)]
[ToolboxData(&quot;&lt;{0}:AutoSuggestTextBox runat=server&gt;&lt;/{0}:AutoSuggestTextBox&gt;&quot;)]
public class AutoSuggestTextBox : WebControl
{
protected override void RenderContents(HtmlTextWriter output)
output.WriteLine(&quot;&lt;script type=\&quot;text/javascript\&quot;&gt;&quot;);
output.WriteLine(&quot;$().ready(function() {&quot;);
output.WriteLine(string.Format(&quot;$(\&quot;#{0}TextControl\&quot;).autocomplete(\&quot;{0}.ashx\&quot;);&quot;, this.ID));
output.WriteLine(&quot;});&lt;/script&gt;&quot;);
output.WriteLine(string.Format(&quot;&lt;input type=\&quot;text\&quot; id=\&quot;{0}TextControl\&quot; name=\&quot;{0}TextControl\&quot; /&gt;&quot;, this.ID));
}
}
</pre>
<p>In the implementation, I need to give the output from the database as string, so I implemented the code in a asp.net handler(ASHX) file. And in the ProcessRequest method, I wrote the following code.</p>
<pre class="brush: csharp;">
if (!string.IsNullOrEmpty(context.Request.QueryString[&quot;q&quot;])) // remember, 'q' is the query the autosuggest will pass
        {
            SqlDataReader reader;
            string query = string.Format(&quot;SELECT [CityName] FROM [City] WHERE [CityName] LIKE '%{0}'&quot;, context.Request.QueryString[&quot;q&quot;].ToString());
            using (SqlConnection connection = new SqlConnection(&quot;Server=mydbserver; User Id=sa;Password=mypassword;Database=mylookups;&quot;))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        context.Response.Write(reader[&quot;CityName&quot;].ToString() + Environment.NewLine);
                    }
                    reader.Close();
                }
                connection.Close();
            }
        }
</pre>
<p>Note: I am not promising the above code is optimised. [:)]</p>
<p>And the ASPX Page you need to add reference to following JS Files and Style.</p>
<pre class="brush: xml;">
    &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;jquery.autocomplete.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        .ac_odd {background:#dddddd;}
        .ac_results { padding: 0px; border: 1px solid black; background-color: white; overflow: hidden; z-index: 99999; }
        .ac_results ul { width: 100%; list-style-position: outside; list-style: none; padding: 0; margin: 0; }
        .ac_results li { margin: 0px; padding: 2px 5px; cursor: default; display: block; font: menu; font-size:12px; line-height: 16px; overflow: hidden; }
        .ac_loading { background:url(loading.jpg) right no-repeat; }
        .ac_over { background-color: #0A246A; color: white; }
    &lt;/style&gt;
</pre>
<p>We have completed almost everything, then compile the project, drag the Custom control from toolbox to ASPX page, where you refering the JS Files and CSS. The ASHX File name should be the name of the control. Like if the control&#8217;s name is AutoSuggestCity, the ASHX Filename should be AutoSuggestCity.ashx. Please modify the control code if you want to change it.</p>
<p>After running you will get a Textbox, type something there, you will get the suggestions. Here is the one I got.</p>
<p><a href="http://anuraj.files.wordpress.com/2009/04/autosuggest.jpg"><img src="http://anuraj.files.wordpress.com/2009/04/autosuggest.jpg" alt="autosuggest" title="autosuggest" width="239" height="267" class="alignnone size-full wp-image-265" /></a></p>
<p>You can download JQuery from JQuery website. &#8211; <a href="http://www.jquery.com" target="_blank">www.jquery.com</a>. And autosuggest plugin from <a href="http://plugins.jquery.com/project/autocompletex" target="_blank">AutoSuggest plugin</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/04/20/simple-autosuggest-textbox-using-jquery/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
