<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://community.sgdotnet.org/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Hannes&amp;#39;s Blog</title><subtitle type="html">Snippets from my C# ASP .Net development.</subtitle><id>http://community.sgdotnet.org/blogs/hannes/atom.aspx</id><link rel="alternate" type="text/html" href="http://community.sgdotnet.org/blogs/hannes/default.aspx" /><link rel="self" type="application/atom+xml" href="http://community.sgdotnet.org/blogs/hannes/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.30912.2823">Community Server</generator><updated>2005-07-01T15:10:00Z</updated><entry><title>Simple Threading in C#</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2007/03/28/Simple-Threading-in-C_2300_.aspx" /><id>/blogs/hannes/archive/2007/03/28/Simple-Threading-in-C_2300_.aspx</id><published>2007-03-28T09:57:00Z</published><updated>2007-03-28T09:57:00Z</updated><content type="html">&lt;p&gt;The following piece of code will keep a specified number of threads running concurrently. The threads all execute the same method which could be any kind of &amp;quot;worker process&amp;quot;.&lt;/p&gt;&lt;p&gt;The reason for this was performance issues on both multiple CPU&amp;#39;s and CPU&amp;#39;s with hyperthreading. From my tests, a dual-CPU server would run most efficiently when 4 threads were running concurrently. The processing speed would be 3 times faster than when running 1 thread.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thread[] Threads = new Thread[THREAD_COUNT];&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int RunningThreads = 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int IdleThreadIdx = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (RunningThreads &amp;gt; 0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Start a new thread while an idle thread slot is available&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((IdleThreadIdx &amp;lt; THREAD_COUNT) &amp;amp;&amp;amp; (!_Stopping))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // It is assumed that this thread will terminate within 1000ms if it has no work to do.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Threads[IdleThreadIdx] = new Thread(new ThreadStart(ProcessEvents));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Threads[IdleThreadIdx].Start();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thread.Sleep(1000);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Search for the first idle thread, and check number of idle threads:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdleThreadIdx = int.MaxValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RunningThreads = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = THREAD_COUNT - 1; i &amp;gt;= 0; i--)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((Threads&lt;img src="http://community.sgdotnet.org/emoticons/emotion-55.gif" alt="Idea" /&gt; != null) &amp;amp;&amp;amp; (Threads&lt;img src="http://community.sgdotnet.org/emoticons/emotion-55.gif" alt="Idea" /&gt;.IsAlive))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RunningThreads++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdleThreadIdx = i;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp;Note that the worker method &amp;quot;ProcessThreads&amp;quot; must not throw an exception, otherwise it seems that the calling application (in my case a&amp;nbsp;Windows service)&amp;nbsp;will be terminated without an exception.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=98026" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Caching Paladin entity lists in ASP .net</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/08/03/19160.aspx" /><id>/blogs/hannes/archive/2005/08/03/19160.aspx</id><published>2005-08-03T20:01:00Z</published><updated>2005-08-03T20:01:00Z</updated><content type="html">&lt;P&gt;I posted this article on a simple way to improve performance in&amp;nbsp;ASP .net&amp;nbsp;applications using Paladin.&lt;/P&gt;
&lt;P&gt;Please feel free to comment or give some further ideas on the topic.&lt;/P&gt;
&lt;P&gt;&lt;a href="http://community.sgdotnet.org/blogs/hannes/articles/19159.aspx"&gt;http://community.sgdotnet.org/blogs/hannes/articles/19159.aspx&lt;/A&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=19160" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>FilterList in Paladin</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/08/02/19121.aspx" /><id>/blogs/hannes/archive/2005/08/02/19121.aspx</id><published>2005-08-02T17:33:00Z</published><updated>2005-08-02T17:33:00Z</updated><content type="html">&lt;P&gt;I just made the leap from Paladin RC1 to RC3.&lt;/P&gt;
&lt;P&gt;The biggest change in code for me is the usage of FilterList's, but I agree with the change.&lt;/P&gt;
&lt;P&gt;I use filters everywhere, but most often as a singular equals comparison. For this reason I created this class to save some typing.&amp;nbsp; Just note that&amp;nbsp;logical AND is used between filters for this class.&lt;/P&gt;&lt;FONT&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;public class FilterListEqual : FilterList&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;public FilterListEqual(string fieldname, object equalvalue)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: base(new Filter(fieldname, Comparison.Equals, equalvalue)) {}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public Filter Add(string fieldname, object equalvalue)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (this.Count == 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return base.Add(fieldname, Comparison.Equals, equalvalue);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return base.Add(Logical.And, fieldname, Comparison.Equals, equalvalue);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;Yep, that's it. The usage for a single equals&amp;nbsp;comparison would then be:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;BusinessComponent BC = new BusinessComponent;&lt;BR&gt;BC.Populate(BudgetList, new FilterListEqual(epcdb.Budget.FieldNames.name, "Budget 2005"));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;The overloaded&amp;nbsp;Add method can be used to add more filters, or you could create more overloaded constructors. &lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=19121" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Checking for duplicates using Paladin</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/07/14/18556.aspx" /><id>/blogs/hannes/archive/2005/07/14/18556.aspx</id><published>2005-07-14T20:46:00Z</published><updated>2005-07-14T20:46:00Z</updated><content type="html">&lt;P&gt;This is one way to check for duplicates when adding/editing records with unique field values.&amp;nbsp; It is useful when the list to check against is not available locally, ie. when the database must be checked for duplicates.&lt;/P&gt;
&lt;P&gt;A CustomValidator's ServerValidate event is used here.&amp;nbsp; EditID is the primary key of the record being edited, or 0 if a new record is added.&amp;nbsp; The "name" field is checked for uniqueness.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;// Paladin RC2 code - pass&amp;nbsp;a FilterList to BC.Populate&amp;nbsp;for RC3!&lt;BR&gt;private void valName_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)&lt;BR&gt;{&lt;BR&gt;try&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string new_name = args.Value.ToString();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.ProductList ProductList = new db.ProductList();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductList.Filters.Add(db.Product.FieldNames.name, Comparison.Equals, new_name);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (EditID != 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductList.Filters.Add(Logical.And, db.Product.FieldNames.id, Comparison.NotEquals, EditID);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;BusinessComponent BC = new BusinessComponent();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;BC.Populate(ProductList);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;args.IsValid = (ProductList.Count == 0);&lt;BR&gt;}&lt;BR&gt;catch (Exception ex)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;args.IsValid = false;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// display error&lt;BR&gt;}&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Note: If a complete&amp;nbsp;entity list is&amp;nbsp;available, you would rather use the following check to avoid the trip to the server:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;int idx = CompleteProductList.Find(db.Product.FieldNames.name, new_name);&lt;BR&gt;IsValid = ( (idx &amp;lt; 0) ||&amp;nbsp;&amp;nbsp; ((CompleteProductList[idx].id == EditID)&amp;nbsp;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Let me know about other ways to check for duplicates!&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=18556" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Ok/Cancel web control</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/07/13/18463.aspx" /><id>/blogs/hannes/archive/2005/07/13/18463.aspx</id><published>2005-07-13T12:28:00Z</published><updated>2005-07-13T12:28:00Z</updated><content type="html">&lt;P&gt;I built this silly control for&amp;nbsp;Ok/Cancel Javascript prompts initiated from the server side. This is useful in cases where you would like to check whether you do want the prompt to pop up first, eg. to check whether&amp;nbsp;the user is allowed to&amp;nbsp;delete an item&amp;nbsp;or not.&lt;/P&gt;
&lt;P&gt;To use the control, the &lt;STRONG&gt;Show method&lt;/STRONG&gt; is called, and the&amp;nbsp;&lt;STRONG&gt;Click event&lt;/STRONG&gt;&amp;nbsp;will fire if the user clicks Ok.&lt;/P&gt;
&lt;P&gt;The source code is small enough. :)&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;[&amp;nbsp;Designer("epc_webcontrols.popupDesigner, epc_webcontrols") ]&lt;BR&gt;public class popup : WebControl&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;public event EventHandler Click;&lt;BR&gt;&amp;nbsp;&amp;nbsp;private LinkButton _Button;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;private string FmtJSConstant(string s)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{ return s.Replace("\\", "&lt;A&gt;\\\\").Replace("'&lt;/A&gt;", "&lt;A href="file://\\'"&gt;\\'&lt;/A&gt;"); }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;public void Show(string prompt)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string JID = this.UniqueID.Replace(":", "_");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string script =&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;"&amp;lt;script&amp;gt;" +&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"&amp;nbsp;if(confirm('%%TEXT%%'))&amp;nbsp;__doPostBack('%%CID%%','');" +&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;"&amp;lt;/script&amp;gt;";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;script = script.Replace("%%JID%%", JID);&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;script = script.Replace("%%TEXT%%", FmtJSConstant(prompt));&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;script = script.Replace("%%CID%%", FmtJSConstant(_Button.ClientID));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (!Page.IsClientScriptBlockRegistered("pppopup_" + JID))&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;Page.RegisterStartupScript("pppopup_" + JID, script);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;protected override void OnInit(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _Button = new LinkButton();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.Controls.Add(_Button);&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;_Button.Click += new EventHandler(_Button_Click);&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;base.OnInit (e);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;private void _Button_Click(object sender, EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Click != null) Click(this, e);&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;public class popupDesigner : System.Web.UI.Design.ControlDesigner &lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public override string GetDesignTimeHtml() &lt;BR&gt;&amp;nbsp; &amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; popup ctl = (popup) Component;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return @"&amp;lt;DIV style='background-color:blue;color:white;'&amp;gt;Ok / Cancel&amp;lt;/DIV&amp;gt;";&lt;BR&gt;&amp;nbsp; &amp;nbsp;}&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=18463" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Custom ASP .net updown control</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/07/11/18363.aspx" /><id>/blogs/hannes/archive/2005/07/11/18363.aspx</id><published>2005-07-11T14:30:00Z</published><updated>2005-07-11T14:30:00Z</updated><content type="html">&lt;P&gt;I posted an article - more of a brief source code explanation - of an updown control that I use in my web projects.&lt;/P&gt;
&lt;P&gt;&lt;a href="http://community.sgdotnet.org/blogs/hannes/articles/18061.aspx"&gt;http://community.sgdotnet.org/blogs/hannes/articles/18061.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The control&amp;nbsp;allows the user to enter numeric values or scroll the value using up/down buttons, and&amp;nbsp;enforces valid values.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The source code for the control is available at the following&amp;nbsp;url.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://triplez.sg.gs/sgdotnet/Updown.zip"&gt;http://triplez.sg.gs/sgdotnet/Updown.zip&lt;/A&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=18363" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Paladin/COM+ transactions on Windows 2000</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/07/04/18054.aspx" /><id>/blogs/hannes/archive/2005/07/04/18054.aspx</id><published>2005-07-04T17:20:00Z</published><updated>2005-07-04T17:20:00Z</updated><content type="html">&lt;P&gt;I will check these issues on Windows XP when possible, and post any remaining issues to the Paladin Knowledge Base. For now, it is only useful to developers working on Windows 2000, which I guess is me.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Error: Failed to register assembly 'Paladin.Core, Version=0.9....&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resolution:&lt;BR&gt;&lt;/STRONG&gt;The COM+ application can not register automatically for some reason.&lt;BR&gt;Execute &lt;EM&gt;regsvcs Paladin.Core.dll&lt;/EM&gt; and do the same for all assemblies that take part in COM+ transactions.&lt;BR&gt;The assemblies will also need to have strong names (signed with a key).&lt;BR&gt;&lt;U&gt;Signing is not possible for the web application assembly&lt;/U&gt;, so all business components should be moved to another assembly.&lt;BR&gt;Whenever an assembly's COM+ components&amp;nbsp;are modified, the COM+ application&amp;nbsp;should be registered again.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Error: An error occurred while enlisting in a distributed transaction.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resolution:&lt;/STRONG&gt;&lt;BR&gt;This could happen when the assembly that you are creating the object from does not have a strong name - an issue if you would like to use &lt;EM&gt;ServicedBusinessComponent&lt;/EM&gt; in your web application.&lt;/P&gt;
&lt;P&gt;I attempted to solve this issue by changing the &lt;EM&gt;Paladin Enterprise Services&lt;/EM&gt; COM+ application's activation type to &lt;EM&gt;server application&lt;/EM&gt;. This in turn produces an &lt;EM&gt;Access is denied&lt;/EM&gt; error. The system event log reports that this is because an IUSR_ account is used to attempt launching a DCOM Server. I did not attempt to resolve this security issue, and abandoned this approach.&lt;/P&gt;
&lt;P&gt;To work around this issue, you can create a replacement class in a signed assembly.&amp;nbsp;Any&amp;nbsp;class&amp;nbsp;that inherits from &lt;EM&gt;ServicedBusinessBase&lt;/EM&gt; will do. This wrapper class can then be used within the web application without problems.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=18054" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry><entry><title>Html tables: fixed-layout</title><link rel="alternate" type="text/html" href="/blogs/hannes/archive/2005/07/01/17951.aspx" /><id>/blogs/hannes/archive/2005/07/01/17951.aspx</id><published>2005-07-01T13:10:00Z</published><updated>2005-07-01T13:10:00Z</updated><content type="html">&lt;P&gt;&lt;EM&gt;I just copied this from my blogger account to test things out. :)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;For some reason I have never used the &lt;STRONG&gt;table-layout&lt;/STRONG&gt; CSS2 attribute. It is handy in cases where one column should use all "remaining width" of a table.&lt;/P&gt;
&lt;P&gt;With table-layout set to auto (the default), the table below will&amp;nbsp;have its&amp;nbsp;first two columns&amp;nbsp;condensed.&lt;BR&gt;&amp;lt;table width="100%"&amp;gt;&amp;lt;tr&amp;gt;&lt;BR&gt;&amp;lt;td width="100" bgcolor="Red"&amp;gt;a&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;td width="200" bgcolor="Blue"&amp;gt;b&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;td width="100%" bgcolor="Green"&amp;gt;c&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt; &lt;/P&gt;
&lt;TABLE&gt;

&lt;TR&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;With table-layout set to fixed, 100%&amp;nbsp;can be regarded as&amp;nbsp;"all remaining space".&amp;nbsp;The &amp;lt;col&amp;gt; notation is optional, but I prefer it.&lt;BR&gt;&amp;lt;table width="100%" style="table-layout: fixed"&amp;gt;&amp;lt;tr&amp;gt;&lt;BR&gt;&amp;lt;col width="100"&amp;gt;&amp;lt;col width="200"&amp;gt;&amp;lt;col width="100%"&amp;gt;&lt;BR&gt;&amp;lt;td bgcolor="Red"&amp;gt;a&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;td bgcolor="Blue"&amp;gt;b&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;td bgcolor="Green"&amp;gt;c&amp;lt;/td&amp;gt;&lt;BR&gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt; &lt;/P&gt;
&lt;TABLE&gt;

&lt;TR&gt;&lt;/TR&gt;





&lt;TR&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;The second Red/Blue/Green table is often the desired result. There must be other ways to get the same results and I would like to hear about them.&lt;/P&gt;
&lt;P&gt;I did have a working layout without using fixed tables, but it caused the horizontal scrollbar to appear in IE6 at the incorrect width.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.sgdotnet.org/aggbug.aspx?PostID=17951" width="1" height="1"&gt;</content><author><name>hannes</name><uri>http://community.sgdotnet.org/members/hannes/default.aspx</uri></author></entry></feed>