<?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>Codepolice.net &#187; C#</title>
	<atom:link href="http://codepolice.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://codepolice.net</link>
	<description>C#, ASP.NET, MVC, LINQ, Wordpress and stuff like that</description>
	<lastBuildDate>Mon, 26 Jul 2010 08:58:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Create a comma separated list with LINQ in C#</title>
		<link>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/</link>
		<comments>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:29:59 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=274</guid>
		<description><![CDATA[For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again. string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())]]></description>
			<content:encoded><![CDATA[<p>For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again.</p>
<pre class="brush:c#">string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())</pre>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert String Array to Int Array and vice versa in C#</title>
		<link>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/</link>
		<comments>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 15:35:17 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[int array]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string array]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=181</guid>
		<description><![CDATA[Sometimes you want to convert arrays back and forth. This is to nice extension methods to convert a int array into a string array and vice versa. public static class ExtensionMethods { public static string[] ToStringArray(this int[] intArray) { return Array.ConvertAll&#60;int, string&#62;(intArray, delegate(int intParameter) { return intParameter.ToString(); }); } public static int[] ToIntArray(this string[] strArray) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to convert arrays back and forth. This is to nice extension methods to convert a int array into a string array and vice versa.</p>
<pre class="brush:c#">public static class ExtensionMethods {

  public static string[] ToStringArray(this int[] intArray) {
   return Array.ConvertAll&lt;int, string&gt;(intArray, delegate(int intParameter) { return intParameter.ToString(); });
  }

  public static int[] ToIntArray(this string[] strArray) {
   return Array.ConvertAll&lt;string, int&gt;(strArray, delegate(string intParameter) { return int.Parse(intParameter.ToString()); });
  }
}</pre>

]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>file_get_contents() in asp.net/C#</title>
		<link>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/</link>
		<comments>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 11:25:59 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[file_get_contents()]]></category>
		<category><![CDATA[StreamReader]]></category>
		<category><![CDATA[WebRequest]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=137</guid>
		<description><![CDATA[The URL shortening service http://bit.ly has a really simple and convient API that lets just get a short url like this. http://bit.ly/api?url=http://www.myreallylong.com/url/with/lots?of=crap I&#8217;ve used this in a wordpress installation with PHP before and there i could just do. $twitter_url .= file_get_contents&#40;'http://bit.ly/api?url=' . get_permalink&#40;&#41;&#41;; Simple and clean. But today i wanted to do the same thing [...]]]></description>
			<content:encoded><![CDATA[<p>The URL shortening service http://bit.ly has a really simple and convient API that lets just get a short url like this.</p>
<p>http://bit.ly/api?url=http://www.myreallylong.com/url/with/lots?of=crap</p>
<p>I&#8217;ve used this in a wordpress installation with PHP before and there i could just do.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$twitter_url</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://bit.ly/api?url='</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Simple and clean. But today i wanted to do the same thing with asp.net and found myself kind of lost. At last i came up with this, not as simple solution. But it works.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">string</span> shortUrl <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #008000;">&#40;</span>WebRequest<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;http://bit.ly/api?url=http://fragor.ohsohightech.se&quot;</span> <span style="color: #008000;">+</span> Url<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Question&quot;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span> number <span style="color: #008000;">=</span> question<span style="color: #008000;">.</span><span style="color: #0000FF;">Number</span>, title <span style="color: #008000;">=</span> question<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertTextToUrl</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponseStream</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>

]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Group By with LINQ</title>
		<link>http://codepolice.net/2008/11/24/linq-group-by/</link>
		<comments>http://codepolice.net/2008/11/24/linq-group-by/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 12:16:58 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Group By]]></category>
		<category><![CDATA[Linq to entities]]></category>
		<category><![CDATA[Linq to sql]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=64</guid>
		<description><![CDATA[Today i wanted to do a group by query with LINQ wich is something i never done before. I turned out to be kind of easy. If you just want to group by a single field. &#40;from s in db.CrewStatsSet where s.LogDate &#38;gt;= date1 &#38;amp;&#38;amp; s.LogDate &#38;lt;= date2 &#38;amp;&#38;amp; s.Action == action group s by [...]]]></description>
			<content:encoded><![CDATA[<p>Today i wanted to do a group by query with LINQ wich is something i never done before. I turned out to be kind of easy.</p>
<p>If you just want to group by a single field.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> s <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">CrewStatsSet</span><br />
<span style="color: #0600FF; font-weight: bold;">where</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;=</span> date1 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> date2 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span> <span style="color: #008000;">==</span> action<br />
group s by s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span> into g<br />
orderby g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> descending<br />
<span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CrewStatsData<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Nick <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,<br />
&nbsp; &nbsp; Count <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>And if you need to group by multiple fields.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> s <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">CrewStatsSet</span><br />
<span style="color: #0600FF; font-weight: bold;">where</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;=</span> date1 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> date2 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span> <span style="color: #008000;">==</span> action<br />
group s by <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span>, s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span>, s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">userID</span> <span style="color: #008000;">&#125;</span> into g<br />
orderby g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> descending<br />
<span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CrewStatsData<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Nick <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span>,<br />
&nbsp; &nbsp; Count <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; ActionId <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span>,<br />
&nbsp; &nbsp; UserId <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">userID</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/11/24/linq-group-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a tag cloud with limited amout of tags in ASP.NET and LINQ</title>
		<link>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/</link>
		<comments>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:13:12 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tag]]></category>
		<category><![CDATA[Tag Cloud]]></category>
		<category><![CDATA[TagCloud]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=24</guid>
		<description><![CDATA[Today i built a Tag cloud for my new site. I found this great article about on how to do it with LINQ and C#. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code [...]]]></description>
			<content:encoded><![CDATA[<p>Today i built a Tag cloud for my new site. I found <a href="http://kosta.apostolou.ca/software-development/how-to-create-a-tagcloud-using-linq-and-aspnet" target="_blank">this great article about on how to do it with LINQ and C#</a>. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code if you have the same problem as me.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var tagSummary <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">TagItemRelations</span><br />
&nbsp; &nbsp; group ti by ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> into tagGroup<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,<br />
&nbsp; &nbsp; TagFrequency <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderByDescending</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Take</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #6666cc; font-weight: bold;">int</span> maxTagFrequency <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> t <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary <span style="color: #0600FF; font-weight: bold;">select</span> t<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
var tagCloud <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TagCloudItem <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span>,<br />
&nbsp; &nbsp; Weight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>ti<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span> <span style="color: #008000;">/</span> maxTagFrequency <span style="color: #008000;">*</span> <span style="color: #FF0000;">100</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>The main difference between my code and the code in the article is that i have slightly more complex data model (should not matter) and that i make the second query against the &#8220;result&#8221; from the first query. This allow me to first order by popularity and then in alphabetic order.</p>
<p>Please leave a comment if there is any better way to do this or if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using JQuery Validation plugin with ASP.NET</title>
		<link>http://codepolice.net/2008/10/09/using-jquery-validation-plugin-with-aspnet/</link>
		<comments>http://codepolice.net/2008/10/09/using-jquery-validation-plugin-with-aspnet/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 13:42:53 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Form Validation]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=4</guid>
		<description><![CDATA[Like everyone else i&#8217;ve been playing around with JQuery alot latley. Asp.net and JQuery is not the best friends in the world but i guess it will be alot better when using ASP.NET MVC. Microsoft also annoncued that they will support JQuery natively in future versions. Nice! If you want to learn more about ASP.NET [...]]]></description>
			<content:encoded><![CDATA[<p>Like everyone else i&#8217;ve been playing around with JQuery alot latley. Asp.net and JQuery is not the best friends in the world but i guess it will be alot better when using ASP.NET MVC. Microsoft also annoncued that they will support <a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx" target="_blank">JQuery natively in future versions</a>. Nice!</p>
<p>If you want to learn more about ASP.NET and Jquery be sure to read both <a href="http://www.west-wind.com/Weblog/" target="_blank">Rick Sthral&#8217;s</a> and the <a href="http://encosia.com/" target="_blank">Encosia</a> blogs.</p>
<p>I&#8217;m working on a new project now where i am trying to stay away from asp.net ajax mainly because of performance reasons but also just because i want to learn something new. Today i&#8217;ve been using the <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">JQuery Validation plugin</a>.</p>
<p>There is alot of documentation of how to use it on the the documentation pages for the plugin but i want to share with you one thing that i had problems with.</p>
<p>This is some regular example code that all the sample&#8217;s use. The problem here is that for example &#8220;EmailTextbox&#8221; is not the ID of the control but the name.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// validate signup form on keyup and submit</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#aspnetForm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;OpenIdTextbox<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;NicknameTextbox<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; required<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remote<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;resources/nickname.aspx&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;EmailTextbox<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; required<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; email<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I scratched my head for a long long time when i used ctl00_ContentPlaceHolder1_EmailTextbox and nothing worked at all. So what you have to do is change this to something like this ..</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #006600; font-style: italic;">// validate signup form on keyup and submit</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#aspnetForm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ctl00$ContentPlaceHolder1$OpenIdTextbox<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ctl00$ContentPlaceHolder1$NicknameTextbox<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;required<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;remote<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;resources/nickname.aspx&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ctl00$ContentPlaceHolder1$EmailTextbox<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;required<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;email<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>You could of course also use <a href="http://geekswithblogs.net/Gaurav/archive/2006/09/04/90195.aspx" target="_blank">some method that rewrite the Control.UniqueID to a name</a> and use &lt;%= %&gt; to get the name of the control.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/10/09/using-jquery-validation-plugin-with-aspnet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->