<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-648126094267448871</id><updated>2024-10-25T02:21:20.815-07:00</updated><category term=".NET"/><category term="Web Development"/><category term="LINQ"/><category term="SQL"/><category term="User Controls"/><category term="HTTP"/><category term="JQuery"/><category term="JavaScript"/><category term="Analysis Services"/><category term="C#"/><category term="IE Bugs"/><category term="IIS"/><category term="Patterns and Practices"/><category term="Podcast"/><category term="SQL Server"/><category term="Web Service"/><category term="XML"/><title type='text'>Console.WriteLine(&quot;Irfan&#39;s blog&quot;)</title><subtitle type='html'>/*  This blog has migrated. Please visit http://irfanghaffar.net */</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default?alt=atom'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default?alt=atom&amp;start-index=26&amp;max-results=25'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>36</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-8411348940969288573</id><published>2011-04-09T01:48:00.000-07:00</published><updated>2011-04-09T01:59:16.302-07:00</updated><title type='text'>This Blog Has Moved</title><content type='html'>Please update your links, feeds, bookmarks.&lt;br /&gt;&lt;br /&gt;This blog is now residing at: &lt;a href=&quot;http://irfanghaffar.net&quot;&gt;http://irfanghaffar.net&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope to see you all there.</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/8411348940969288573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2011/04/this-blog-has-moved.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/8411348940969288573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/8411348940969288573'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2011/04/this-blog-has-moved.html' title='This Blog Has Moved'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-3518329781766265789</id><published>2010-12-17T07:00:00.000-08:00</published><updated>2010-12-17T13:40:35.967-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Rolling your own identities</title><content type='html'>&lt;p&gt;I must say that I am not a database guy and my SQL skills are limited. But, it is not an acceptable excuse, specially when we are working in a small team and there is no dedicated database guy. We have no choice but to hone in our database skills and get ready to switch between the roles. That is exactly what I had to do when one of the system users reported an issue where database generated the same ID for 2 different records. I delved into to the SP and found what in the database world is called “&lt;em&gt;Rolling your own identities&lt;/em&gt;”. It is a technique (hack or shortcut or whatever you want to call it) to generate ID numbers by getting the MAX of a column and adding 1 to it. It is a widely known solution in the community for situations when displaying a primary key column (with its seed and increment values set) on the client interface is not an option. For example if it is a GUID column or it has an out of sequence ID numbers due to frequent delete and insert operations.&lt;/p&gt;&lt;p&gt;So, this is what I saw in the SP, which is actually a way of &lt;em&gt;Rolling your own identities.&lt;/em&gt;&lt;/p&gt;&lt;pre class=&quot;brush: sql&quot;&gt;&lt;br /&gt;BEGIN TRANSACTION&amp;#160;&lt;br /&gt;/* select query */&amp;#160; &lt;br /&gt;SELECT TOP 1 @ItemNumber = ItemNumber + 1 &lt;br /&gt;FROM ItemTable &lt;br /&gt;WHERE {some_condition} &lt;br /&gt;ORDER BY ItemNumber DESC&lt;br /&gt;&lt;br /&gt;/* insert query */ &lt;br /&gt;INSERT INTO ItemTable (ItemNumber, {column2}, {column3}) &lt;br /&gt;VALUES (@ItemNumber, {some_value}, {some_value}) &lt;br /&gt;END TRANSACTION&lt;/pre&gt;&lt;p&gt;The /*select query*/ above can also be written using MAX a function.&lt;/p&gt;&lt;pre class=&quot;brush: sql&quot;&gt;&lt;br /&gt;SELECT MAX(ItemNumber) FROM ItemTable&lt;br /&gt;WHERE {some_condition}&lt;/pre&gt;&lt;h2&gt;What exactly the problem is&lt;/h2&gt;&lt;p&gt;If you notice, select and insert queries above are within a transaction which is important in a distributed environment where multiple clients access the database (or at least this SP) at the same time. I always believed that &lt;em&gt;BEGIN TRANSACTION&lt;/em&gt; statement is the ultimate savior and creates a critical section internally, thus preventing 2 transactions from accessing the same database resource at the same time, like a lock statement in C#. If that was true, then why it allowed 2 different transactions to execute the select query concurrently thus allowing them to have the same max ItemNumber?&lt;/p&gt;&lt;h2&gt;Research ensues&lt;/h2&gt;&lt;p&gt;My first clue was the transactions isolation level. It is a keyword which controls the default locking behavior. The default transaction isolation level in SQL Server is &lt;em&gt;Read Committed, &lt;/em&gt;which means only data committed by other transaction can be read hence avoids dirty read. But, this is not what I wanted.&lt;/p&gt;&lt;h2&gt;What do you want then?&lt;/h2&gt;&lt;p&gt;I wanted a way to bar other users from accessing select query until transaction is finished executing select *AND* insert statements both. I think I was wanting to convert my transaction into a truly atomic unit of work in order to make sure every transaction gets a new ItemNumber whenever it runs its select statement. Since &lt;em&gt;Read Committed&lt;/em&gt; doesn’t serve the purpose, I decided on reading more about other transaction isolation levels and locking behaviors.&lt;/p&gt;&lt;h4&gt;&lt;em&gt;Read Uncommitted: &lt;/em&gt;&lt;/h4&gt; As explained in many places on the internet, By using this level one can read the data which has been read by other transactions but not yet committed. In this case no shared and exclusive locks will be honored and dirty read will not be prevented. It can also result in Phantom data or nonrepeatable reads. I certainly didn’t want this as I needed more restrictive locking not less. I moved onto &lt;em&gt;Repeatable Read.&lt;/em&gt;&lt;h4&gt;&lt;em&gt;Repeatable Read: &lt;/em&gt;&lt;/h4&gt;&lt;p&gt;This one took a bit long to get into my head. This isolation level will not allow other users to update the data that has been read in the select query. But, why do they call it repeatable? Actually within a SAME transaction we would like to issue the same SELECT statement multiple times.&lt;/p&gt;&lt;h4&gt;&lt;em&gt;Transaction 1&lt;/em&gt;&lt;/h4&gt;&lt;pre class=&quot;brush: sql&quot;&gt; &lt;br /&gt;         SELECT ItemNumber, ItemDetail FROM ItemTable &lt;br /&gt;         WHERE ItemNumber &amp;lt; 10&lt;/pre&gt;&lt;h4&gt;&lt;em&gt;Transaction 2&lt;/em&gt;&lt;/h4&gt;&lt;pre class=&quot;brush: sql&quot;&gt;&lt;br /&gt;          SET ItemDetail = {some_new_value} &lt;br /&gt;          WHERE ItemNumber = 5&lt;br /&gt;        &lt;/pre&gt;&lt;h4&gt;&lt;em&gt;Transaction 1 continues...&lt;/em&gt;&lt;/h4&gt;&lt;pre class=&quot;brush: sql&quot;&gt;   &lt;br /&gt;        SELECT ItemNumber, ItemDetail FROM ItemTable &lt;br /&gt;        WHERE ItemNumber &amp;lt; 10&lt;/pre&gt;&lt;p&gt;In order to make sure Transaction 2 doesn’t update the records we have selected between multiple reads (means we may repeat our read later in the transaction), SQL Server will maintain a lock on all the rows we have read until the transaction ends. This is certainly more restrictive locking than &lt;em&gt;Read Committed. &lt;/em&gt;We get the ownership of the rows we read till the end of the transaction.&lt;/p&gt;&lt;p&gt;Unfortunately, even &lt;em&gt;Repeatable Read &lt;/em&gt;can’t help create the kind of critical section I talked about earlier because of one reason. It does allow INSERTS. Yes, no other users/transactions can update the rows&amp;#160; in the transaction, but they can always insert new rows amid the rows we have already locked. The newly inserted rows are called Phantom rows. This is exactly what our problem is that we don’t want to let other users insert until transaction is finished. Hmm.. since I was desperate to find a solution, I moved on and read about the next isolation level.&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;h4&gt;Serializable: &lt;/em&gt;&lt;/h4&gt;This isolation level will place a range lock on all the data we have read, means whatever rows come in that range will not be allowed to be updated or deleted, and no insertion will also be possible within that range. This level does what I wanted as it is the most restrictive locking. We can use HOLDLOCK as it has the same effect as using Serializable on all tables in SELECT statement in a transaction.&lt;/p&gt;&lt;pre class=&quot;brush: sql;&quot;&gt;/* select query */&amp;#160; &lt;br /&gt;SELECT MAX(ItemNumber) FROM ItemTable WITH (HOLDLOCK)&lt;/pre&gt;&lt;p&gt;But, why do they say “Serializable is prone to cause deadlock”? Should I be worried about it? I think yes, because now I am eyeing on the most optimized solution and it is fair to be threatened by every warning it gives.&amp;#160; &lt;/p&gt;&lt;h2&gt;Serializable and Repeatable Read may cause deadlocks&lt;/h2&gt;&lt;p&gt;I can’t explain this better than MSDN:&lt;/p&gt;&lt;p&gt;“The transaction reads data, acquiring a shared (S) lock on the resource (page or row), and then modifies the data, which requires lock conversion to an exclusive (X) lock. If two transactions acquire shared-mode locks on a resource and then attempt to update data concurrently, one transaction attempts the lock conversion to an exclusive (X) lock. The shared-mode-to-exclusive lock conversion must wait because the exclusive lock for one transaction is not compatible with the shared-mode lock of the other transaction; a lock wait occurs. The second transaction attempts to acquire an exclusive (X) lock for its update. Because both transactions are converting to exclusive (X) locks, and they are each waiting for the other transaction to release its shared-mode lock, a deadlock occurs.”&lt;/p&gt;&lt;p&gt;To avoid this potential deadlock problem, update (U) locks are used. Since HOLDLOCK only applies &lt;em&gt;shared range locks&lt;/em&gt;, we can always complement this with UPDATE to turn into &lt;em&gt;update range locks&lt;/em&gt;.&lt;/p&gt;&lt;pre class=&quot;brush: sql;&quot;&gt;&lt;br /&gt;/* to see what locks HOLDLOCK applies – same can be repeated for UPDATE as well */&lt;br /&gt;BEGIN TRANSACTION &lt;br /&gt;  SELECT MAX(ItemNumber) from Orders with(HOLDLOCK) &lt;br /&gt;  EXEC sp_lock @@SPID &lt;br /&gt;  ROLLBACK&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;So, that means our final query should look something like this:&lt;/p&gt;&lt;pre class=&quot;brush: sql;&quot;&gt; &lt;br /&gt;  /* select query */&lt;br /&gt;  BEGIN TRANSACTION&amp;#160; &lt;br /&gt;   SELECT MAX(ItemNumber) FROM ItemTable WITH (HOLDLOCK, UPDATE)&lt;br /&gt;   &lt;br /&gt;   /* insert query */ &lt;br /&gt;   INSERT INTO ItemTable (ItemNumber, {column2}, {column3}) &lt;br /&gt;   VALUES (@ItemNumber, {some_value}, {some_value}) &lt;br /&gt;  END TRANSACTION&lt;/pre&gt;&lt;p&gt;We should now be able to generate our own *unique* identities in a distributed environment without worrying about deadlocks using appropriate isolation level and locking.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/3518329781766265789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/12/rolling-your-own-identities_17.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3518329781766265789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3518329781766265789'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/12/rolling-your-own-identities_17.html' title='Rolling your own identities'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-5395103661369735726</id><published>2010-12-03T12:30:00.001-08:00</published><updated>2010-12-04T03:09:24.770-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>Using Generics Judiciously</title><content type='html'>&lt;p&gt;Generics is one of the important features C# offers. It was one of biggest changes when C#2.0. was announced. As it name suggests, It helps developers write generic code using generic (unknown) types that are replaced with actual types at JIT time.  &lt;/p&gt;  &lt;p&gt;Generic types and functions, of course, offer many advantages e.g. they enhance performance, make code more expressive, move a lot of safety from execution time to compile time etc. One of the advantages which I like most is that it avoids casting and duplicate code, something which we used to do before Generics were introduced. I have used Object type in the past in order to make the code generic when the actual (specific) types were not known in advance.&lt;/p&gt;  &lt;p&gt;The thing which I learnt today is the fact that by just looking at the function signatures one can’t decide whether these functions should be converted into Generic. They may share the same name but not the same implementation. For example consider below functions I encountered:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet;&quot;&gt;&lt;br /&gt; Public Shared Function GetXSLTTransformedXML(ByVal xmlLocation As String, ByVal xsltLocation As String, ByVal args As XsltArgumentList) As String&lt;br /&gt;&lt;br /&gt;        Dim document As New Linq.XDocument()&lt;br /&gt;        Dim xsltTransformer As Xsl.XslCompiledTransform = New Xsl.XslCompiledTransform()&lt;br /&gt;        Dim transformedXML As String = String.Empty&lt;br /&gt;&lt;br /&gt;        Try&lt;br /&gt;            document = Linq.XDocument.Load(xmlLocation)&lt;br /&gt;            xsltTransformer.Load(xsltLocation, New Xsl.XsltSettings(False, True), New XmlUrlResolver())&lt;br /&gt;            transformedXML = GetXSLTTransformedXML(document, xsltTransformer, args)&lt;br /&gt;&lt;br /&gt;        Catch ex As Exception&lt;br /&gt;            Throw ex&lt;br /&gt;&lt;br /&gt;        End Try&lt;br /&gt;&lt;br /&gt;        Return transformedXML&lt;br /&gt;&lt;br /&gt;    End Function&lt;br /&gt;&lt;br /&gt;    Public Shared Function GetXSLTTransformedXML(ByVal document As Linq.XDocument, ByVal xslt As XslCompiledTransform, ByVal args As XsltArgumentList) As String&lt;br /&gt;&lt;br /&gt;        Dim memStream As New System.IO.MemoryStream()&lt;br /&gt;        Dim writer As XmlTextWriter&lt;br /&gt;        Dim streamReader As StreamReader&lt;br /&gt;        Dim transformedXML As String = String.Empty&lt;br /&gt;&lt;br /&gt;        Try&lt;br /&gt;            writer = New XmlTextWriter(memStream, System.Text.Encoding.UTF8)&lt;br /&gt;            xslt.Transform(document.CreateReader(), args, writer)&lt;br /&gt;            writer.Flush()&lt;br /&gt;            memStream.Position = 0&lt;br /&gt;            streamReader = New StreamReader(memStream)&lt;br /&gt;            transformedXML = streamReader.ReadToEnd()&lt;br /&gt;&lt;br /&gt;        Catch ex As Exception&lt;br /&gt;            Throw ex&lt;br /&gt;&lt;br /&gt;        Finally&lt;br /&gt;            memStream.Close()&lt;br /&gt;            writer.Close()&lt;br /&gt;        End Try&lt;br /&gt;&lt;br /&gt;        Return transformedXML&lt;br /&gt;&lt;br /&gt;    End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;I got excited when I looked at them and thought let’s convert them into one generic function because both share the same signature and differ in parameters. Later, I realized that I will not get the advantage Generics bring to the code if both the functions do not share the same implementation as well.&lt;/p&gt;&lt;p&gt;For example in the above functions, I want to execute a different branch of code based upon the first parameter. Knowing this, If I go on converting them into one Generic function, I will end up type casting the first parameter to decide which code to execute. If I have to type cast it then it kills the whole purpose of using Generics. Not only that, it also kills the intuitiveness of the code also. My fellow developer can easily identify what function to call if  he has an XML document location leaving the other implementation for those who have XML document loaded in the cache. If it were Generic, It would be difficult for people.&lt;/p&gt;&lt;p&gt;I don’t mean that Generics is bad in anyway. I believe it is just not best for this kind of situation. If I have a MakeList&amp;lt;T&amp;gt; kind of function, I would not think twice.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Public Function MakeList(of T)(ByVal first As T, ByVal second As T) As List&lt;t&gt;&lt;br /&gt;   &#39;Builds the same list containing parameters irrespective of their types.&lt;br /&gt;End Function&lt;/t&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/5395103661369735726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/12/using-generics-judiciously.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5395103661369735726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5395103661369735726'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/12/using-generics-judiciously.html' title='Using Generics Judiciously'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-340935555316953350</id><published>2010-12-03T05:34:00.001-08:00</published><updated>2010-12-04T02:45:49.068-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTTP"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Service"/><title type='text'>Posting data from a web service to a web page</title><content type='html'>&lt;p&gt;Writing and consuming web services is one of the important things we do at work. Systems running a variety of operating systems and with a completely different set of configurations make it difficult to exchange data easily. Things get even worse when there is a difference in time zones. We really didn’t want to wait for our integration partner to come back to us with a feedback whether they received the data or not. We rather decided to take ‘just-try-it” approach to post (HTTP-POST) web service data to a web page on localhost and it worked. I know it is not a rocket science, but it saved me time and effort, so I thought of sharing it.&lt;/p&gt;&lt;p&gt;So, this is what we do to send data to a web service:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet; highlight: 7&quot;&gt;&lt;br /&gt;Try&lt;br /&gt;&lt;br /&gt;      stream = File.OpenText( &quot;C:\ServiceData.xml&quot; )&lt;br /&gt;      strXML = stream.ReadToEnd()&lt;br /&gt;      stream.Close()&lt;br /&gt;&lt;br /&gt;      webreq = HttpWebRequest.Create(&quot;{Web-Service-Uri}&quot;)&lt;br /&gt;      webreq.Method = &quot;POST&quot;&lt;br /&gt;      webreq.ContentType = &quot;application/x-www-form-urlencoded&quot;&lt;br /&gt;&lt;br /&gt;      strXML = &quot;data=&quot; &amp;amp; HttpUtility.UrlEncode(strXML)&lt;br /&gt;      bytes = System.Text.Encoding.UTF8.GetBytes(strXML)&lt;br /&gt;      webreq.ContentLength = bytes.Length&lt;br /&gt;&lt;br /&gt;      requestStream = webreq.GetRequestStream()&lt;br /&gt;      requestStream.Write(bytes, 0, bytes.Length)&lt;br /&gt;      requestStream.Close()&lt;br /&gt;&lt;br /&gt;      webResponse = webreq.GetResponse()&lt;br /&gt;      responseStream = New IO.StreamReader(webResponse.GetResponseStream())&lt;br /&gt;      responseStream.Close()&lt;br /&gt;      webResponse.Close()&lt;br /&gt;      webreq = Nothing&lt;br /&gt;&lt;br /&gt;Catch ex As System.Net.WebException&lt;br /&gt;&lt;br /&gt;     Dim responseFromServer As [String] = ex.Message.ToString() &amp;amp; &quot; &quot;&lt;br /&gt;     If ex.Response IsNot Nothing Then&lt;br /&gt;            Using response As Net.WebResponse = ex.Response&lt;br /&gt;            Dim data As Stream = response.GetResponseStream()&lt;br /&gt;                  Using reader As New StreamReader(data)&lt;br /&gt;                         responseFromServer += reader.ReadToEnd()                        &lt;br /&gt;                End Using&lt;br /&gt;     End Udsing&lt;br /&gt; End If&lt;br /&gt;End Try&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The above code works fine if you want to send data to a web service. However, to send to a webpage all we have to do is replace the service uri  {Web-Service-Uri} on line 07 with web page address, something like this:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;webreq = HttpWebRequest.Create(&quot;{Web-Service-Uri}&quot;) –&amp;gt; Posting to a web service&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;webreq = HttpWebRequest.Create(&quot;http://localhost:1886/service-data-receiver.aspx&quot; ) –&amp;gt; Posting to a web page&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The part which I had to figure out was how to access the data sent from a web service to my page. Since the request was not originated by a page-based model, I couldn&#39;t use Request.Forms or Request.QueryString. After some research I found that it is just Request object that can be used to access data. Yes, that is it. &lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Protected Sub Page_Load(ByVal sender As Object , ByVal e As System.EventArgs) Handles Me.Load&lt;br /&gt;&lt;br /&gt; Dim response1 As String = HttpUtility.UrlDecode(Request( &quot;data&quot;))Dim doc As XDocument = XDocument.Parse(response1)     &lt;br /&gt; doc.Save( &quot;C:\inetpub\wwwroot\service-data-received.xml&quot; )&lt;br /&gt; Response.Write(response1)&lt;br /&gt;&lt;br /&gt;End Sub&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/340935555316953350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/12/posting-data-from-web-service-to-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/340935555316953350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/340935555316953350'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/12/posting-data-from-web-service-to-web.html' title='Posting data from a web service to a web page'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-3728780427700206998</id><published>2010-07-31T15:56:00.001-07:00</published><updated>2010-12-04T02:59:57.405-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>LINQ to XML ― brings new reasons to use more XML</title><content type='html'>&lt;p&gt;I recently did a small talk about the benefits of using new XML API “LINQ to XML”. According to MSDN:&lt;/p&gt;&lt;i&gt;&lt;blockquote&gt;LINQ to XML provides an in-memory XML programming interface that leverages the .NET Language-Integrated Query (LINQ) Framework. LINQ to XML uses the latest .NET Framework language capabilities and is comparable to an updated, redesigned Document Object Model (DOM) XML programming interface.&lt;/blockquote&gt;&lt;/i&gt;The talk wealso requirednt very well, and luckily I managed to get the attention of the audience, because the approach I adopted was a little different than the normal. Instead of talking plainly about the new functions and properties, I rather tried to draw a comparison between the way we deal with the XML using existing and new API. I also shared why VB developers are more excited about this API than C# guys, and what is making them feel more privileged. &lt;p&gt;&lt;/p&gt; &lt;p&gt;The core functionality of the new API revolves around 3 key concepts.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Functional Construction  &lt;/li&gt;&lt;li&gt;Context-Free XML creation  &lt;/li&gt;&lt;li&gt;Simplified NameSpaces&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;Functional Construction&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;The ability to create the entire XML tree or part of it by just using one statement.&lt;em&gt; &lt;/em&gt;If you are someone like me who doesn’t play with XML day-in and day-out, you have to probably recall for a second how do you create XML and using which API. This is so true because the depth and breadth of XML API choices available to us today is overwhelming. For example, &lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;XMLTextReade&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:small;&quot;&gt;r&lt;/span&gt;:&lt;/strong&gt; for low-level parsing of XML &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;document&lt;/span&gt;s.  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;XMLTextWriter&lt;/span&gt;: &lt;/strong&gt;fast, non-cached, forward-only way of generating XML  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;XMLReader:&lt;/strong&gt; read-only, forward-only API generally used to deal with large XML documents.  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;XMLDocument&lt;/strong&gt;, &lt;strong&gt;XMLNode&lt;/strong&gt; and &lt;strong&gt;XPathNavigator&lt;/strong&gt; etc. etc. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;So, if I want to create the below book XML in my application, I can either use XmlTextWriter.WriteStartElement() or I can also use XMLDocument.CreateNode() If document manipulation is also required.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&amp;lt;books&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;book&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;title&amp;gt;Essential .NET&amp;lt;/title&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;author&amp;gt;Don Box&amp;lt;/author&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;author&amp;gt;Chris Sells&amp;lt;/author&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;publisher&amp;gt;Addison-Wesley&amp;lt;/publisher&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/books&amp;gt;  &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Though, there is nothing wrong with both of the approaches mentioned above except the fact that they take more lines of code and more time as well just to churn out a tiny piece of XML. LINQ to XML aims to solve this problem by introducing XElement which takes params array as a parameter in one of its constructors allowing us to write entire XML tree in one statement.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;XElement elements = new XElement(&quot;books&quot;,&lt;br /&gt;&lt;br /&gt;                           new XElement(&quot;book&quot;,&lt;br /&gt;                               new XElement(&quot;title&quot;, &quot;Essential .NET&quot;),&lt;br /&gt;                               new XElement(&quot;author&quot;, &quot;Don Box&quot;),&lt;br /&gt;                               new XElement(&quot;author&quot;, &quot;Chris Sells&quot;),&lt;br /&gt;                               new XElement-W(&quot;publisher&quot;, &quot;Addisonesley&quot;)&lt;br /&gt;                       )&lt;br /&gt;                    );&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;&lt;br /&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;Context-Free XML creation: &lt;/span&gt;&lt;/h2&gt;&lt;/strong&gt;&lt;p&gt;When creating XML using DOM, everything has to be in context of parent document. This document-centric approach for creating XML results in code hard to read, write and debug. In LINQ to XML, attributes have been given first-class status. So, rather than going through factory methods to create elements and attributes, we can use compositional constructors offered by XElement and XAttribute class.&lt;/p&gt;&lt;p&gt;If I want to add an ISBN number as an attribute to the book element in the above book XML, I can simply write:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;XElement elements = new XElement(&quot;books&quot;,&lt;br /&gt;                           new XElement(&quot;book&quot;, &lt;b&gt;new XAttribute(“ISBN”, “0201734117”)&lt;/b&gt;,&lt;br /&gt;                                new XElement(&quot;title&quot;, &quot;Essential .NET&quot;),&lt;br /&gt;                              new XElement(&quot;author&quot;, &quot;Don Box&quot;),&lt;br /&gt;                              new XElement(&quot;author&quot;, &quot;Chris Sells&quot;),&lt;br /&gt;                              new XElement(&quot;publisher&quot;, &quot;Addison-Wesley&quot;)&lt;br /&gt;                       )&lt;br /&gt;                    );&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;&lt;br /&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;Simplified Namespaces: &lt;/span&gt;&lt;/h2&gt;&lt;/strong&gt;I believe this is the most confusing aspect of XML. With the existing set of API, we have to remember many things like XML names, NameSpaces, prefixes associated with the NameSpaces, Namespace managers etc. LINQ to XML allows us to forget everything else and just focus on one thing called “&lt;strong&gt;fully expanded name&lt;/strong&gt;” which is represented by XName class.&lt;br /&gt;&lt;p&gt;Let’s see how this new functionality differs from the existing one by taking an example of RSS feed of my blog. In the RSS document, which can be accessed from here &lt;a href=&quot;http://feeds.feedburner.com/feed-irfan&quot;&gt;http://feeds.feedburner.com/feed-irfan&lt;/a&gt; (right click → view source), I am interested in “totalResults” element which is prefixed by “openSearch”. This is how I do it using  XMLNameSpaceManager which has been part of the .NET framework for a long time.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;XmlDocument rss = new XmlDocument();&lt;br /&gt;&lt;br /&gt;rss.Load(&quot;http://feeds.feedburner.com/feed-irfan&quot;);&lt;br /&gt;&lt;br /&gt;XmlNamespaceManager nsManager = new XmlNamespaceManager(rss.NameTable);&lt;br /&gt;&lt;br /&gt;nsManager.AddNamespace(&quot;openSearch&quot;, &quot;http://a9.com/-/spec/opensearchrss/1.0/&quot;);&lt;br /&gt;&lt;br /&gt;XmlNodeList list = rss.SelectNodes(&quot;//openSearch:totalResults&quot;, nsManager);&lt;br /&gt;&lt;br /&gt;foreach (XmlNode node in list)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(node.InnerXml);&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;You can see I have to create XMLNameSpaceManager, add a namespace, remember the syntax of the query, provide the manager as a parameter…huh...too much of work. LINQ to XML says, forget about XMLNameSpaceManager, and create a fully expanded name and use it every time.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;XElement rss = XElement.Load(&quot;http://feeds.feedburner.com/feed-irfan&quot;);&lt;br /&gt;&lt;br /&gt;XNamespace ns = &quot;http://a9.com/-/spec/opensearchrss/1.0/&quot;;&lt;br /&gt;&lt;br /&gt;IEnumerable&amp;lt;XElement&amp;gt; items = rss.Descendants(ns + &quot;totalResults&quot;);&lt;br /&gt;&lt;br /&gt;foreach (XElement element in items)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(element.Value);&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;We can also take a look at how exactly we can load, create and update XML using LINQ to XML API.&lt;/p&gt;&lt;h2&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;Loading XML&lt;/span&gt;&lt;/strong&gt;&lt;/h2&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;Loading from URL:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;XElement feed = XElement.Load(&quot;http://feeds.feedburner.com/feed-irfan&quot;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;Loading from file:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;XElement file = XElement.Load(@&quot;book.xml&quot;);&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Loading from String&lt;/strong&gt;:&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;XElement document = XElement.Parse(&quot;&amp;lt;books&amp;gt;&amp;lt;book&amp;gt;&amp;lt;title&amp;gt;Essential.NET&amp;lt;/title&amp;gt;&amp;lt;author&amp;gt;Don Box&amp;lt;/author&amp;gt;&amp;lt;author&amp;gt;Chris Sells&amp;lt;/author&amp;gt;&amp;lt;publisher&amp;gt;Addison-Wesley&amp;lt;/publisher&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/books&amp;gt;&quot;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Loading from a reader: &lt;/strong&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;using (XmlReader xReader = XmlReader.Create(@&quot;book.xml&quot;))&lt;br /&gt;{&lt;br /&gt;while (xReader.Read())&lt;br /&gt;{&lt;br /&gt;if (xReader.NodeType == XmlNodeType.Element)&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;XElement messages = (XElement)XNode.ReadFrom(xReader);&lt;br /&gt;Console.WriteLine(messages);&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;XDocument:&lt;/strong&gt;&lt;br /&gt;You may wonder If for every kind of load we use XElement, what is then the purpose of XDocument then? XDocument can be used whenever we require additional details about the document e.g. document type definition(DTD), document declaration etc. These are details which XElement doesn’t seem to provide.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;Creating XML &lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Functional construction key concept that&lt;em&gt; &lt;/em&gt;I mentioned above, defines the way XML is created using LINQ to XML. We have also seen above how to create an XML tree with fully qualified names. We can now take a look at how to associate a prefix with a namespace while creating an XML document.&lt;br /&gt;&lt;br /&gt;Associating prefixes is just a matter of creating an XAttribute with appropriate values in the constructor and supplying it to XElemennt prefix is going to be associated with.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;XNamespace ns = &quot;http://www.essential.net&quot;&lt;br /&gt;&lt;br /&gt;   var xml2 = new XElement(&quot;books&quot;,&lt;br /&gt;               new XElement(ns + &quot;book&quot;, new XAttribute(XNamespace.Xmlns + &quot;pre&quot;, ns),&lt;br /&gt;                   new XElement(&quot;title&quot;, &quot;Essential .NET&quot;),&lt;br /&gt;                   new XElement(&quot;author&quot;, &quot;Don Box&quot;),&lt;br /&gt;                   new XElement(&quot;publisher&quot;, &quot;Addison-Wesley&quot;)&lt;br /&gt;                )&lt;br /&gt;              );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;XML Literals&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;As I mentioned in the beginning of this post that there is something in this API exclusively for VB.NET 9.0(+) developers. It is a new offering called “&lt;strong&gt;XML Literal&lt;/strong&gt;” that enables developers to embed XML directly within VB.NET code. We have seen how to create book XML using Functional Construction above. Let’s now see how the same can be done using XML Literal:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;Dim bookXML As XElement = &amp;lt;books&amp;gt;&lt;br /&gt;                             &amp;lt;book&amp;gt;&lt;br /&gt;                                 &amp;lt;title&amp;gt;Essential .NET&amp;lt;/title&amp;gt;&lt;br /&gt;                                 &amp;lt;author&amp;gt;Don Box&amp;lt;/author&amp;gt;&lt;br /&gt;                                 &amp;lt;author&amp;gt;Chris Sells&amp;lt;/author&amp;gt;&lt;br /&gt;                                 &amp;lt;publisher&amp;gt;Addison-Wesley&amp;lt;/publisher&amp;gt;&lt;br /&gt;                             &amp;lt;/book&amp;gt;&lt;br /&gt;                         &amp;lt;/books&amp;gt;&lt;br /&gt;&lt;br /&gt;bookXML.Save(&quot;book.xml&quot;, SaveOptions.None)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Rather than creating LINQ to XML object hierarchies that represent XML, VB guys instead can define the entire XML using XML syntax. And, If they want to make it more dynamic, they can also use ASP.NET code nuggets (&amp;lt;%= %&amp;gt;) which is called “expression holes” to embed the dynamic values into XML Literals.&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt; Private Sub GetBookXML(ByVal bookName As String, ByVal publisher As String, ByVal ParamArray authors As String())&lt;br /&gt;&lt;br /&gt;Dim customAttrib = &quot;ISBN&quot;&lt;br /&gt;Dim bookXML As XElement = &amp;lt;books&amp;gt;&lt;br /&gt;                             &amp;lt;book &amp;lt;%= customAttrib %&amp;gt;=&amp;lt;%= &quot;0201734117&quot; %&amp;gt;&amp;gt;&lt;br /&gt;                                 &amp;lt;title&amp;gt;&amp;lt;%= bookName %&amp;gt;&amp;lt;/title&amp;gt;&lt;br /&gt;                                 &amp;lt;author&amp;gt;&amp;lt;%= authors(0) %&amp;gt;&amp;lt;/author&amp;gt;&lt;br /&gt;                                 &amp;lt;author&amp;gt;&amp;lt;%= authors(1) %&amp;gt;&amp;lt;/author&amp;gt;&lt;br /&gt;                                 &amp;lt;publisher&amp;gt;&amp;lt;%= publisher %&amp;gt;&amp;lt;/publisher&amp;gt;&lt;br /&gt;                             &amp;lt;/book&amp;gt;&lt;br /&gt;                         &amp;lt;/books&amp;gt;&lt;br /&gt;&lt;br /&gt;bookXML.Save(&quot;book.xml&quot;, SaveOptions.None)&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:large;&quot;&gt;XML Axis Properties &lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Another unique feature which is available only in VB.NET 9.0 is “&lt;strong&gt;XML Axis properties&lt;/strong&gt;”, which allows XML axis methods to be called using more compact syntax. Let’s take a look at those properties&lt;/p&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;Child Axis Property&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;This property allows all the child elements to return with a particular name. For example, I am looking for &amp;lt;author&amp;gt; element in my book XML. Using Child Axis Property I can directly say:&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;Dim authorName as String = bookXML.&amp;lt;book&amp;gt;.&amp;lt;author&amp;gt;(0).Value &lt;/pre&gt;&lt;br /&gt;And, If you are interested in all the authors:&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;Dim authors As IEnumerable(Of XElement) = bookXML.&amp;lt;book&amp;gt;.&amp;lt;author&amp;gt;&lt;br /&gt;Dim authors As List(Of String) = (From author As XElement In authors _&lt;br /&gt;                                 Select author.Value).ToList()  &lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;Descendent Axis Property &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;It returns all the decedent elements that have the qualified name that is specified within the angle brackets. To see how it works, we’ll use the XML we produced using GetBookXML() method in XML Literal section explained above as input.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;Dim elements As IEnumerable(Of XElement) = bookXML. . .&amp;lt;title&amp;gt;.Where(Function(t) CInt(t.@ISDN) &amp;gt; 1)&lt;br /&gt;For Each e As XElement In elements&lt;br /&gt;Console.WriteLine(e.Value)&lt;br /&gt;Next&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size:medium;&quot;&gt;Attribute Axis Property&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;This property returns the string value of the attribute that has the qualified name that is specified after the “@” character.&lt;br /&gt;We have already seen an example of this property in the previous “Descendent property” section where we tried to get all the book titles by providing their ISDN property values to the WHERE clause.&lt;br /&gt;Another example could be a tiny piece of code that returns all the ISDN number in the entire bookXML document that we saved earlier.&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;Dim ISDNList As New List(Of String)&lt;br /&gt;Dim elements As IEnumerable(Of XElement) = bookXML. . .&amp;lt;title&amp;gt;&lt;br /&gt;&lt;br /&gt;For Each e As XElement In elements&lt;br /&gt;   ISDNList.Add(e.@ISDN.Value)&lt;br /&gt;Next&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;XML axis properties help a great deal in searching in XML documents. By having this shorthand syntax for accessing the primary XML axes, Visual Basic developers can stay focused on the XML they are trying to consume. As I said earlier, for the developers who deal with XML everyday, learning and understanding XPath is not a problem. However, for those like me who use XML rarely, Axis properties being a no-brainer has more attraction.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/3728780427700206998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/07/linq-to-xml-brings-new-reasons-to-use.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3728780427700206998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3728780427700206998'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/07/linq-to-xml-brings-new-reasons-to-use.html' title='LINQ to XML ― brings new reasons to use more XML'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-4042031986806972840</id><published>2010-06-24T12:11:00.001-07:00</published><updated>2010-07-12T12:54:29.481-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Google dictionary tooltip – a cool thing</title><content type='html'>&lt;p&gt;Have you ever seen something on the internet that surprised you a great deal? I saw something cool today that made me realize that there are companies out there like &lt;a href=&quot;http://en.wikipedia.org/wiki/Google&quot; target=&quot;_blank&quot;&gt;Google©&lt;/a&gt; that do clever things in their work even if it is a very small thing. I am talking about &lt;a href=&quot;https://chrome.google.com/extensions/detail/mgijmajocgfcbeboacabfgobmjgjcoja&quot; target=&quot;_blank&quot;&gt;Google dictionary extension for chrome&lt;/a&gt; which employs some cool techniques to render the tooltip arrow. I have seen a couple of tooltip implementations online like on &lt;a href=&quot;http://en.wikipedia.org/wiki/LinkedIn&quot; target=&quot;_blank&quot;&gt;LinkedIn®&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Twitter&quot; target=&quot;_blank&quot;&gt;Twitter&lt;/a&gt;, but all they do is use an image for the arrow and sometimes complete tooltip balloon as an image. What caught my attention in Google Dictionary balloon was the use of simple plain html divs, and after I dug deeper, I realized there is no magic going on in there. Check this out.&lt;/p&gt;  &lt;p&gt;Using chrome on a Wikipedia page for “&lt;em&gt;Programmer”, &lt;/em&gt;I look up the meaning of this terminology in Google dictionary.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOtPviJgzI/AAAAAAAAAv0/rwBhDEHxli4/s1600-h/img0119.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-01&quot; border=&quot;0&quot; alt=&quot;img-01&quot; src=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtQ_GvMII/AAAAAAAAAv4/yyT5bSjIeY8/img01_thumb13.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;213&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;I do an “&lt;em&gt;Inspect element” &lt;/em&gt;to see what styles arrows has.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtSBRKO2I/AAAAAAAAAv8/n23F2zofLwk/s1600-h/img0213.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-02&quot; border=&quot;0&quot; alt=&quot;img-02&quot; src=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOtUfCibnI/AAAAAAAAAwA/t9ceqwdyffQ/img02_thumb11.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;342&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The div I am interested in is next to the div with class “&lt;em&gt;gd-bubble&lt;/em&gt;”, which is just a container for two inner divs which are creating the arrow effect. If you click the second inner div of this container, you can get all the styles. In order to figure out what exactly is happening there, I give some different colors to its borders (left,right and top). &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtV_fjkjI/AAAAAAAAAwE/s_5Fom-6Vn4/s1600-h/img047.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-04&quot; border=&quot;0&quot; alt=&quot;img-04&quot; src=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOtXQ_6q2I/AAAAAAAAAwI/cEGwgyxHxEA/img04_thumb5.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;334&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As soon as I give the colors, it (second inner div) will look like this:&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;font color=&quot;#5588aa&quot;&gt;&lt;/font&gt;&lt;/u&gt;&lt;a href=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOtZJlf9UI/AAAAAAAAAwM/LHL_aQ-xhmM/s1600-h/img037.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-03&quot; border=&quot;0&quot; alt=&quot;img-03&quot; src=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtbBAW-lI/AAAAAAAAAwQ/FgNpboIJvmc/img03_thumb5.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;210&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next, in addition to border colors, I now try to change its height and width and see what happens.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtc8XXPLI/AAAAAAAAAwU/fxj-R8v7Idg/s1600-h/img054.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-05&quot; border=&quot;0&quot; alt=&quot;img-05&quot; src=&quot;http://lh4.ggpht.com/_Imdc9xCpgf0/TCOtroUeF2I/AAAAAAAAAwc/TGYYI8t7YzI/img05_thumb2.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;285&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It is now time to touch the first inner div as well. We give a green color to its top border (border-top) in order to distinguish it from its sibling (second inner div). The result I get is this:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOttaZebLI/AAAAAAAAAwg/8dQ_WlG8csY/s1600-h/img064.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-06&quot; border=&quot;0&quot; alt=&quot;img-06&quot; src=&quot;http://lh4.ggpht.com/_Imdc9xCpgf0/TCOtu3XhsoI/AAAAAAAAAwk/GPFEHASDvLs/img06_thumb2.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;300&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;To my surprise, the tooltip arrow is nothing but just a box with its bottom border (border-bottom) stripped off. Now, In order to give it an arrow shape, what I have to do is reduce its width to zero.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/_Imdc9xCpgf0/TCOtwNKF9hI/AAAAAAAAAwo/Du_RfPhWkiw/s1600-h/img074.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-07&quot; border=&quot;0&quot; alt=&quot;img-07&quot; src=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtxvDcM5I/AAAAAAAAAws/xegnswpL6ZM/img07_thumb2.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;300&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;And, changed the height to “&lt;em&gt;auto”.&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;u&gt;&lt;font color=&quot;#5588aa&quot;&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOtyaVimKI/AAAAAAAAAww/WqZ9DqUEnlw/s1600-h/img084.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-08&quot; border=&quot;0&quot; alt=&quot;img-08&quot; src=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtzbGhZYI/AAAAAAAAAw0/YxeMsFnzK4g/img08_thumb2.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;259&quot; /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now change the border colors of the second inner div back to “&lt;em&gt;transparent&lt;/em&gt;”.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_Imdc9xCpgf0/TCOt0QqF1DI/AAAAAAAAAw4/ws1GQ1j557M/s1600-h/img099.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;img-09&quot; border=&quot;0&quot; alt=&quot;img-09&quot; src=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOt1un1owI/AAAAAAAAAw8/okMMFQ2y4DM/img09_thumb5.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;232&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As well as change the border-top color of the first inner div back to “&lt;em&gt;transparent” &lt;/em&gt;and there I go. What I get is not a multi-color box, but a nice tooltip arrow pointing downwards.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/_Imdc9xCpgf0/TCOt23sFx6I/AAAAAAAAAxA/x4jAVOgl36I/s1600-h/Untitled104.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;Untitled-10&quot; border=&quot;0&quot; alt=&quot;Untitled-10&quot; src=&quot;http://lh3.ggpht.com/_Imdc9xCpgf0/TCOt4FbzQMI/AAAAAAAAAxE/la4VzuFG2GE/Untitled10_thumb2.jpg?imgmax=800&quot; width=&quot;429&quot; height=&quot;242&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I know tooltip is not a big thing, but the point is that at times even the smallest thing can make a big difference in the performance of the site. It doesn’t imply at all that using an image will slow down the rendering of the page for the image can be cached, but when I can use native html to accomplish something, then why not.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/4042031986806972840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/06/google-dictionary-tooltip-cool-thing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4042031986806972840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4042031986806972840'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/06/google-dictionary-tooltip-cool-thing.html' title='Google dictionary tooltip – a cool thing'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/_Imdc9xCpgf0/TCOtQ_GvMII/AAAAAAAAAv4/yyT5bSjIeY8/s72-c/img01_thumb13.jpg?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-689422616758989788</id><published>2010-06-19T02:10:00.001-07:00</published><updated>2010-07-15T14:48:49.608-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><title type='text'>Commonly used JQuery methods and snippets</title><content type='html'>&lt;p&gt;It’s been a long time since I have written anything on my blog. I seriously feel that it is turning into an “update-only-when-I-have-time” kind of thing. I don’t like it, but can’t do anything. That’s the way life goes. Anyways, there is something I have to say about JQuery. I am very much impressed with it and the way it is making everybody’s life easier. It is like the social networking fever in the software development industry where everybody seems to be talking about JQuery, its plug-ins and trying to find new ways to use it in one way or the other. It is a good thing. I also use it whenever I see even a little room to insert JavaScript in web applications. I can’t recall when was the last time I used&amp;nbsp; &lt;a href=&quot;http://www.w3schools.com/jsref/met_doc_getelementbyid.asp&quot; target=&quot;_blank&quot;&gt;document.getElementById()&lt;/a&gt;:). JQuery is taking over the world. All we need to do is to keep up with its pace if we want to get ahead in web development business.&lt;/p&gt; &lt;p&gt;The thing which bothers me more than anything else whenever I use JQuery is the fact that it’s all scattered. A small number of commonly used JQuery methods are being used everywhere repeatedly without change. This is definitely not a problem with JQuery, but with me as I am a long time fan of putting all the JavaScript dirty stuff in one file. I guess the same can’t be achieved with JQuery for its methods are tightly coupled with the HTML elements on the page.&lt;/p&gt; &lt;p&gt;One might think what I am trying to achieve here. My intention is to have all the JQuery methods in one place so that I can come back to them whenever I need them. I know the JQuery documentation is there exactly for this purpose, but I guess that documentation is not &lt;em&gt;control-driven&lt;/em&gt; rather &lt;em&gt;functionality driven&lt;/em&gt;. For example if I am using a Dropdown control on my page and using JQuery want to find out its selected value, I have to undergo the same struggle I went the last time in order to figure out all the possible methods I can use to accomplish the task. How about creating a &lt;em&gt;control driven&lt;/em&gt; JQuery wrapper that will wrap the functionality of JQuery library core methods? err…that was just of the top of my head.&lt;/p&gt; &lt;p&gt;May be my thinking is not legitimate and it is just a matter of spending more time around JQuery and I will start memorizing every bit of it. May be. Anyways, for the time being, I have decided to help myself by compiling a small list of JQuery methods I HAVE USED SO FAR in different scenarios in order to commit it to my memory. This list will be updated with more methods in future as I use them.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;Checkbox list has at least one item CHECKED (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/length/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.length()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;if ($(&quot;div.container input:checked&quot;).length == 0)&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;CHECK/UNCHECK a Checkbox (.&lt;/strong&gt;&lt;strong&gt;&lt;a href=&quot;http://api.jquery.com/attr/#attr2&quot; target=&quot;_blank&quot;&gt;attr(name,value)&lt;/a&gt; / &lt;a href=&quot;http://api.jquery.com/removeAttr/&quot; target=&quot;_blank&quot;&gt;.removeAttr(name)&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;if ($(&quot;input:checkbox&quot;).attr(&quot;checked&quot;) == true)&lt;br&gt;$(&quot;input:checkbox&quot;).removeAttr(&quot;checked&quot;);&lt;br&gt;else&lt;br&gt;$(&quot;input:checkbox&quot;).attr(&quot;checked&quot;, &quot;checked&quot;);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Dropdown list has a SELECTED item (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/val/#val1&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.val()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;if ($(&quot;div.container select.dropdownlist&quot;).val() != -1)&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;VALUE of the Selected Checkbox (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/attr/#attr1&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.attr()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;div.container input:checked&quot;).attr(&quot;value&quot;); &lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;TEXT between &amp;lt;SPAN&amp;gt; and &amp;lt;/SPAN&amp;gt; (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/html/#html1&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;html()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;div.container input:checked&quot;).find(&quot;span&quot;).html();&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Setting the VALUE of a Textbox or a Hidden field (&lt;a href=&quot;http://api.jquery.com/val/#val2&quot; target=&quot;_blank&quot;&gt;.val(value)&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;div.container&quot;).siblings(&quot;#&amp;lt;%=hSelectedItem.ClientId%&amp;gt;&quot;).val(selectedVal);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Getting a STYLE property from first matched element (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/css/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.css()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;if ($(this).siblings(&#39;.container).css(&quot;display&quot;) == &#39;none&#39;)) &lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Animating the element OPACITY&amp;nbsp; (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/fadeIn/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.fadeIn()&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;&lt;strong&gt;/ &lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/fadeOut/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.fadeOut()&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br&gt;examples: &lt;pre class=&quot;brush: javascript&quot;&gt;$(this).siblings(&#39;.itemlist&#39;).fadeIn(200);     &lt;br&gt;$(this).siblings(&#39;.itemlist&#39;).fadeOut(200);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Switching between EXPAND and COLLAPSE images (&lt;a href=&quot;http://api.jquery.com/attr/#attr2&quot; target=&quot;_blank&quot;&gt;.attr(name,value)&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(this).children(&quot;img&quot;).attr(&quot;src&quot;, &#39;&amp;lt;%=ImagePath%&amp;gt;Collapse.png&#39;);&amp;nbsp; &lt;br&gt;$(this).children(&quot;img&quot;).attr(&quot;src&quot;, &#39;&amp;lt;%=ImagePath%&amp;gt;Expand.png&#39;);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Changing the CSS CLASS NAME (&lt;/strong&gt;&lt;a href=&quot;http://api.jquery.com/addClass/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;.addClass(name)&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(this).addClass(&quot;selected&quot;);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Creating the &amp;lt;OPTGROUP&amp;gt;s in an ASP.NET Dropdown list (&lt;a href=&quot;http://api.jquery.com/wrapAll/&quot; target=&quot;_blank&quot;&gt;.wrapAll()&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;I did I blog post &lt;a href=&quot;http://irfaann.blogspot.com/search/?q=OPTGROUP&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; about it a while ago where I have shown how &amp;lt;OPTGROUP&amp;gt;s can be created in an ASP.NET Dropdown list using just two lines of JQuery code. &lt;br&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;select.dropdownlist option[@type=&#39;1&#39;]&quot;).wrapAll(&#39;&amp;lt;optgroup label=&quot;Level1&quot;&amp;gt;&#39;); &lt;br /&gt;$(&quot;select.dropdownlist option[@type=&#39;2&#39;]&quot;).wrapAll(&#39;&amp;lt;optgroup label=&quot;Level2&quot;&amp;gt;&#39;);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Getting a COMMA SEPERATED LIST of VALUES of selected Checkboxes (&lt;a href=&quot;http://api.jquery.com/serializeArray/&quot; target=&quot;_blank&quot;&gt;.SerializeArray()&lt;/a&gt;&lt;b&gt;)&lt;/b&gt; &lt;br&gt;&lt;/strong&gt;The below small function makes use of JQuery .SerializeArray() method which returns form elements as an array of name/value pair. Each element’s value will then be pushed into another array and returned as a comma separated string. &lt;br&gt;&lt;pre class=&quot;brush: javascript&quot;&gt;function GetSelectedApplicants()     &lt;br&gt;{     &lt;br&gt;  var fields = $(&quot;tr td input:checkbox:checked&quot;).serializeArray();     &lt;br&gt;  $.each(fields, function(i, field)     &lt;br&gt;  {     &lt;br&gt;    selectedApplicants.push(field.value);     &lt;br&gt;  });    &lt;br&gt;  return selectedApplicants.join(&#39;,&#39;);     &lt;br&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Creating a DYNAMIC TOOLTIP containing the data from ASP.NET web server. (&lt;a href=&quot;http://api.jquery.com/jQuery.ajax/&quot; target=&quot;_blank&quot;&gt;.ajax()&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;I wanted to create a fancy dynamic tooltip like the one on LinkedIN® and Google Dictionary Lookup in Chrome. I ended up using JQuery .ajax() method which is calling ASP.NET server-side function asynchronously and after retrieving the data populating the tooltip container with HTML elements around the data. &lt;br&gt;&lt;pre class=&quot;brush: javascript&quot;&gt;function GetItemList(item, appID) &lt;br /&gt;{   &lt;br&gt;$.ajax({     &lt;br&gt;type: &quot;POST&quot;,     &lt;br&gt;url: &quot;ListApplicants.aspx/GetFolderList&quot;,     &lt;br&gt;data: &quot;{id: &quot; + appID + &quot;}&quot;,     &lt;br&gt;contentType: &quot;application/json; charset=utf-8&quot;,     &lt;br&gt;dataType: &quot;json&quot;,     &lt;br&gt;success: function(msg)     &lt;br&gt;{     &lt;br&gt;  //hiding the loading bar once the resluts has been retrived.     &lt;br&gt;  item.parent().children(&quot;.loadingbar&quot;).css(&quot;display&quot;, &quot;none&quot;);     &lt;br&gt;  item.parent().append(    &lt;br&gt;  &#39;&amp;lt;div class=&quot;toolTipWrapper&quot;&amp;gt;&#39;    &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &#39;&amp;lt;div class=&quot;closex&quot; onclick=&quot;closex();&quot;&amp;gt;[x]&amp;lt;/div&amp;gt;&#39;    &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; + msg.d    &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &#39;&amp;lt;div class=&quot;arrowContainer&quot;&amp;gt;&#39;    &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &#39;&amp;lt;div class=&quot;arrowInner&quot;&amp;gt;&amp;lt;/div&amp;gt;&#39;    &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &#39;&amp;lt;div class=&quot;arrowOuter&quot;&amp;gt;&amp;lt;/div&amp;gt;&#39;    &lt;br&gt;+ &#39;&amp;lt;/div&amp;gt;&#39;     &lt;br&gt;+ &#39;&amp;lt;/div&amp;gt;&#39;     &lt;br&gt;)    &lt;br&gt;}     &lt;br&gt;});   &lt;br&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Clearing the TEXT field on focus (&lt;a href=&quot;http://api.jquery.com/focus/&quot; target=&quot;_blank&quot;&gt;.focus()&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;Sometimes we need to display a default text in the textbox like “Click here to search” or “email address” to inform the user what needs to go in the textbox. The below snippet makes it easier for us to clear the text as soon as the user clicks on the textbox to type something.&lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;input.text&quot;).focus( function() {     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $(this).val() == &#39;(email address)&#39; || $(this).val() == &#39;Site Search...&#39; )     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(this).val(&#39;&#39;);&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;} ); &lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Selecting an element which does NOT have a particular stylesheet. (&lt;a href=&quot;http://api.jquery.com/not-selector/&quot; target=&quot;_blank&quot;&gt;:not()&lt;/a&gt;) &lt;br&gt;&lt;/strong&gt;example: &lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;div.container div p:not(.quote)&quot;).css(&#39;display&#39;, &#39;none&#39;);&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Appending the content of an element to the end of another element (&lt;a href=&quot;http://api.jquery.com/append/&quot; target=&quot;_blank&quot;&gt;.append()&lt;/a&gt;)&lt;/strong&gt;&lt;br&gt;example:&lt;pre class=&quot;brush: javascript&quot;&gt;$(&quot;td.column&quot;).append($(&quot;div.row&quot;).contents());&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;Honestly, I have no intension to write another JQuery documentation, but at times it makes a lot of sense to have everything we have used so far in one place, specially if it is just one group of things being repeated again and again. The ultimate goal is to scribble down the way I have used JQuery methods with web/HTML controls.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/689422616758989788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/06/commonly-used-jquery-methods-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/689422616758989788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/689422616758989788'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/06/commonly-used-jquery-methods-and.html' title='Commonly used JQuery methods and snippets'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-5314082850897433311</id><published>2010-03-12T14:39:00.001-08:00</published><updated>2010-03-15T12:57:12.952-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="User Controls"/><title type='text'>Should it be a user control or a server control?</title><content type='html'>&lt;p&gt;You must have heard this question in the developer community or in online forums, or at least at your work place. Though, the concept of user and server controls in .NET is pretty old, some developers still get confused when it comes to making a choice between both of them. I myself used to go wrong with the selection and would pick one over the other, mainly because of a very thin line (ok ok..I heard you..a little thick) between them.&lt;/p&gt;  &lt;p&gt;Up until now, I was fond of using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.aspx&quot; target=&quot;_blank&quot;&gt;UserControl&lt;/a&gt; for all of my projects. The ratio of picking a user control over server control always used to be somewhere close to 10:1 (probabilistically, 1.0 to 0.1) for me. However, it was then when I received a comment for my experimental work on Code Project article &lt;a title=&quot;Multiselect Drodown Control&quot; href=&quot;http://www.codeproject.com/KB/user-controls/Multiselect-Dropdown.aspx&quot; target=&quot;_blank&quot;&gt;MultiSelect Dropdown Control&lt;/a&gt; about my decision being an unthoughtful over choosing a UserControl as the parent class, I decided to enlighten myself more about both the control types and find out why I feel it a thin line what is a very clear distinction, and why I fail to take their design guidelines into account when it comes to authoring them.&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;I believe one of the important reasons to go for a user control is its simplistic nature. It can be created as easily as a web page and Its design time development support for authoring makes things a lot easier. We don’t need to override the Render() method as we get out-of-the-box support for rendering. A user control is more suitable choice when target control is composite (a collection of other intrinsic controls) in nature and has a lot of static data. On the downside, it is less convenient for advanced scenarios due to its tight coupling with the application it is built for. If the same user control needs to be used in more than one application, it introduces redundancy and maintenance problems as its source form (.ascx) needs be copied and its reference must be provided on the hosting web page. We don’t get to see this kind of problem while dealing with server controls. A server control can be a best choice in the following scenarios:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Redistributable &lt;/li&gt;    &lt;li&gt;Dynamically generated content&lt;br /&gt;&lt;/li&gt;    &lt;li&gt;zero maintenance ― single DLL which can also be added in the GAC &lt;/li&gt;    &lt;li&gt;Support to add the control in Visual Studio Toolbox. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A server control helps reduce redundancy as it is only a single DLL which can very easily be consumed in more than one application. According to &lt;a href=&quot;http://support.microsoft.com/kb/893667&quot; target=&quot;_blank&quot;&gt;Microsoft Support&lt;/a&gt; &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&quot;A server control is more suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Server controls provide full design-time support when used in a design-time host. It can be added to the toolbox of a visual designer and dragged and dropped onto a page. However, I believe the biggest disadvantage of using a server control is that, it requires to be written from the scratch for which one has to have a good understanding of page lifecycle and the order in which events execute which is normally taken care of in user controls.&lt;/p&gt;  &lt;p&gt;Now, coming back to the title of my post &quot;what should we choose&quot;, a user control or a server control? I would say such a decision should be a thoughtful one. If you want rapid application development (RAD) with full design time support without understanding the page life cycle, user control is the way to go. On the other hand, If ease of deployment with no redundancy and maintenance headaches is more important for you, think about custom server control. &lt;/p&gt;  &lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/5314082850897433311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/03/should-it-be-user-control-or-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5314082850897433311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5314082850897433311'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/03/should-it-be-user-control-or-server.html' title='Should it be a user control or a server control?'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-4286035539666004509</id><published>2010-02-27T11:14:00.000-08:00</published><updated>2010-02-28T11:33:07.979-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="User Controls"/><title type='text'>Creating User Controls ― a few good practices</title><content type='html'>&lt;p&gt;In my previous post, &lt;a href=&quot;http://irfaann.blogspot.com/2010/01/dealing-with-gac-atrocities.html&quot; target=&quot;_blank&quot;&gt;Dealing with GAC atrocities&lt;/a&gt;, I talked about code reusability being an important aspect of rapid application development (&lt;a href=&quot;http://en.wikipedia.org/wiki/Rapid_application_development&quot; target=&quot;_blank&quot;&gt;RAD&lt;/a&gt;).  &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.aspx&quot; target=&quot;_blank&quot;&gt;User Controls&lt;/a&gt; in .NET support code reusability out of the box. Just to remind ourselves,  a user control is a control that is created using the same technique we use for creating ASP.NET web pages. We create user controls every now and then in our everyday programming and, at times, we forget to entertain some of its important aspects during the development. For example exposing properties that define its behavior and layout , taking care of the situation where a web page can have multiple instances of a user control etc.&lt;/p&gt;  &lt;p&gt;As you probably know that I love to follow the guidelines and like to stick to the checklist whenever possible. I decided to create one for myself containing good practices for user control development. The idea is to come back to this list to see what should go in the user control and what should not. Though, these are not industry standard best practices, I find them very useful in most of the scenarios. Please have a look and let me know what do you have to say about it. Moreover, If there is anything, a procedure, a guideline or even a practice that you think helps you in anyway while writing a user control and saves your time, share it with the world in the comments below.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Every single behavior  of a user control should be represented by a public property. More the properties it has, the more it is customizable for the end user. I never forget to write properties that define the important characteristics of my list-type control e.g. AutoPostBack.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Private _AutoPostback As Boolean&lt;br /&gt;  Public Property AutoPostback() As Boolean&lt;br /&gt;      Get&lt;br /&gt;          Return _AutoPostback&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As Boolean)&lt;br /&gt;          _AutoPostback = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;br /&gt;&lt;br /&gt;  Private _AllowParentSelect As Boolean&lt;br /&gt;  Public Property AllowParentSelect() As Boolean&lt;br /&gt;      Get&lt;br /&gt;          Return _AllowParentSelect&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As Boolean)&lt;br /&gt;          _AllowParentSelect = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;There will always be only one instance of a user control on a web page is a blind assumption. If the user control looks good and is designed to keep the user friendliness and intuitiveness in mind, people would love to use it than once, sometimes on the same page which might lead to a conflict between their child control IDs.  To deal with it, ClientID property can be used in the HTML as well as in the back end.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;If AutoPostback = True AndAlso Request.Form(&quot;__EVENTTARGET&quot;) IsNot _&lt;br /&gt;              Nothing AndAlso Request.Form(&quot;__EVENTTARGET&quot;).Equals(Me.ClientID + &quot;_categoryMenu&quot;) Then&lt;br /&gt;&lt;br /&gt;                  RaiseEvent OnSelectedIndexChanged(Me, Nothing)&lt;br /&gt;&lt;br /&gt;              End If&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;All the external script files (JavaScript etc.) should always be registered using Page.ClientScript.&lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptinclude.aspx&quot;&gt;RegisterClientScriptInclude&lt;/a&gt; and Page.ClientScript.&lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/255xet9e.aspx&quot;&gt;IsClientScriptIncludeRegistered&lt;/a&gt; method to avoid registering duplicate scripts resources for multiple instances of user control on a page.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Private Sub RegisterClientScriptIncludes()&lt;br /&gt;&lt;br /&gt;      Dim clientScriptMgr As ClientScriptManager = Me.Page.ClientScript&lt;br /&gt;&lt;br /&gt;      If clientScriptMgr.IsClientScriptIncludeRegistered(Me.GetType(), &quot;mcDropdown&quot;) = False Then&lt;br /&gt;          clientScriptMgr.RegisterClientScriptInclude(Me.GetType(), &quot;mcDropdown&quot;, ClientScriptIncludePath)&lt;br /&gt;      End If&lt;br /&gt;&lt;br /&gt;  End Sub&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;The user control should have no knowledge (no hard-coding), unless required, of any project/application-wide configurations e.g. resource (image/script) file path, connection strings, database column names of the supplied data source, default values etc. We can maintain the abstractness of a control by passing all these values from the page as properties.&lt;br /&gt;&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Private _DropdownListStyles As String&lt;br /&gt;  Public Property DropdownListStyles() As String&lt;br /&gt;      Get&lt;br /&gt;          Return _DropdownListStyles&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As String)&lt;br /&gt;          _DropdownListStyles = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;br /&gt;&lt;br /&gt;  Private _DataTextField As String&lt;br /&gt;  Public Property DataTextField() As String&lt;br /&gt;      Get&lt;br /&gt;          Return _DataTextField&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As String)&lt;br /&gt;          _DataTextField = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;br /&gt;&lt;br /&gt;  Private _DataValueField As String&lt;br /&gt;  Public Property DataValueField() As String&lt;br /&gt;      Get&lt;br /&gt;          Return _DataValueField&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As String)&lt;br /&gt;          _DataValueField = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;There is a possibility of a user control being used on a page which does not contain any .NET default server control, hence no sign of __doPostBack JavaScript function definition which can be a serious problem if the user control has to do a PostBack. We can harness &lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getpostbackeventreference.aspx&quot;&gt;GetPostBackEventReference()&lt;/a&gt; under ClientScriptManager which returns a string that can be used in a client event to cause Postback to the server.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;There is a consistency in the property names e.g. DataSource, DataTextField, DataValueField for all ASP.NET data bound controls because of their support to the standard Windows Forms data-binding model. This helps developers gain familiarity with the control very quickly. We can try wherever possible to maintain this level of friendliness in our user control as well by keeping the property and method names as close to that of default controls.  The same goes for event names as well. For example for a user control that is going to behave like a  list-type control, we can think of having properties such as DataTextField, DataValueField, DataSource, SelectedIndex etc. and events like SelectedIndexChanged.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Private Sub ddlApplicationStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _&lt;br /&gt;                                          Handles ddlApplicationStatus.OnSelectedIndexChanged&lt;br /&gt;      Try&lt;br /&gt;&lt;br /&gt;          Dim ctlDropdown As mcDropdown = CType(sender, mcDropdown)&lt;br /&gt;          Dim selectedVal As Integer = ctlDropdown.SelectedValue&lt;br /&gt;          Dim selectedText As String = ctlDropdown.SelectedText&lt;br /&gt;&lt;br /&gt;      Catch ex As Exception&lt;br /&gt;          &#39;log exception here...&lt;br /&gt;      End Try&lt;br /&gt;&lt;br /&gt;  End Sub&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;In addition to method and events, a list-type user control should also expose  ListItemCollection that gives complete control of the items and facilitates  adding, inserting, removing and finding items.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We need to make sure the control is able to maintain its state on PostBacks. It goes in line with the best practice of loading controls when the page is being rendered for the first time.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt; If Not Me.IsPostBack Then&lt;br /&gt;              InitializeUserControls()&lt;br /&gt;          End If&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Instead of inheriting our control class directly from System.Web.UI.UserControl class every time, we should first look for an abstract class if it is available that defines the same properties, methods, and events common that we need for our user control. For example &lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.aspx&quot;&gt;ListControl&lt;/a&gt; class can be served as the abstract class for all list-type controls  and &lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.databoundcontrol.aspx&quot;&gt;DataBoundControl&lt;/a&gt; class for the controls that display their data in list of tabular form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The default values should be specified for the control properties, hence allowing the user to get the control up and running in very little time.&lt;/li&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Private _AllowParentSelect As Boolean&lt;br /&gt;  Public Property AllowParentSelect() As Boolean&lt;br /&gt;      Get&lt;br /&gt;          Return _AllowParentSelect&lt;br /&gt;      End Get&lt;br /&gt;      Set(ByVal value As Boolean)&lt;br /&gt;          _AllowParentSelect = value&lt;br /&gt;      End Set&lt;br /&gt;  End Property&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/ol&gt;&lt;p&gt;HTH,&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/4286035539666004509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/02/creating-user-controls-few-good.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4286035539666004509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4286035539666004509'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/02/creating-user-controls-few-good.html' title='Creating User Controls ― a few good practices'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-1707775864206262564</id><published>2010-01-31T13:46:00.000-08:00</published><updated>2010-01-31T14:05:07.909-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>Dealing with GAC atrocities</title><content type='html'>Code reusability is one of the important pillars of Object Oriented programming (&lt;a target=&quot;_new&quot; href=&quot;http://en.wikipedia.org/wiki/Object-oriented_programming&quot;&gt;OOP&lt;/a&gt;). I like this feature a lot as It doesn&#39;t make sense to write a crucial piece of code again and again and in multiple places, which is actually being shared across applications. Why not to write it once and reuse it everywhere. Classes in OOP can be a very good example of this, which can be written once and used as many times as we want by initializing them as objects.&lt;br /&gt;&lt;br /&gt;Anyone, who works with Visual Studio knows that referencing an assembly in the project paves the way towards code reusability. On the other hand, in order to achieve this same thing while in the production environment, we need to install assemblies in the Global Assembly Cache(&lt;a target=&quot;_new&quot; href=&quot;http://en.wikipedia.org/wiki/Global_Assembly_Cache&quot;&gt;GAC&lt;/a&gt;) . There are a lot of advantages of using GAC as a shared repository, but this post is not an effort towards that as there are a bunch of articles already available on the internet. What I want to share here are the concerns which I have listed below, which may come to minds before deciding on to go down this route of using GAC for our projects.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Let&#39;s consider a scenario where we want to share a DLL say ExceptionHandler.dll between two applications HelloWorld and HelloUniverse. We have signed the assembly (DLL) using a strong name key and installed it in the GAC on the production server so that it would be utilized by both the applications. We have deployed the applications where they seem to be accessing the DLL from GAC. So far so good. Now assuming, the ClassLibrary project (ExceptionHandler.dll) is part of a solution which also contains either of the applications let&#39;s say HelloWorld, there is a possibility while building the application someone from the team can unintentionally do a FULL Debug of the solution, leaving the version number (build + revision) changed. Now, a week later our HelloUniverse  application which is also pointing to the same DLL project undergoes a change and is deployed alone to the server assuming it will pick the same DLL that was deployed earlier and eventually he gets this:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Could not load file or assembly &#39;ExceptionHandler, Version=3.1.65.66, Culture=neutral, PublicKeyToken=a2e77a5f9a0ce598&#39; or one of its dependencies. The system cannot find the file specified.&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Let&#39;s assume for the time being that the situation above will never happen as there is no room for an unintentional behavior in your team. But, You will agree with me on the fact that using GAC as a shared repository motivates one towards having multiple versions of the same DLL as there is a native support for that. When it was designed to overcome problems like &lt;a target=&quot;_new&quot; href=&quot;http://en.wikipedia.org/wiki/DLL_hell&quot;&gt;DLL HELL&lt;/a&gt;, then why not to use it.  It is a very valid point to support applications still relying on the older version. One of the concerns is that if I come back to my GAC after a year, I will find it cluttered with multiple copies of the DLL with same name but with different version numbers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;If the above scenario proves to be true, will it not become a manageability issue to keep a track of assembly versions on both production as well as development ends considering we have a reasonably big number of applications.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;I am in no way trying to discourage anyone from using GAC, rather giving my point of view on the issues that get in our way whenever we decide to use it as a shared folder for assemblies. I may be wrong and may be these issues will never come for someone or they may not be a big concern for a few, but I believe sometimes it is good to be paranoid of implementing new technology or suggesting it over an existing one.  This may give us an opportunity to think left, right and center before we get our hands dirty with it.&lt;br /&gt;&lt;br /&gt;Before I finish,  I would like to briefly comment on the way I believe above issues can be addressed. For the first point, each application or set of applications can point to their own copy of the shared DLL leaving no room for errors. The second and the third issues can be tackled by building applications targeting a single stable version of DLL at some point in future, which then can be replaced with all of the older DLLs with multiple versions in the GAC.&lt;br /&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/1707775864206262564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2010/01/dealing-with-gac-atrocities.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/1707775864206262564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/1707775864206262564'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2010/01/dealing-with-gac-atrocities.html' title='Dealing with GAC atrocities'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-255648811132010770</id><published>2009-12-29T21:07:00.000-08:00</published><updated>2009-12-29T21:10:32.927-08:00</updated><title type='text'>Live Online SharePoint Saturday - EMEA (Free)</title><content type='html'>To all ya SharePoint ppl. based in EMEA region:&lt;br /&gt;&lt;br /&gt;&lt;a target=&quot;_new&quot; href=&quot;http://20100123-spsemea.eventbrite.com/&quot;&gt;Live Online SharePoint Saturday - EMEA&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/255648811132010770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/12/live-online-sharepoint-saturday-emea.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/255648811132010770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/255648811132010770'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/12/live-online-sharepoint-saturday-emea.html' title='Live Online SharePoint Saturday - EMEA (Free)'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-6262306862803383324</id><published>2009-12-21T07:48:00.001-08:00</published><updated>2009-12-26T12:41:01.926-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><title type='text'>ASP.NET DropdownList with &amp;lt;optgroup&amp;gt;</title><content type='html'>If you are looking for an easy and simplest solution to create groups in the ASP.NET DropdownList control without writing unnecessary amount of backend code, then you are at the right place. Let me show you how we can do this using JQuery 1.2.6.&lt;br /&gt;&lt;br /&gt;I have divided the solution into two different parts. First part explains achieving the desired output using JQuery&#39;s native support for wrapping elements into other elements with the help of wrapAll() method. It takes only 1 line of code and we can have the groups created in the HTML. However, the drawback of this approach is the groups will disappear on postback. But if the DropdownList is small and we are not loading it from the database, then this approach is very suitable as it will save a lot of time and effort.&lt;br /&gt;&lt;br /&gt;Ok, enough of the riff-raff and get down to business now. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Part 01 (static binding of list items with no support for postback)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;font-style:italic;&quot;&gt;Step 01: Creating a DropdownList&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;br /&gt; ListItemCollection list = new ListItemCollection();&lt;br /&gt;&lt;br /&gt;            list.Add(new ListItem(&quot;1&quot;, &quot;1&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;2&quot;, &quot;2&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;3&quot;, &quot;3&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;4&quot;, &quot;4&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;5&quot;, &quot;5&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;6&quot;, &quot;6&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;7&quot;, &quot;7&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;8&quot;, &quot;8&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;9&quot;, &quot;9&quot;));&lt;br /&gt;            list.Add(new ListItem(&quot;10&quot;, &quot;10&quot;));&lt;br /&gt;&lt;br /&gt;            ddl.DataSource = list;&lt;br /&gt;            ddl.DataBind();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;font-style:italic;&quot;&gt;Step 02: Creating a new attribute&lt;/span&gt;&lt;br /&gt;We have to create a new attribute for every DropdownList item. This new attribute will be used for grouping in the JQuery code.&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;br /&gt;protected void ddl_DataBound(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            foreach (ListItem item in ((DropDownList)sender).Items)&lt;br /&gt;            {&lt;br /&gt;                if (System.Int32.Parse(item.Value) &amp;lt; 5)&lt;br /&gt;                    item.Attributes.Add(&quot;classification&quot;, &quot;LessThanFive&quot;);&lt;br /&gt;                else&lt;br /&gt;                    item.Attributes.Add(&quot;classification&quot;, &quot;GreaterThanFive&quot;);&lt;br /&gt;            }        &lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;font-style:italic;&quot;&gt;Step 03:  The fun part - Creating groups using JQuery WrapAll() method&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush:jscript&quot;&gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;        $(document).ready(function() {&lt;br /&gt;            //Create groups for dropdown list&lt;br /&gt;            $(&quot;select.listsmall option[@classification=&#39;LessThanFive&#39;]&quot;).wrapAll(&quot;&amp;lt;optgroup label=&#39;Less than five&#39;&amp;gt;&quot;);&lt;br /&gt;            $(&quot;select.listsmall option[@classification=&#39;GreaterThanFive&#39;]&quot;).wrapAll(&quot;&amp;lt;optgroup label=&#39;Greater than five&#39;&amp;gt;&quot;); &lt;br /&gt;        });&lt;br /&gt;&lt;br /&gt;    &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Part 02 (dynamic binding of list items with full support for postback)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This approach not only creates groups using JQuery 1.2.6 but also allows DropdownList to remember these groups across postbacks. We will have to create a custom server control using DropdownList class and override SaveViewState() and LoadViewState() methods that will help the page ViewState remember and restore groups respectively. &lt;br /&gt;&lt;br /&gt;As mentioned earlier, in this approach we have to create a custom server control with a bit of a backend code and override some of it&#39;s important methods. However, if you are one of those lazy developers like me who don&#39;t like the idea of creating controls specially custom server controls that reside in a separate assembly for a very tiny job such as the one in hand, then you can create control that is part of the same assembly by adding a new class file and deriving it&#39;s class from System.Web.UI.WebControls.DropDownList.  &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;br /&gt;namespace ControlLibrary&lt;br /&gt;{&lt;br /&gt;    public class DropdownList : System.Web.UI.WebControls.DropDownList&lt;br /&gt;    {&lt;br /&gt;        protected override object SaveViewState()&lt;br /&gt;        {&lt;br /&gt;            // Create an object array with one element for the CheckBoxList&#39;s&lt;br /&gt;            // ViewState contents, and one element for each ListItem in skmCheckBoxList&lt;br /&gt;            object[] state = new object[this.Items.Count + 1];&lt;br /&gt;&lt;br /&gt;            object baseState = base.SaveViewState();&lt;br /&gt;            state[0] = baseState;&lt;br /&gt;&lt;br /&gt;            // Now, see if we even need to save the view state&lt;br /&gt;            bool itemHasAttributes = false;&lt;br /&gt;            for (int i = 0; i &lt; this.Items.Count; i++)&lt;br /&gt;            {&lt;br /&gt;                if (this.Items[i].Attributes.Count &gt; 0)&lt;br /&gt;                {&lt;br /&gt;                    itemHasAttributes = true;&lt;br /&gt;&lt;br /&gt;                    // Create an array of the item&#39;s Attribute&#39;s keys and values&lt;br /&gt;                    object[] attribKV = new object[this.Items[i].Attributes.Count * 2];&lt;br /&gt;                    int k = 0;&lt;br /&gt;                    foreach (string key in this.Items[i].Attributes.Keys)&lt;br /&gt;                    {&lt;br /&gt;                        attribKV[k++] = key;&lt;br /&gt;                        attribKV[k++] = this.Items[i].Attributes[key];&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    state[i + 1] = attribKV;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            // return either baseState or state, depending on whether or not&lt;br /&gt;            // any ListItems had attributes&lt;br /&gt;            if (itemHasAttributes)&lt;br /&gt;                return state;&lt;br /&gt;            else&lt;br /&gt;                return baseState;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void LoadViewState(object savedState)&lt;br /&gt;        {&lt;br /&gt;            if (savedState == null) return;&lt;br /&gt;&lt;br /&gt;              // see if savedState is an object or object array&lt;br /&gt;              if (savedState is object[])&lt;br /&gt;              {&lt;br /&gt;                 // we have an array of items with attributes&lt;br /&gt;                 object [] state = (object[]) savedState;&lt;br /&gt;                 base.LoadViewState(state[0]);   // load the base state&lt;br /&gt;&lt;br /&gt;                 for (int i = 1; i &lt; state.Length; i++)&lt;br /&gt;                 {&lt;br /&gt;                    if (state[i] != null)&lt;br /&gt;                    {&lt;br /&gt;                       // Load back in the attributes&lt;br /&gt;                       object [] attribKV = (object[]) state[i];&lt;br /&gt;                       for (int k = 0; k &lt; attribKV.Length; k += 2)&lt;br /&gt;                          this.Items[i-1].Attributes.Add(attribKV[k].ToString(), &lt;br /&gt;                                                         attribKV[k+1].ToString());&lt;br /&gt;                    }&lt;br /&gt;                 }&lt;br /&gt;              }&lt;br /&gt;              else&lt;br /&gt;             // we have just the base state&lt;br /&gt;             base.LoadViewState(savedState);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre &gt;&lt;br /&gt;If you search on the internet for a solution to &lt;span style=&quot;font-style:italic;&quot;&gt;create &amp;lt;optgroup&amp;gt; in ASP.NET DropdownList&lt;/span&gt;, you will find some of the articles talking about overriding RenderContents() method of DropdownList to create &lt;optgroup&gt;. However, I personally feel that this job can also be done with less of  a hassle using JQuery WrapAll() method that wraps elements inside other elements. All we need is to have a mechanism to have these groups saved upon postbacks which we are doing here by overriding SaveVeiwState() and LoadViewState() as Scott Mitchell describes in his &lt;a target=&quot;_new&quot; href=&quot;http://www.4guysfromrolla.com/articles/110205-1.aspx&quot;&gt;article&lt;/a&gt;. Apart from these 2 methods, we need to populate the DropdownList in Page_Load method and create a new attribute in the ddl_DataBound() event as explained in the part 01 above. That is all required to create &amp;lt;optgroup&amp;gt;s in an ASP.NET DropdownList. You can see the output control populated with ListItems which are properly encapsulated within optiongroups below.&lt;br /&gt;&lt;br /&gt;The source code for this approach can be downloaded from &lt;a href=&quot;http://dropdownlost-with-optiongroups-for-aspnet.googlecode.com/files/Dropdown-Grouping.rar&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a target=&quot;_new&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://1.bp.blogspot.com/_Imdc9xCpgf0/Sy-_Cyy0mPI/AAAAAAAAAsA/b9vDMZsh0N8/s1600-h/dropdown-grouping.jpg&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 139px; height: 218px;&quot; src=&quot;http://1.bp.blogspot.com/_Imdc9xCpgf0/Sy-_Cyy0mPI/AAAAAAAAAsA/b9vDMZsh0N8/s400/dropdown-grouping.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5417758931465574642&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/6262306862803383324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/12/dropdownlist-control-with-grouping.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/6262306862803383324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/6262306862803383324'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/12/dropdownlist-control-with-grouping.html' title='ASP.NET DropdownList with &amp;lt;optgroup&amp;gt;'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_Imdc9xCpgf0/Sy-_Cyy0mPI/AAAAAAAAAsA/b9vDMZsh0N8/s72-c/dropdown-grouping.jpg" height="72" width="72"/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-5624716608492829985</id><published>2009-12-19T06:51:00.000-08:00</published><updated>2009-12-19T22:01:29.864-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="IE Bugs"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Watchout for getElementById bug</title><content type='html'>Being a web developer targeting IE 7, We  should be very careful with the way getElementById method behaves in IE 7. According to &lt;a target=&quot;_new&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms536437%28VS.85%29.aspx&quot;&gt;getElementById explanation on MSDN&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;blockquote style=&quot;font-style: italic;&quot;&gt;this method performs a case-insensitive match on both the &lt;strong&gt;ID&lt;/strong&gt; and &lt;strong&gt;NAME&lt;/strong&gt; attributes, which might produce unexpected results&lt;/blockquote&gt;&lt;br /&gt;We may NOT see any problem with this method as long as the ID and Name attributes of the controls on the webpage are same (which is the case most of the time). But, when values of these attributes are different e.g. while using a Master Page which mangles ID attributes by appending &quot;_&quot; and Name attribute using &quot;$&quot;, getElementById in IE 7.0 might produce unexpected results. Read more about this bug &lt;a target=&quot;_new&quot; href=&quot;http://www.sixteensmallstones.org/ie-javascript-bugs-overriding-internet-explorers-documentgetelementbyid-to-be-w3c-compliant-exposes-an-additional-bug-in-getattributes&quot;&gt;here.&lt;br /&gt;&lt;br /&gt;&lt;/a&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/5624716608492829985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/12/watchout-for-getelementbyid-bug.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5624716608492829985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5624716608492829985'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/12/watchout-for-getelementbyid-bug.html' title='Watchout for getElementById bug'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-5222091374711185498</id><published>2009-11-27T14:18:00.000-08:00</published><updated>2010-04-28T23:27:25.678-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>ThreadAbortException ― This behavior is by design</title><content type='html'>If you are coding in .NET and want to transfer  a web request from one page to another then you don’t have many options in terms of API to does that for you. You will either use Server.Redirect or Server.Transfer . The former does the client side redirection and later is responsible for server side. The problem with both of them is their dependency on Response.End which in turn calls Thread.Abort that causes ThreadAbortException (Reference: &lt;a target=&quot;_new&quot; href=&quot;http://support.microsoft.com/kb/312629/EN-US/&quot;&gt;MSDN&lt;/a&gt;). To work around this problem Microsoft suggests the followings alternatives:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Using Server.Execute instead of Server.Transfer&lt;/li&gt;&lt;li&gt;Supplying endResponse parameter to Response.Redirect method to suppress the internal call to Resonse.End&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;In case of not implementing the above will result in showing output of 2 different web pages (caller and callee) in the same web browser window. These alternatives are most likely to work 99% of the time as in general in everyday programming they are not followed by any other statement. And rightly so, why would one write something which is not meant to be executed. This implies that you are completely safe even if:&lt;br /&gt;&lt;br /&gt;1. Control comes back from Server.Execute and continues execution on the current page.&lt;br /&gt;2. Response.Redirect transfers control to the other page and due to the presence of endResponse=true parameter, it continues execution on the current page.&lt;br /&gt;&lt;br /&gt;just because we don&#39;t write any database processing, file processing or any other code logic that follows Server.Execute or Server.Execute. However, in a situation where you must directly use Response.End, you can call HttpContext.Current.ApplicationInstance.CompleteRequest method in lieu of Response.End which bypasses the code execution of Application_EndReqeust event (Reference: &lt;a target=&quot;_new&quot; href=&quot;http://support.microsoft.com/kb/312629&quot;&gt;MSDN&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;If you are thinking as I was thinking that it&#39;s a bug in .NET, then you are wrong. MSDN explains that this is not a bug but a behavior by design. However, I would really love to see that real world usage of this behavior in everyday programming that could justify this design decision.&lt;br /&gt;&lt;br /&gt;References:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;margin:0in;font-family:Calibri;font-size:11.0pt&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a target=&quot;_new&quot; href=&quot;http://support.microsoft.com/kb/312629&quot;&gt;http://support.microsoft.com/kb/312629&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target=&quot;_new&quot; href=&quot;http://support.microsoft.com/kb/817266&quot;&gt;http://support.microsoft.com/kb/817266&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target=&quot;_new&quot; href=&quot;http://www.c6software.com/articles/ThreadAbortException.aspx&quot;&gt;http://www.c6software.com/articles/ThreadAbortException.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target=&quot;_new&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception.aspx&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;      &lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;    style=&quot;font-family:&#39;Trebuchet MS&#39;, &#39;Lucida Grande&#39;, Verdana, Tahoma, sans-serif;font-size:100%;color:#333333;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; line-height: 24px;font-size:13px;&quot;&gt;&lt;p&gt;&lt;/p&gt;      &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;HTH,&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/5222091374711185498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/11/threadabortexception-this-behavior-is.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5222091374711185498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/5222091374711185498'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/11/threadabortexception-this-behavior-is.html' title='ThreadAbortException ― This behavior is by design'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-3323495405995115426</id><published>2009-11-05T01:06:00.000-08:00</published><updated>2009-11-06T06:05:40.579-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>IIF(A,B,C) -- Beware it is a function not a statement!!</title><content type='html'>Learning how to write neat and clean is something many people wish to achieve. I believe it&#39;s an art which can be mastered with practice. I myself have this habit of keeping things brief and to the point, and I always tend to apply the same theory to my coding as well. However, today while writing a small piece of code in the similar consise manner for a small module, I found something interesting that made me realize the importance of understanding the difference between different programming constructs. I am talking about IIF(A,B,C) function and IF ELSE statement in particular here. &lt;br /&gt;&lt;br /&gt;I had a situation where I was getting some value from the database and there was a fair chance of that value being NULL. I preferred IIF over IF ELSE to save 3 lines of code. &lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Dim lCVCount As Integer = IIf(IsDBNull(DataBinder.Eval(e.Item.DataItem, &quot;IsCV&quot;)), 0, CInt(DataBinder.Eval(e.Item.DataItem, &quot;IsCV&quot;)))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Mucy to my surprise, it didn&#39;t work and threw me exception. I kept wondering for a few minutes what is wrong with this. You know it is generally said that not knowing something is acceptable but forgetting something which you know is completely unacceptable and I agree with this. How can I forget that a function behaves differently than a statement. It passes parameter values to calle which means it must execute those parameters first, if they are found to be compund in order to get their value. This explains it all that why the third parameter in above statement is throwing exception. I thought I am better off using IF ELSE here in order to keep .NET runtime happy. &lt;br /&gt;&lt;br /&gt;Sometimes It is good to get these kinds of errors which reinforces the fact that we should always be careful in what we write and specially when it comes to writing code!!&lt;br /&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/3323495405995115426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/11/iifabc-beware-it-is-function-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3323495405995115426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3323495405995115426'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/11/iifabc-beware-it-is-function-not.html' title='IIF(A,B,C) -- Beware it is a function not a statement!!'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-3445564845376537947</id><published>2009-10-16T10:32:00.001-07:00</published><updated>2009-10-21T14:44:00.501-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTTP"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>File &quot;Save As&quot; issue while downloading with Content-Disposition: inline</title><content type='html'>&lt;blockquote&gt;&lt;/blockquote&gt;It has been a long a time since I wrote anything on the blog. I was on a long holiday and (honestly speaking) wanted to stay away from the technology. But now, since life is back on rails, let&#39;s start with the very first issue I faced after I joined my workplace a couple of days ago. It is about an issue with the file name not being considered when using &quot;inline&quot; as HTTP response Content-Disposition header.&lt;br /&gt;&lt;br /&gt;Downloading a file using Content-Disposition: attachment as HTTP response header displays a &quot;File Download&quot; dialog box asking the user whether  to &quot;Open&quot;, &quot;Save&quot; or &quot;Cancel&quot; the document. In certain scenarios this dialog box can be really painful specially when user has to repeatedly do this exercise for multiple links available on our website. In order to avoid this we use Content-Disposition: inline which opens the document without asking by using appropriate software like MS Word, Adobe Acrobat Reader etc. installed on the user&#39;s machine. This document can be saved later on using &quot;Save As&quot; option.&lt;br /&gt;&lt;br /&gt;Before I move on, let&#39;s have a look on the following statement that shows the way to add Content-Disposition header to Response stream:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;context.Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=resume.doc&quot;)&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;The problem with the Content-Disposition: inline is that it doesn&#39;t pick the file name from filename attribute we use in AddHeader function rather, it always takes the name of web page from the URL while saving the document. Content-Disposition: attachment seems to be working fine even with the &quot;Save As&quot; command, but this is something I didn&#39;t want to use. I spent some time researching on this issue and couldn&#39;t found a workable solution. In order to workaround I came up with the below solution that seems to be doing the job.&lt;br /&gt;&lt;br /&gt;I actually decided to use a URL for the document link that reflects the name of the document being downloaded.  For example for the document &quot;MyResume.doc&quot;, the URL I have used looks something like this:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;a href=&quot;Default/FileName/882bd3e9-5035-4946-8c2a-98ef0eccc6e0/uploads/MyResume.doc.aspx&quot;&amp;gt;Download File&amp;lt;/a&amp;gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Did you notice &quot;.aspx&quot; at the end of the URL? It is very important to append it in the end in order to send the request back to server whenever user clicks on the link. On the server, I have created an HTTPHandler to catch this sort of request that contains &quot;*.doc.aspx&quot;. Without appending &quot;.aspx&quot;, browser will server your document directly without changing the URL in the browser. But, we want to change the URL which means request has to go to the server.&lt;br /&gt;&lt;br /&gt;The rest of the solution is very easy as I have written below code under the body of  ProcessRequest function in my HTTPHanlder which helps dump file contents into response stream. It is also important to note that URL of the document must be relative and not absolute. The reason being, it&#39;s a dummy URL which doesn&#39;t exist at all. Relative URL guarantees that request will come to the same web site/application where we can catch it before it goes to ASP.NET engine. QueryString data can be made part of the URL as in my case GUID is the piece of information which is part of the URL and I receive it on the server.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vb&quot;&gt;&lt;br /&gt;Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest&lt;br /&gt;&lt;br /&gt; &#39;Context.RewritePath(&quot;Test-Page.aspx&quot;)&lt;br /&gt; context.Response.ContentType = &quot;application/msword&quot;&lt;br /&gt; context.Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=adeel.doc&quot;)&lt;br /&gt; context.Response.TransmitFile(&quot;C:\inetpub\wwwroot\Uploads\882bd3e9-5035-4946-8c2a-98ef0eccc6e0.doc&quot;)&lt;br /&gt; context.Response.Flush()&lt;br /&gt; context.Response.End()&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The last bit is to add the below statement in web.config to enable HTTPHandler to catch &quot;*.*.aspx&quot; so that it will serve for all kinds of file type extensions.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;add verb=&quot;*&quot; path=&quot;/uploads/*.*.aspx&quot; type=&quot;Test.HttpHandler, Test&quot;/&amp;gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;References:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/381890/securly-download-file-inside-browser-with-correct-filename&quot;&gt;http://stackoverflow.com/questions/381890/securly-download-file-inside-browser-with-correct-filename&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://support.microsoft.com/kb/162059&quot;&gt;http://support.microsoft.com/kb/162059&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.datadynamics.com/forums/ShowPost.aspx?PostID=49196&quot;&gt;http://www.datadynamics.com/forums/ShowPost.aspx?PostID=49196&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.datadynamics.com/forums/ShowPost.aspx?PostID=42860&quot;&gt;http://www.datadynamics.com/forums/ShowPost.aspx?PostID=42860 &lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;HTH,&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/3445564845376537947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/10/file-save-as-issue-while-downloading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3445564845376537947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3445564845376537947'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/10/file-save-as-issue-while-downloading.html' title='File &quot;Save As&quot; issue while downloading with Content-Disposition: inline'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-3238467189610440042</id><published>2009-08-22T05:36:00.001-07:00</published><updated>2010-03-13T03:43:43.495-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>XML Literals - (VB.NET only)</title><content type='html'>After I learned about lambda statements that they are supported only in C# 3.5 and not in VB.NET 9.0, I got curious and thought why not to find something that is available only for VB.NET and not for C#, and found this interesting thing which is called XML Literals. Using this nice features which is a part of LINQ to XML API, we can embed XML directly within Visual Basic 9.0 code.&lt;br /&gt;&lt;br /&gt;To illustrate its power let&#39;s have a look at the below XML that we will produce using XML Literal.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&amp;lt;books&amp;gt;&lt;br /&gt;&amp;lt;book&amp;gt;&lt;br /&gt;   &amp;lt;title&amp;gt;LINQ IN ACTION&amp;lt;/title&amp;gt;&lt;br /&gt;   &amp;lt;author&amp;gt;FABRICE MARGUERIE&amp;lt;/author&amp;gt;&lt;br /&gt;   &amp;lt;author&amp;gt;STEVE EICHERT&amp;lt;/author&amp;gt;&lt;br /&gt;   &amp;lt;author&amp;gt;JIM WOOLEY&amp;lt;/author&amp;gt;&lt;br /&gt;   &amp;lt;publisher&amp;gt;Manning&amp;lt;/publisher&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;/books&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;now take a look at Listing 1.1 below, which shows the code for creating the XML using the XML literal syntax offered by VB9.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;Listing 1.1&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load&lt;br /&gt;&lt;br /&gt;Dim booksElement As XElement = &amp;lt;books&amp;gt;&lt;br /&gt;                                   &amp;lt;book&amp;gt;&lt;br /&gt;                                       &amp;lt;title&amp;gt;LINQ IN ACTION&amp;lt;/title&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;FABRICE MARGUERIE&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;STEVE EICHERT&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;JIM WOOLEY&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;publisher&amp;gt;Manning&amp;lt;/publisher&amp;gt;&lt;br /&gt;                                   &amp;lt;/book&amp;gt;&lt;br /&gt;                               &amp;lt;/books&amp;gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note that in the above code we are using &lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;XElement&lt;/span&gt; which is a new class introduced in .NET 3.5 which represents an XML element. According to MSDN:&lt;br /&gt;&lt;blockquote&gt;&lt;span style=&quot;FONT-STYLE: italic&quot;&gt;&quot;XElement can be used to create elements; change the content of the element; add, change, or delete child elements; add attributes to an element; or serialize the contents of an element in text form&lt;/span&gt;&quot;&lt;br /&gt;&lt;/blockquote&gt;The XML fragment in listing 1.1 above is static. When building real applications we might need to create XML using expressions stored in a set of local variables. XML Literal allows us to do so through expression holes which is expressed with the .&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;Listing 1.2&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load&lt;br /&gt;&lt;br /&gt;Dim xml = LoadXML(&quot;LINQ IN ACTION&quot;, &quot;Manning&quot;, &quot;FABRICE MARGUERIE&quot;, &quot;STEVE EICHERT&quot;, &quot;JIM WOOLEY&quot;)&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub LoadXML(ByVal title As String, ByVal publisher As String, ByVal ParamArray authours() As String)&lt;br /&gt;&lt;br /&gt;Dim booksElement As XElement = &amp;lt;books&amp;gt;&lt;br /&gt;                                   &amp;lt;book&amp;gt;&lt;br /&gt;                                       &amp;lt;title&amp;gt;&amp;lt;%= title %&amp;gt;&amp;lt;/title&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;&amp;lt;%= authours(0) %&amp;gt;&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;&amp;lt;%= authours(1) %&amp;gt;&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;author&amp;gt;&amp;lt;%= authours(2) %&amp;gt;&amp;lt;/author&amp;gt;&lt;br /&gt;                                       &amp;lt;publisher&amp;gt;&amp;lt;%= publisher %&amp;gt;&amp;lt;/publisher&amp;gt;&lt;br /&gt;                                   &amp;lt;/book&amp;gt;&lt;br /&gt;                               &amp;lt;/books&amp;gt;&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XML Literals allows us to embed XML directly within the code without having to learn the details of XML API. It&#39;s a great addition to VB9.0 and hope that it will get added to C# as well in future.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/3238467189610440042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/08/xml-literals-vbnet-only.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3238467189610440042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/3238467189610440042'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/08/xml-literals-vbnet-only.html' title='XML Literals - (VB.NET only)'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-2881511878964466117</id><published>2009-08-21T13:10:00.000-07:00</published><updated>2010-04-10T07:38:10.750-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>From Delegates to Lambda Expressions</title><content type='html'>&lt;span style=&quot;font-weight: bold;&quot;&gt;Delegates:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Delegate was a wonderful addition to .NET 1.1 in early 2000. It is a type that can store a pointer to a function. The below snippet shows the way we would use delegates in our everyday programming.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Listing 1.1&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;br /&gt;delegate DataTable GetUserDetailsDelegate(int userID);&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;GetUserDetailsDelegate GetUserDetails = new  GetUserDetailsDelegate(GetUserDetailsByUserID);&lt;br /&gt;DataTable dt = GetUserDetails(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private DataTable GetUserDetailsByUserID(int userID)&lt;br /&gt;{&lt;br /&gt;return new DataTable();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Anonymous Methods&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C#2.0 was improved to allow working with delegates through anonymous methods. I said C#, because VB.NET doesn’t offer support for anonymous methods. These anonymous methods allow us to write shorter code and avoid the need for explicitly named methods. Let&#39;s modify the code in Listing1.1 and re-write it using anonymous methods.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Listing 1.2&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;delegate DataTable GetUserDetailsDelegate(int userID);&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;GetUserDetailsDelegate GetUserDetails = delegate(int userID) { return new DataTable(); };&lt;br /&gt;var dt = GetUserDetails(1);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Lambda Expressions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, Starting with C# 3.0, instead of anonymous methods we can use lambda expressions.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Listing 1.3&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;C#&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;var GetUserDetails = userID =&gt; { return new DataTable(); };&lt;br /&gt;var dt = GetUserDetails(1);&lt;br /&gt;&lt;/pre&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;VB.NET&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;Dim GetUserDetails = Function(x) New DataTable()&lt;br /&gt;Dim dt = GetUserDetails(1)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The anonymous method introduced in C#2.0 is verbose and imperative in nature. In contrast, lambda expressions provide a more concise syntax, providing much of the expressive power of functional programming languages. It is a superset of anonymous methods with additional functionalities like inferring types, using both statement blocks and expression as bodies etc.&lt;br /&gt;&lt;br /&gt;Note that, In the above lambda expression left hand side variable is of anonymous type. Anonymous type is a new language enhancement that enable us to declare types without names. If you are concerned about their limitations and don&#39;t want to use them then you can use Func&amp;lt;T, TResult&amp;gt;&lt;t, tresult=&quot;&quot;&gt; generic delegate in lieu of a&lt;/t,&gt;nonymous types&lt;t, tresult=&quot;&quot;&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/t,&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Listing 1.4&lt;/span&gt;&lt;br /&gt;&lt;t, tresult=&quot;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;C#&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;Func&amp;lt;int,DataTable&amp;gt; GetUserDetails = userID =&gt; { return new DataTable(); };&lt;br /&gt;var dt = GetUserDetails(1);&lt;br /&gt;&lt;/pre&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;VB.NET&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Dim GetUserDetails As Func(Of Integer, DataTable) = Function(x) New DataTable&lt;br /&gt;Dim dt = GetUserDetails(1)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HTH,&lt;/t,&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/2881511878964466117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/08/from-delegates-to-lambda-expressions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/2881511878964466117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/2881511878964466117'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/08/from-delegates-to-lambda-expressions.html' title='From Delegates to Lambda Expressions'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-9033570905240678306</id><published>2009-08-02T13:46:00.000-07:00</published><updated>2009-08-08T05:48:48.321-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>Server.URLEncode an Encrypted String - do it twice my friend!!</title><content type='html'>Query string is a very important part of a web application which needs to be prevented from being sniffed or changed when it carries sensitive data. We do not have a magic wand that upon waving will hide the sensitive portion of the query string across multiple requests, but we do have powerful encryption algorithms that come as a rescue and encrypt everything which turns out to look like a toddler&#39;s handwriting. And, if it contains characters that are prohibited in a query string e.g. (&#39;+&#39;,&#39;?&#39;,&#39;:&#39;,&#39;&amp;amp;&#39;,&#39;/&#39;,&#39;=&#39;), then we can encode it using Server.URLEncoding API which comes as part of .NET class library.&lt;br /&gt;&lt;pre class=&quot;brush: csharp&quot;&gt;&lt;br /&gt;var encryptedString = CommonUtils.Encrypt(&quot;clientid=1980&amp;amp;code=alphabravo&quot;, lKey);&lt;br /&gt;var encodedEncrypted = Server.URLEncode(encryptedString);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the above code, CommonUtils is my&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;em&gt;&lt;/em&gt; homegrown encryption utility (symmetric key encryption) that takes lKey to encrypt/decrypt large quantities of data. But wait, I notice it&#39;s throwing an exception on the receiving side and not showing my properly URLEncoded query string that i generated while sending. Why o why!!&lt;br /&gt;&lt;br /&gt;After a small research I found that I need to do Server.URLEncoding twice but not just once before sending it out. By just doing it once, I witnessed that all my URL encoded characters for (&#39;+&#39;) were getting lost somehow. Anyways, the final correct sequence that I have come to know about encoding an encrypted string and decoding it is this:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Encrypt it&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Encode it twice&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Decode it once&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Decrypt it&lt;/li&gt;&lt;/ol&gt;Happy coding!!</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/9033570905240678306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/08/serverurlencode-encrypted-string-do-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/9033570905240678306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/9033570905240678306'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/08/serverurlencode-encrypted-string-do-it.html' title='Server.URLEncode an Encrypted String - do it twice my friend!!'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-4896443984538603192</id><published>2009-08-02T13:12:00.000-07:00</published><updated>2009-08-16T14:08:20.955-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>LINQ to SQL - Multiple result shapes</title><content type='html'>Working with LINQ to SQL, you might come across a situation where your stored procedure looks something like this:&lt;br /&gt;&lt;pre class=&quot;brush: sql&quot;&gt;&lt;br /&gt;CREATE PROCEDURE [dbo].[GetAllProductsAndCustomers]&lt;br /&gt;   @CompanyID INT&lt;br /&gt;AS &lt;br /&gt;SELECT [Code, Category] FROM Products&lt;br /&gt;SELECT [Name, Email,Contact] FROM Customers&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This SP returns multiple result sets which LINQ supports quite efficiently. However, If you work with auto-generated object relational mapper (*.dbml), you must have noticed that CLR cannot automatically determine which stored procedure returns multiple result shapes, hence creates a wrapper function with ISingleResult as a return type, which represents the result of a mapped function that has a single return sequence. For the above SP, it generated the below method signature:&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;&amp;lt;FunctionAttribute(Name:=&quot;GetAllProductsAndCustomers&quot;)&amp;gt; _&lt;br /&gt;Public Function GetAllProductsAndCustomers(&amp;lt;Parameter(Name:=&quot;CompanyID&quot;, DbType:=&quot;Int&quot;)&amp;gt; ByVal CompanyID As System.Nullable(Of Integer)) As ISingleResult(Of GetAllProductsAndCustomersResult)&lt;br /&gt;Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod,MethodInfo), companyID)&lt;br /&gt;Return CType(result.ReturnValue,ISingleResult(Of GetAllProductsAndCustomersResult))&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In order to turn this situation into our favor and handle multiple result shapes returned by the stored proc, all we need to do is replace the ISingleResult with IMultipleResults and supply the appropriate result types. If in case there is no specific result type, which is quite possible if stored proc is generating columns from multiple tables as a result of join, you can provide any names and LINQ will treat them as anonymous types. In the method signature below, I have created two classes GetAllProductsAndCustomersResult1 and GetAllProductsAndCustomersResult2 along with the properties Code and Category  in the first and Name, Email, Contact in the second class.&lt;br /&gt;&lt;br /&gt;One important thing, for the kind of SP we are using we need to read the result shapes in the same sequence as the SP returns the results. The order of IMultipleResults.GetResult() should be same as the order of SELECT statements in SP in order to avoid getting unexpected results or errors and exceptions if our IEnumerable result set is bound to a data source control. &lt;br /&gt;&lt;br /&gt;The modified method signature will look like:&lt;br /&gt;&lt;pre class=&quot;brush:vbnet&quot;&gt;&lt;br /&gt;&amp;lt;FunctionAttribute(Name:=&quot;GetAllProductsAndCustomers&quot;), _&lt;br /&gt;ResultType(GetType(GetAllProductsAndCustomersResult1)), _&lt;br /&gt;ResultType(GetType(GetAllProductsAndCustomersResult2))&amp;gt; _&lt;br /&gt;Public Function GetAllProductsAndCustomers(&amp;lt;Parameter(Name:=&quot;DataBridgeQueueID&quot;, DbType:=&quot;Int&quot;)&amp;gt; ByVal companyID As System.Nullable(Of Integer)) As IMultipleResults&lt;br /&gt;Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod,MethodInfo), companyID)&lt;br /&gt;Return CType(result.ReturnValue,IMultipleResults)&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;HTH,</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/4896443984538603192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/08/linq-to-sql-multiple-result-shapes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4896443984538603192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4896443984538603192'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/08/linq-to-sql-multiple-result-shapes.html' title='LINQ to SQL - Multiple result shapes'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-7637858839350328282</id><published>2009-07-20T07:44:00.000-07:00</published><updated>2009-07-20T14:32:12.992-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>VB.NET Nullable Types Gotcha</title><content type='html'>Nullable types ― A valuable language addition in .NET allowing value types to store null values. It helps a variable get it&#39;s default value which is not part of the business logic. A very common example is integer type whose default value is always set to 0 restricting programs using 0 as a legitimate value. However, Nullable types take away this restriction by allowing null values to be set for value types like reference types.&lt;br /&gt;While using nullables we need to be very careful specially when programming in VB.NET where implicit casting is frequently used. Consider the example below:&lt;div&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;&lt;br /&gt;ByVal temp As Nullable(Of Integer)&lt;br /&gt;temp = Request.QueryString(&quot;DataBridgeQueueID&quot;)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Guess what value &quot;temp&quot; will get if there is no &quot;DataBridgeQueueID&quot; passed in the query string?? a nurd like me will expect Nothing in &quot;temp&quot; which is wrong. The reason being that QueryString always returns string and in my case null (Nothing) string which is equal to 0 when assigned to an integer. Although I have declared &quot;temp&quot; variable as nullable, it will continue to have 0 because of implicit type casting. So what to do then?? You are right, just do a CType and life is easy.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&#39;If Option Strict On&lt;br /&gt;temp = CType(CType(Request.QueryString(&quot;DataBridgeQueueID&quot;), Object), Nullable(Of Integer))&lt;br /&gt;&lt;br /&gt;&#39;If Option Strict Off&lt;br /&gt;temp = CType(Request.QueryString(&quot;DataBridgeQueueID&quot;), Object)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;HTH,&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/7637858839350328282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/07/vbnet-nullable-types-gotcha.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/7637858839350328282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/7637858839350328282'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/07/vbnet-nullable-types-gotcha.html' title='VB.NET Nullable Types Gotcha'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-8941461421698003176</id><published>2009-07-11T08:42:00.000-07:00</published><updated>2009-07-11T09:32:43.374-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="User Controls"/><title type='text'>Ajax based multiselect dropdown control</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://2.bp.blogspot.com/_Imdc9xCpgf0/Sli7Q1Z0btI/AAAAAAAAAbQ/PGr0hNnaZek/s1600-h/expand-3.png&quot;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: left;&quot;&gt;As the saying goes..&quot;a picture is worth a thousand words&quot;. Checkout the pictures below and download control if you like.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;  Collapsed View-1:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(0, 0, 238); -webkit-text-decorations-in-effect: underline; &quot;&gt;&lt;img src=&quot;http://3.bp.blogspot.com/_Imdc9xCpgf0/Sli6hIB03nI/AAAAAAAAAa4/AH6EPe1tfHU/s400/collapsed-2.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5357236835010797170&quot; style=&quot;float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 338px; height: 37px; &quot; /&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold; &quot;&gt;  Expanded View-1:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal; &quot;&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://3.bp.blogspot.com/_Imdc9xCpgf0/Sli6y4k98bI/AAAAAAAAAbA/GhPzRnKQdZ8/s1600-h/expand-1.png&quot;&gt;&lt;img src=&quot;http://3.bp.blogspot.com/_Imdc9xCpgf0/Sli6y4k98bI/AAAAAAAAAbA/GhPzRnKQdZ8/s400/expand-1.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5357237140100870578&quot; style=&quot;float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 370px; height: 302px; &quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold; &quot;&gt;Expanded View-2:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal; color: rgb(0, 0, 238); -webkit-text-decorations-in-effect: underline; &quot;&gt;&lt;img src=&quot;http://2.bp.blogspot.com/_Imdc9xCpgf0/Sli7Q1Z0btI/AAAAAAAAAbQ/PGr0hNnaZek/s400/expand-3.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5357237654644879058&quot; style=&quot;float: left; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; cursor: pointer; width: 370px; height: 300px; &quot; /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Click &lt;a href=&quot;http://multiselect-dropdown.googlecode.com/files/Multiselect-Dropdown-Control.rar&quot;&gt;here&lt;/a&gt; download the control.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/8941461421698003176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/07/ajax-based-multiselect-dropdown-control.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/8941461421698003176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/8941461421698003176'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/07/ajax-based-multiselect-dropdown-control.html' title='Ajax based multiselect dropdown control'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_Imdc9xCpgf0/Sli6hIB03nI/AAAAAAAAAa4/AH6EPe1tfHU/s72-c/collapsed-2.png" height="72" width="72"/><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-6213802949191601739</id><published>2009-07-02T14:03:00.000-07:00</published><updated>2009-10-17T03:45:02.913-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTTP"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Uploading files using HTTPWebRequest</title><content type='html'>&lt;p&gt;I want to upload a file but can&#39;t use html input file control as I don&#39;t have any html page in my application. I am into a situation where i want to utilize all the power of HTTP protocols and internet media types like POST and multipart/form-data respectively without using any html control. This situation is not very rare and most likely you will face it while creating an automatic batch file upload utility where this is no chance of manual intervention hence no possibility of using html input file control.&lt;/p&gt;&lt;p&gt;Since I am using .NET, I can use low level HTTPWebRequest to upload files to webserver. This class helps simulate manual upload using ContentType=multipart/form-data. multipart/form-data can be used for forms that are presented using representations other than HTML (spreadsheets, Portable Document Format, etc), and for transport using other means than electronic mail or HTTP.&lt;/p&gt;&lt;p&gt;An important aspect of uploading files is the way web request is structured where every form value has to start with &lt;b&gt;--{boundary}&lt;/b&gt; and full web reqeust has to end with &lt;b&gt;--{boundary}--&lt;/b&gt;. This can be seen by debugging the request using any web request debugging tools like Fiddler while uploading through html input file control. We will have to immitate the same request format in order for it to be accepted by web server. Let&#39;s quickly mention some of the important parts of this request that we need to set in order to successfully upload a file.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;ContentType: Multipart/form-data&lt;/li&gt;&lt;li&gt;Request Method: Post&lt;/li&gt;&lt;li&gt;Content-Disposition: form-data&lt;/li&gt;&lt;li&gt;Boundary: Guid&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The reason to use multipart MIME type is that its is used by file upload which has a more complicated than a simple post. For a detailed explanation you can read the &lt;a target=&quot;_new&quot; href=&quot;http://www.faqs.org/rfcs/rfc2388.html&quot;&gt;RFC2388 - Returning Values from Forms: multipart/form-data&lt;/a&gt;. For boundary we can use Guid as this is value that should not occur in any of the form value.&lt;/p&gt;&lt;p&gt;The funciton UploadFile() mentioned below uploads a file along with 2 other form values using the parameters mentioned above. Apart from them, HTTPWebRequest.Headers can also be used to supply credentials if our server requires authentication.&lt;/p&gt;&lt;b&gt;Request: (UploadFile.aspx)&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Private Sub UploadLocalFile()&lt;br /&gt;&lt;br /&gt;Dim objWebReq As HttpWebRequest&lt;br /&gt;Dim memStream As MemoryStream = Nothing&lt;br /&gt;Dim writer As StreamWriter = Nothing&lt;br /&gt;Dim newLine As String = vbCrLf&lt;br /&gt;Dim fileContent As Byte() = Nothing&lt;br /&gt;Dim fileText As String = Nothing&lt;br /&gt;Dim rStream As Stream = Nothing&lt;br /&gt;Dim webResponse As HttpWebResponse = Nothing&lt;br /&gt;Dim stReader As StreamReader = Nothing&lt;br /&gt;Dim output As String = Nothing&lt;br /&gt;&lt;br /&gt;Try&lt;br /&gt;&lt;br /&gt;   Dim boundary As String = Guid.NewGuid().ToString().Replace(&quot;-&quot;, String.Empty)&lt;br /&gt;   Dim obj As Object = HttpWebRequest.Create(&quot;http://localhost:3860/ReceiveFile.aspx&quot;)&lt;br /&gt;&lt;br /&gt;   objWebReq = CType(obj, HttpWebRequest)&lt;br /&gt;&lt;br /&gt;   objWebReq.ContentType = &quot;multipart/form-data; boundary=&quot; + boundary&lt;br /&gt;   objWebReq.Method = &quot;POST&quot;&lt;br /&gt;   objWebReq.Headers.Add(&quot;loginName&quot;, &quot;{username}&quot;)&lt;br /&gt;   objWebReq.Headers.Add(&quot;loginPassword&quot;, &quot;{password}&quot;)&lt;br /&gt;&lt;br /&gt;   memStream = New MemoryStream(100240)&lt;br /&gt;   writer = New StreamWriter(memStream)&lt;br /&gt;&lt;br /&gt;   &#39;Feed ID&lt;br /&gt;   writer.Write(&quot;--&quot; + boundary + newLine)&lt;br /&gt;   writer.Write(&quot;Content-Disposition: form-data; name=&quot;&quot;{0}&quot;&quot;{1}{2}&quot;, &quot;FeedID&quot;, newLine, newLine)&lt;br /&gt;   writer.Write(&quot;10250&quot;)&lt;br /&gt;   writer.Write(newLine)&lt;br /&gt;&lt;br /&gt;   &#39;Feed Category&lt;br /&gt;   writer.Write(&quot;--&quot; + boundary + newLine)&lt;br /&gt;   writer.Write(&quot;Content-Disposition: form-data; name=&quot;&quot;{0}&quot;&quot;{1}{2}&quot;, &quot;FeedCategory&quot;, newLine, newLine)&lt;br /&gt;   writer.Write(&quot;Automotive&quot;)&lt;br /&gt;   writer.Write(newLine)&lt;br /&gt;&lt;br /&gt;   &#39;XML File&lt;br /&gt;   writer.Write(&quot;--&quot; + boundary + newLine)&lt;br /&gt;   writer.Write(&quot;Content-Disposition: form-data; name=&quot;&quot;{0}&quot;&quot;; filename=&quot;&quot;{1}&quot;&quot;{2}&quot;, &quot;XMLfile&quot;, &quot;C:\Users\Irfan\Desktop\feed-automotive.xml&quot;, newLine)&lt;br /&gt;   writer.Write(&quot;Content-Type: text/xml &quot; + newLine + newLine)&lt;br /&gt;   writer.Write(File.ReadAllText(&quot;C:\Users\Irfan\Desktop\feed-automotive.xml&quot;))&lt;br /&gt;   writer.Write(newLine)&lt;br /&gt;&lt;br /&gt;   writer.Write(&quot;--{0}--{1}&quot;, boundary, newLine)&lt;br /&gt;&lt;br /&gt;   writer.Flush()&lt;br /&gt;&lt;br /&gt;   objWebReq.ContentLength = memStream.Length&lt;br /&gt;   rStream = objWebReq.GetRequestStream()&lt;br /&gt;   memStream.WriteTo(rStream)&lt;br /&gt;   memStream.Close()&lt;br /&gt;&lt;br /&gt;   webResponse = objWebReq.GetResponse()&lt;br /&gt;   stReader = New StreamReader(webResponse.GetResponseStream())&lt;br /&gt;   stReader.ReadToEnd()&lt;br /&gt;   output = stReader.ReadToEnd()&lt;br /&gt;&lt;br /&gt;   Response.Write(output)&lt;br /&gt;&lt;br /&gt;Catch ex As Exception&lt;br /&gt;&lt;br /&gt;   Response.Write(ex.Message)&lt;br /&gt;&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Response: (ReceiveFile.aspx)&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;brush: vbnet&quot;&gt;&lt;br /&gt;Private Sub ReceiveFile()&lt;br /&gt;&lt;br /&gt;Dim reader As System.IO.StreamReader = Nothing&lt;br /&gt;&lt;br /&gt;Try&lt;br /&gt;&lt;br /&gt;   If Not Reqeust.Files.Count &gt; 0 AndAlso Not Request.Files(&quot;XMLFile&quot;) Is Nothing Then&lt;br /&gt;       reader = New System.IO.StreamReader(Request.Files(&quot;XMLFile&quot;).InputStream)&lt;br /&gt;       System.IO.File.WriteAllText(&quot;c:\feed.xml&quot;, reader.ReadToEnd())&lt;br /&gt;   Else&lt;br /&gt;       Response.Write(&quot;No feed file received in the request.&quot;)&lt;br /&gt;   End If&lt;br /&gt;&lt;br /&gt;Catch ex As Exception&lt;br /&gt;   Response.Write(ex.Message)&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;End Sub&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/6213802949191601739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/07/uploading-files-using-httpwebrequest.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/6213802949191601739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/6213802949191601739'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/07/uploading-files-using-httpwebrequest.html' title='Uploading files using HTTPWebRequest'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-2789061342541764042</id><published>2009-06-20T12:06:00.001-07:00</published><updated>2009-07-08T08:05:08.267-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Checklist for Multilingual website development</title><content type='html'>I sometimes wish if i could have a checklist or to do list to follow before actually starting developing something new. Checklists are great as they, in certain situations, prove to be more helpful than full length articles due to their short and precise nature. The checklist I am going to propose in this post is solely for those who want to have some idea about multilingual websites and the core steps involved in developing them. By just skimming through the steps below, one can calculate the amount of time required to translate a website into a another language. This checklist is nothing but merely a set of suggestions and recommendations based upon my very recent experience that I had while translating a website from English to Arabic.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;First and foremost,  a seperate style sheet can be created for each language. I have created two in my project &lt;span style=&quot;font-weight: bold;&quot;&gt;en-US-main.css &lt;/span&gt;and &lt;span style=&quot;font-weight: bold;&quot;&gt;ar-SA-main.css.&lt;/span&gt; Using a separate style sheet while doing the translation guarantees that the existing design and layout will remain intact.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We should never embed any content or label text/values directly into html page like this:&lt;span style=&quot;font-family:Aharoni;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&amp;lt;p&amp;gt;embedded text.&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;input id=&quot;lblFirstName&quot; type=&quot;label&quot;&amp;gt;First Name&amp;lt;/input&amp;gt;&lt;br /&gt;&amp;lt;input id=&quot;lblLastName&quot; type=&quot;label&quot;&amp;gt;Last Name&amp;lt;/input&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;By using the above approach, we take away the privilege that we get through resource files to switch culture specific content at runtime. It is a best practice to create language specific resource files like *.RESOURCE or *.RESX which help setting labels and messages on the fly. In the below code i am calling GetLabelTring() function which pulls labels values either from en-US.resouces file or ar-SA.resources based upon the selected culture.&lt;br /&gt;&lt;blockquote&gt;&amp;lt;p&amp;gt;GetLabelString(&quot;L1000&quot;) &amp;lt;/p&amp;gt; {html side}&lt;br /&gt;lblFirstName.Text = GetLabelString(&quot;L1001&quot;)  {ASP side}&lt;br /&gt;lblLastName.Text = GetLabelString(&quot;L1002&quot;)   {ASP side}&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;/li&gt;&lt;li&gt;The current culture  can be saved into session variables which will help maintain the same language across all of the pages for a specific session.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The labels and messages can be cached if the frequency of their modification is low which will result in better performance and speed.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We can use HTML DIR attribute if the language we are targeting is written right to left such as Arabic and Hebrew. This attribute specifies the base direction (RTL, LTR) of text, or sections of text.&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;margin: 0in; font-weight: bold; font-family: Calibri; font-size: 13pt;&quot;&gt;HTML Markup&lt;/p&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://2.bp.blogspot.com/_Imdc9xCpgf0/Sj0-qxiHMjI/AAAAAAAAATs/ZTZcg8bw-r0/s1600-h/DIR%3DLTR-1.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 400px; height: 133px;&quot; src=&quot;http://2.bp.blogspot.com/_Imdc9xCpgf0/Sj0-qxiHMjI/AAAAAAAAATs/ZTZcg8bw-r0/s400/DIR%3DLTR-1.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5349500836957860402&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;margin: 0in; font-weight: bold; font-family: Calibri; font-size: 13pt;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Resulting Display&lt;br /&gt;&lt;/p&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://3.bp.blogspot.com/_Imdc9xCpgf0/Sj0-8uPlCMI/AAAAAAAAAT0/Wr69N4Vn_mY/s1600-h/DIR%3DLTR-2.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 400px; height: 134px;&quot; src=&quot;http://3.bp.blogspot.com/_Imdc9xCpgf0/Sj0-8uPlCMI/AAAAAAAAAT0/Wr69N4Vn_mY/s400/DIR%3DLTR-2.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5349501145312463042&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can also specify a single base direction for all of the content available on the website by using the DIR attribute with HTML tag.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;For everything else on the page other than content can be controlled through style sheets. If our website is blessed with DIV-based layout, we can be rest assured that the style sheet attributes such as &lt;b&gt;float&lt;/b&gt;, &lt;b&gt;background-position&lt;/b&gt; and &lt;b&gt;margin/padding&lt;/b&gt; etc. will take care of the direction (right-to-left / left-to-right) for most of the HTML elements.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;That’s all from the HTML side. I would like to add a couple of bits here in regards insertion of multilingual text in the database table. The idea is to insert a separate row for every culture and do it for all of the content pages of the website. Of course, we need to enable the Unicode support on the table.&lt;div style=&quot;direction: ltr;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;table valign=&quot;top&quot; style=&quot;border: 1pt solid rgb(163, 163, 163); direction: ltr; border-collapse: collapse; width: 570px; height: 139px;&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.8486in;&quot;&gt;&lt;p    style=&quot;margin: 0in; font-weight: bold;font-family:Calibri;font-size:11pt;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;RecID&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9569in;&quot;&gt;   &lt;p    style=&quot;margin: 0in; font-weight: bold;font-family:Calibri;font-size:11pt;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;PageName&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.8756in;&quot;&gt;   &lt;p  style=&quot;margin: 0in; font-weight: bold;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;PageText&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.0736in;&quot;&gt;   &lt;p    style=&quot;margin: 0in; font-weight: bold;font-family:Calibri;font-size:11pt;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;LangID&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.709in;&quot;&gt;   &lt;p  style=&quot;margin: 0in; font-weight: bold;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;PageID&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9118in;&quot;&gt;   &lt;p  style=&quot;margin: 0in; font-weight: bold;color:black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:arial;&quot;&gt;PageTitle&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.8486in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;101&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9569in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;My   Website Home Page&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.8756in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;Welcome   to my page&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.0736in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;1&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.709in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;2002&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9118in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;Home   Page&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.8486in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;102&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9569in;&quot;&gt;   &lt;p   style=&quot;margin: 0in;font-family:Arial;font-size:11pt;&quot;&gt;&lt;span style=&quot;direction: rtl; unicode-bidi: embed;&quot; lang=&quot;ar-SA&quot;&gt;الصفحة الرئيسية الموقع   الخاص بي&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.8756in;&quot;&gt;   &lt;p   style=&quot;margin: 0in;font-family:Arial;font-size:11pt;&quot;&gt;&lt;span style=&quot;direction: rtl; unicode-bidi: embed;&quot; lang=&quot;ar-SA&quot;&gt;مرحباً بك في الصفحة   الخاصة بي&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.0736in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;2&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 0.709in;&quot;&gt;   &lt;p style=&quot;margin: 0in; font-family: Calibri; font-size: 11pt; color: black;&quot;&gt;2002&lt;/p&gt;   &lt;/td&gt;   &lt;td style=&quot;border: 1pt solid rgb(163, 163, 163); padding: 4pt; vertical-align: top; width: 1.9118in;&quot;&gt;   &lt;p  style=&quot;margin: 0in;font-size:11pt;&quot;&gt;&lt;span style=&quot;direction: rtl; unicode-bidi: embed;font-family:Arial;&quot;  lang=&quot;ar-SA&quot;&gt;الصفحة الرئيسية&lt;/span&gt;&lt;span  lang=&quot;en-US&quot; style=&quot;font-family:Calibri;&quot;&gt; (Home Page)&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;/div&gt;  &lt;p   style=&quot;margin: 0in;font-family:Calibri;font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p face=&quot;Calibri&quot; size=&quot;11pt&quot; style=&quot;margin: 0in;&quot;&gt;&lt;span style=&quot;color:black;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Last but not least, there are many free translation tools available on the internet that can be of great help for cross-checking the content between the languages. Two such great tools that I have extensively used are &lt;a target=&quot;_new&quot; href=&quot;http://www.microsofttranslator.com/Default.aspx&quot;&gt;Bing Translator&lt;/a&gt; and &lt;a target=&quot;_new&quot; href=&quot;http://translate.google.com/&quot;&gt;Google Translate&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/2789061342541764042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/06/checklist-for-multilingual-website.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/2789061342541764042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/2789061342541764042'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/06/checklist-for-multilingual-website.html' title='Checklist for Multilingual website development'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_Imdc9xCpgf0/Sj0-qxiHMjI/AAAAAAAAATs/ZTZcg8bw-r0/s72-c/DIR%3DLTR-1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-648126094267448871.post-4547352365525329220</id><published>2009-06-06T08:51:00.001-07:00</published><updated>2009-06-24T11:52:38.291-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Podcast"/><title type='text'>Podcast - Vernon Bryce from Kenexa</title><content type='html'>Vernon Bryce, the managing partner of Kenexa was interviewed by dubaieye1038 radio station. Use the blow link to check it out.&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://irfan.podomatic.com/enclosure/2009-06-06T07_49_56-07_00.mp3&quot;&gt;Click to download the podcast&lt;/a&gt;</content><link rel='enclosure' type='audio/mpeg' href='http://irfan.podomatic.com/enclosure/2009-06-06T07_49_56-07_00.mp3' length='0'/><link rel='replies' type='application/atom+xml' href='http://irfaann.blogspot.com/feeds/4547352365525329220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://irfaann.blogspot.com/2009/06/vernon-bryce-from-kenexa.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4547352365525329220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/648126094267448871/posts/default/4547352365525329220'/><link rel='alternate' type='text/html' href='http://irfaann.blogspot.com/2009/06/vernon-bryce-from-kenexa.html' title='Podcast - Vernon Bryce from Kenexa'/><author><name>irfan</name><uri>http://www.blogger.com/profile/11601582823200426073</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>