<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6104185749662767834</atom:id><lastBuildDate>Thu, 05 Nov 2009 16:37:05 +0000</lastBuildDate><title>dotNETspidor</title><description /><link>http://dotnetspidor.blogspot.com/</link><managingEditor>sangam.uprety@gmail.com (Sangam Uprety)</managingEditor><generator>Blogger</generator><openSearch:totalResults>61</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/dotnetspidor" type="application/rss+xml" /><feedburner:emailServiceId>dotnetspidor</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-8012312715800361204</guid><pubDate>Wed, 28 Oct 2009 11:26:00 +0000</pubDate><atom:updated>2009-10-28T05:15:39.045-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jquery</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>jQuery Mutually exclusive checkboxes in asp.net</title><description>&lt;p&gt;We often see radio buttons to implement single choices out of many in web forms. Wouldn’t it be better if we could imply ‘choose one option from many’ using checkboxes? I have implemented such mutually exclusive checkboxes in asp.net using jquery. This certainly is not any new practice. We have already seen such mutually exclusive checkboxes in asp.net ajax, and perhaps there are others also. But achieving this functionality using a lightweight javascript library like jquery would be a benefit. So let’s start the race. &lt;/p&gt;  &lt;p&gt;First of all, let me present the design philosophy of this realization of mutually exclusive checkboxes. &lt;/p&gt;  &lt;p&gt;1. We will have a group of checkboxes with same css class name. We will not need the id of checkboxes besides for associating label to display text and make label clickable.&lt;/p&gt;  &lt;p&gt;2. For our example, initially we will check one of the checkboxes. You may wish not to and this will work.&lt;/p&gt;  &lt;p&gt;3. We can add any number of such groups of checkboxes but each group will have distinct class name. For example, one group of checkboxes can have class name ‘class1’ and other can have ‘class2’ and so on.&lt;/p&gt;  &lt;p&gt;4. When a checkbox is checked, if it is already checked nothing will happen, otherwise this checkbox will be checked and all other checkboxes having the same class name as of this checked one will be unchecked.&lt;/p&gt;  &lt;p&gt;5. If a checkbox is unchecked, we re-check it, since we want at least one checkbox checked. We can let a checkbox get unchecked if our requirement does not demand at least one option checked, but for this tutorial we will not let so.&lt;/p&gt;  &lt;p&gt;By this time we have realized the need and design philosophy of implementing mutually exclusive checkboxes in asp.net using jquery. Now let’s proceed on.&lt;/p&gt;  &lt;p&gt;We need the latest version of jquery which is &lt;a href="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"&gt;available here&lt;/a&gt; [latest version is jquery 1.3.2 till date].&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/SugrkwpFgeI/AAAAAAAAAFM/qYWvzXtUCUA/s1600-h/jquery+library+added+in+asp-net+website+project.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 268px; height: 157px;" src="http://3.bp.blogspot.com/_1sICTF7VWbI/SugrkwpFgeI/AAAAAAAAAFM/qYWvzXtUCUA/s400/jquery+library+added+in+asp-net+website+project.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5397612063936053730" /&gt;&lt;/a&gt;&lt;br/&gt;&lt;i&gt;Fig:1 jQuery library added in asp.net website project&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now reference the jquery library file in the head section of the design page.&lt;/p&gt;&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/SugsL3vl6mI/AAAAAAAAAFU/1o0trG0y4G8/s1600-h/jquery+library+file+referenced+in+head+section+of+asp-net+design+page.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 82px;" src="http://3.bp.blogspot.com/_1sICTF7VWbI/SugsL3vl6mI/AAAAAAAAAFU/1o0trG0y4G8/s400/jquery+library+file+referenced+in+head+section+of+asp-net+design+page.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5397612735857289826" /&gt;&lt;/a&gt;&lt;br/&gt;&lt;i&gt;Fig:2 jQuery libray referenced in the header section of asp.net design page&lt;/i&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Here goes the design markup code in the aspx page.&lt;/p&gt; &lt;pre name="code" class="html"&gt;&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;asp:Label ID=&amp;quot;lblResult&amp;quot; runat=&amp;quot;server&amp;quot; ForeColor=&amp;quot;Green&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;    &amp;lt;div id=&amp;quot;toggleContainer&amp;quot;&amp;gt;&lt;br /&gt;        I like to mix  &lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;aspnet&amp;quot; class=&amp;quot;firstClass&amp;quot; checked=&amp;quot;checked&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;         &amp;lt;label for=&amp;quot;aspnet&amp;quot;&amp;gt;asp.net&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;php&amp;quot; class=&amp;quot;firstClass&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;php&amp;quot;&amp;gt;php&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;jsp&amp;quot; class=&amp;quot;firstClass&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;jsp&amp;quot;&amp;gt;jsp&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;asp&amp;quot; class=&amp;quot;firstClass&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;   &lt;br /&gt;        &amp;lt;label for=&amp;quot;asp&amp;quot;&amp;gt;asp&amp;lt;/label&amp;gt;     &lt;br /&gt;        &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; with  &lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;jquery&amp;quot; class=&amp;quot;secondClass&amp;quot; checked=&amp;quot;checked&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;jquery&amp;quot;&amp;gt;jquery&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;javascript&amp;quot; class=&amp;quot;secondClass&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;javascript&amp;quot;&amp;gt;pure javascript&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;aspnetajax&amp;quot; class=&amp;quot;secondClass&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;aspnetajax&amp;quot;&amp;gt;asp.net ajax&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;input type=&amp;quot;checkbox&amp;quot; id=&amp;quot;thirdajax&amp;quot; class=&amp;quot;secondClass&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;label for=&amp;quot;thirdajax&amp;quot;&amp;gt;third party ajax&amp;lt;/label&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;btnResult&amp;quot; runat=&amp;quot;server&amp;quot; OnClick=&amp;quot;btnResult_Click&amp;quot; Text=&amp;quot;Show Result!&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;/pre&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_1sICTF7VWbI/SugtD-EGhBI/AAAAAAAAAFc/2lCk1ueorJ0/s1600-h/mutually+exclusive+checkboxes+at+initial+state+in+asp-net+web+page.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 104px;" src="http://4.bp.blogspot.com/_1sICTF7VWbI/SugtD-EGhBI/AAAAAAAAAFc/2lCk1ueorJ0/s400/mutually+exclusive+checkboxes+at+initial+state+in+asp-net+web+page.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5397613699626599442" /&gt;&lt;/a&gt;&lt;br/&gt;&lt;i&gt;Fig:3 Mutually exclusive checkboxes at initial state&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;As shown in the page code above, we have three different groups of checkboxes having class names firstClass and secondClass. Each group has one checkbox checked initially.&lt;/p&gt;  &lt;p&gt;Now is the time to use and understand the jquery script in the page. Here is the complete code in the script block.&lt;/p&gt;  &lt;pre name="code" class="javascript"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;      $(document).ready(function(){&lt;br /&gt;            //toggle all checkboxes in toggleContainer div&lt;br /&gt;            $('#toggleContainer :checkbox').bind('change',function(){&lt;br /&gt;                var thisClass=$(this).attr('class');&lt;br /&gt;                if($(this).attr('checked'))&lt;br /&gt;                {&lt;br /&gt;                    $('#toggleContainer :checkbox.'+thisClass+&amp;quot;:not(#&amp;quot;+this.id+&amp;quot;)&amp;quot;).removeAttr('checked');    &lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                {&lt;br /&gt;                    $(this).attr('checked','checked');                          &lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;        });&lt;br /&gt;    &amp;lt;/script&amp;gt;&lt;/pre&gt;  &lt;p&gt;&lt;b&gt;Explanation of jquery code snippet&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;1. We put all the codes that are required to run at the page load within document’s ready event handler code block, so the first line.&lt;/p&gt;  &lt;p&gt;2. toggleContainer is the div element we put all our checkboxes. We have done this to avoid collision with other checkboxes in the page. For all checkboxes [as by :checkbox selector] within this div element we bind change event. So, the following code block will execute when any checkbox is checked or unchecked.&lt;/p&gt;  &lt;p&gt;3. In the change event, we read the class name of the current checkbox in thisClass variable. Note that we are reading the value of attribute class [as by .attr method, used to get or set value of an attribute]&lt;/p&gt;  &lt;p&gt;4. If this checkbox has attribute ‘checked’, this means we are checking this checkbox exclusive of others in its group. So we uncheck all checkboxes other than itself having class name of this checkbox [stored in variable thisClass]. How we achieve this- uncheck all checkboxes other than this? Answer is: using : not[itself] selector. This selector excludes the matching dom element from the result.&lt;/p&gt;  &lt;p&gt;5. If this class has no ‘checked’ attribute, this means the previously checked chexbox has been tried to uncheck which we prevent by re-checking this checkbox since this violates our design philosophy.&lt;/p&gt;  &lt;p&gt;That’s all.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Reading Result&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Remember the Show Result button in the pages? Yeah, we will publish the result as of user’s selections. Here goes the code-behind code snippet.&lt;/p&gt;  &lt;pre name="code" class="csharp"&gt;//prints your choices in the result label&lt;br /&gt;    protected void btnResult_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        string result = "Oh, you like to mix &lt;b&gt;";&lt;br /&gt;        if (asp.Checked)&lt;br /&gt;            result += "asp";&lt;br /&gt;        else if (aspnet.Checked)&lt;br /&gt;            result += "asp.net";&lt;br /&gt;        else if (php.Checked)&lt;br /&gt;            result += "php";&lt;br /&gt;        else&lt;br /&gt;            result += "jsp";&lt;br /&gt;&lt;br /&gt;        result += "&lt;/b&gt; with &lt;b&gt;";&lt;br /&gt;&lt;br /&gt;        if (jquery.Checked)&lt;br /&gt;            result += "jquery ajax!";&lt;br /&gt;        else if (javascript.Checked)&lt;br /&gt;            result += "pure javascript ajax!";&lt;br /&gt;        else if (aspnetajax.Checked)&lt;br /&gt;            result += "asp.net ajax!";&lt;br /&gt;        else&lt;br /&gt;            result += "other third party ajax!";&lt;br /&gt;&lt;br /&gt;        result += "&lt;/b&gt;";&lt;br /&gt;&lt;br /&gt;        lblResult.Text = result;&lt;br /&gt;    }&lt;/pre&gt;  &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/_1sICTF7VWbI/SuguHJhSTpI/AAAAAAAAAFk/0otZL0pr_jU/s1600-h/mutually+exclusive+checkboxes+in+action+in+asp-net+web+page.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 108px;" src="http://1.bp.blogspot.com/_1sICTF7VWbI/SuguHJhSTpI/AAAAAAAAAFk/0otZL0pr_jU/s400/mutually+exclusive+checkboxes+in+action+in+asp-net+web+page.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5397614853753032338" /&gt;&lt;/a&gt;&lt;br/&gt;&lt;i&gt;Fig:4 Mutually exclusive checkboxes in action&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In this simple yet descriptive tutorial we implemented mutually exclusive checkboxes in asp.net using latest javascript jquery library. Since we used class property of checkboxes, we have been able to implement this with any number of distinct groups of checkboxes. If you enjoyed this tutorial, please spread the words: bookmark this, share your opinions via comments or email this article etcetera! Happy programming!&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f10%2fjquery-mutually-exclusive-checkboxes-in.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f10%2fjquery-mutually-exclusive-checkboxes-in.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-8012312715800361204?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/PSCf-ZD-DW0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/PSCf-ZD-DW0/jquery-mutually-exclusive-checkboxes-in.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_1sICTF7VWbI/SugrkwpFgeI/AAAAAAAAAFM/qYWvzXtUCUA/s72-c/jquery+library+added+in+asp-net+website+project.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/10/jquery-mutually-exclusive-checkboxes-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-5497951058413511905</guid><pubDate>Thu, 03 Sep 2009 12:49:00 +0000</pubDate><atom:updated>2009-09-03T05:49:10.887-07:00</atom:updated><title>Programming foa and fop to generate pdf files from xml and xslt</title><description>&lt;span xmlns=''&gt;&lt;p&gt;In real world, there is a great deal of demand of pdf files. Programmers often need to generate pdf file from data fed in different formats. One popular format is &lt;a href='http://www.w3.org/XML/'&gt;xml&lt;/a&gt;. There exists lots of ways to generate pdf files in different programming languages. And interestingly most of them are platform and program independent. Sweet!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I am currently programming &lt;a href='http://www.w3.org/TR/xslt'&gt;xslt&lt;/a&gt;. There has been an interesting task. We have xml file as input and &lt;a href='http://xmlgraphics.apache.org/fop/'&gt;fop&lt;/a&gt; batch file which can be run to accept some xml, xslt and pdf files to generate pdf out of the xml and xslt file. With this scenario, all we have to do is write the xslt that styles and maps to the original xml file, which can be then rendered as pdf files.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We are writing xslt using &lt;a href='http://foa.sourceforge.net/'&gt;foa&lt;/a&gt;. The fop can take this xslt as input. The foa even provides IDE to write xslt. And this free yet significant tool is very programmer-friendly in the sense it provides environment to integrate style and xml at once into the xslt from one place.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This is my first time with fop and foa. They do make great marriage. But there doesn't seem to be updates in foa since long time. The latest foa we get is too old to match the latest version of fop. How would this foa keep with the latest, new, improved fop?&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Anyway, I hope to come up with more issues in using xsl. Keep up warming your programming. Happy programming!&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-5497951058413511905?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/GFbEdNBEMO4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/GFbEdNBEMO4/programming-foa-and-fop-to-generate-pdf.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/09/programming-foa-and-fop-to-generate-pdf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-474312426542918409</guid><pubDate>Wed, 12 Aug 2009 06:24:00 +0000</pubDate><atom:updated>2009-08-11T23:24:38.405-07:00</atom:updated><title>International Youth Day 2009</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Hi all. Today is August 12, 2009, the &lt;a href='http://www.un.org/esa/socdev/unyin/iyouthday.htm'&gt;International Youth Day&lt;/a&gt;. May this day empower the youth all over the world!&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-474312426542918409?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/FH86Z4H40eQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/FH86Z4H40eQ/international-youth-day-2009.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/08/international-youth-day-2009.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-2206207484070582728</guid><pubDate>Mon, 10 Aug 2009 13:14:00 +0000</pubDate><atom:updated>2009-08-11T05:51:20.415-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">performance</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Smart sorting, paging in asp-net, especially repeater control</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Hi all. There has been little lagging in my presence to you all with new post. Actually these days there are lots of things in my mind. I am looking over the web to know the best asp.net performance practices. But most of the times I do get stuck with the same old strategies you can find everywhere if you search with the keyword – "asp.net performance tips" or so. However, these tips work 90% of the cases, they are intermediate ones. What about the advanced ones? There are some genius guys who have presented advanced and deep asp.net performance improvement techniques, and thanks to them. Good things cannot hide, so you are sure to find them over the web hanging here and there, no problem. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;But here I am going to talk about one thing- paging and sorting in asp.net. From the very beginning I am dissatisfied with the old, easy paging of asp.net gridview that really kills the spirit of web- faster response and scalability. In fact gridview and datagrid both generate heavy markup. The only good way to get rid of all these is to do custom paging, sorting with the gridview and datalist.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Then what about repeater control? Yes, the best option to go is use repeater and use custom sorting/paging with it. Repeater control has always won the heart of programmers- light, efficient and thus effective! I have just been through &lt;a href='http://www.aspdotnetcodes.com/Custom_Sorting_Paging_GridView.aspx'&gt;this better way of paging and sorting with asp.net gridview control&lt;/a&gt;. They have managed an &lt;a href='http://www.aspdotnetcodes.com/GridView_Custom_Sorting_Paging_HeaderTemplate_Example.aspx'&gt;example page&lt;/a&gt; also. I hope following the same pattern would make a good impression with repeater control also. We would certainly go different pattern for sorting- perhaps a dropdownlist populating all the column names and another dropdownlist with "asc" and "desc" for sorting direction.&lt;/p&gt;&lt;p&gt;As alternatives, I have also liked: &lt;a href='http://www.codeproject.com/KB/aspnet/PagingLarge.aspx'&gt;this one from codeproject&lt;/a&gt; and &lt;a href='http://www.asp.net/Learn/Data-Access/tutorial-26-cs.aspx'&gt;this one discussed in asp.net tutorial&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;What you think? I am still looking for the best paging in asp.net- for gridview, datalist or repeater. Your suggestions and referrals are welcome. Please keep in mind that I am fond of performance friendly options. Thank you. Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f08%2fsmart-sorting-paging-in-asp-net.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f08%2fsmart-sorting-paging-in-asp-net.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-2206207484070582728?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/cyaQFCkR3bA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/cyaQFCkR3bA/smart-sorting-paging-in-asp-net.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/08/smart-sorting-paging-in-asp-net.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-5603859121301665697</guid><pubDate>Fri, 03 Jul 2009 12:47:00 +0000</pubDate><atom:updated>2009-07-03T06:11:32.485-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Ajax</category><title>How to change second textbox text when the first textbox date of AJAX CalendarExtender changes?</title><description>&lt;span xmlns=""&gt;&lt;p&gt;Sometime ago I saw an interesting question in &lt;a href="http://forums.asp.net/t/1382766.aspx"&gt;asp.net forum&lt;/a&gt;. It raised my enthusiasm. I started to code the requirement. And I found one. Here goes the requirement:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;Hi!&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;I have two text boxes inside my aspx page: a) the "txt1" and b) the "txt2". Both text boxes have CalendarExtender controls attached:&lt;br /&gt;a) the txt1 has the "CalendarExtender1"&lt;br /&gt;b) the txt2 has the"CalendarExtender2".&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;All I want is this:&lt;br /&gt;Using client-side script (or other method without postbacks), I want when the user chooses a date from CalendarExtender1, the same date plus a day front to go to the txt2.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;If the user chooses 03/28/2009 in the CalendarExtender1, I want the value of the txt2 to be the 03/29/2009....&lt;br /&gt;Also, if the month reaches the end, I want the txt2 to take the new moth.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;For example:&lt;br /&gt;If the user chooses 03/31/2009 in the CalendarExtender1, I want the value of the txt2 to be the 04/01/2009....&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;That behavior I want to exists only to the CalendarExtender1 like I describe it. I don't want the user to be able to do this with CalendarExtender2 (the CalendarExtender2 has the default behavior)... &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;color:#1f497d;"&gt;How can I accomplish that? Thank you very much!&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;There are two solutions provided to this requirement. Let me put them here.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Solution1: (By &lt;a href="http://forums.asp.net/members/kinjalin.aspx"&gt;Kinjalin&lt;/a&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Here you have to add it in Javascript.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="xhtml" name="code"&gt;&amp;lt;cc1:CalendarExtender ID=&amp;quot;ClExFromDt&amp;quot;                     runat=&amp;quot;server&amp;quot;                     TargetControlID=&amp;quot;TxtFromDate&amp;quot;                     PopupButtonID=&amp;quot;BtnFromCal&amp;quot;                     Format=&amp;quot;dd/MM/yyyy&amp;quot;                     OnClientDateSelectionChanged=&amp;quot;AddDate&amp;quot;                     CssClass=&amp;quot;calExt_Theme1&amp;quot;&amp;gt;&amp;lt;/cc1:CalendarExtender&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Here on OnBlur, write a Javascript function &lt;strong&gt;addDate&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;on Page_Load write the line " Text1.Attributes.Add("onblur", "javascript:addDate();")&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;&amp;amp; in Javascript Fetch the Value using document.getElementByID("TextBox1").value&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;add it using below Javascript &amp;amp; bit of ur Logic&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:10;"&gt;//create the date&lt;br /&gt;var myDate = new Date();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//add a day to the date&lt;br /&gt;myDate.setDate(myDate.getDate() + 1);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//add a week&lt;br /&gt;myDate.setDate(myDate.getDate() + 7);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;After  adding Show it in your TextBox2&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;$get(TextBox2).value = myDate&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Thats it.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Solution2: (By &lt;a href="http://forums.asp.net/members/sangam100.aspx"&gt;sangam100&lt;/a&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Hi &lt;a href="http://forums.asp.net/members/MinimalTech.aspx"&gt;&lt;span style="color:#034efa;"&gt;MinimalTech&lt;/span&gt;&lt;/a&gt; ,&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Here goes the prototype, which is close to what kinjalin posted:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Add this script in the design page:&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="javascript"&gt;&amp;lt;script&amp;gt;&lt;br /&gt;&lt;br&gt;    function addDays() {&lt;br /&gt;&lt;br&gt;        dateParts = document.getElementById('txtDate1').value.split('/');&lt;br /&gt;&lt;br&gt;        year  =  dateParts[2];&lt;br /&gt;&lt;br&gt;        month = parseInt(dateParts[0])-1;&lt;br /&gt;&lt;br&gt;        day   = parseInt(dateParts[1]) + 1;&lt;br /&gt;&lt;br&gt;        &lt;br /&gt;&lt;br&gt;        newDate = new Date ( year, month, day );&lt;br /&gt;&lt;br&gt;        year  = newDate.getYear();&lt;br /&gt;&lt;br&gt;       month = newDate.getMonth()+1;&lt;br /&gt;&lt;br&gt;       day   = newDate.getDate();&lt;br /&gt;&lt;br&gt;       formattedDate = month + '/' + day + '/' + year;&lt;br /&gt;&lt;br&gt;   &lt;br /&gt;&lt;br&gt;       document.getElementById('txtDate2').value=formattedDate;&lt;br /&gt;&lt;br&gt;   }&lt;br /&gt;&lt;br&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;Now in the design page:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="xhtml"&gt;Date1:&amp;lt;asp:TextBox ID=&amp;quot;txtDate1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;  Date2 (One day forward):&amp;lt;asp:TextBox ID=&amp;quot;txtDate2&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;cc1:CalendarExtender ID=&amp;quot;CalendarExtender1&amp;quot; runat=&amp;quot;server&amp;quot; TargetControlID=&amp;quot;txtDate1&amp;quot; PopupButtonID=&amp;quot;txtDate1&amp;quot;&amp;gt;&amp;lt;/cc1:CalendarExtender&amp;gt;&lt;/pre&gt;&lt;p&gt;In the code behind.&lt;span style="font-family:Courier New;font-size:10;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New;font-size:10;"&gt;txtDate1.Attributes.Add("onchange", "addDays();");&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Now this works.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Times New Roman;font-size:12;"&gt;Hope this will be useful to all. Happy Programming!&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-5603859121301665697?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/dh14NjHt_do" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/dh14NjHt_do/how-to-change-second-textbox-text-when.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/07/how-to-change-second-textbox-text-when.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-1886695854890886487</guid><pubDate>Fri, 26 Jun 2009 12:43:00 +0000</pubDate><atom:updated>2009-06-26T06:17:17.293-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server 2005</category><title>Convert date to different date string using Convert function of ms sql server 2005</title><description>&lt;span xmlns=""&gt;&lt;p&gt;Many times we need to convert datetime to different strings representing date, varying from 2009/06/2009 to June 26, 2009, and so on. Microsoft sql server 2005 can do the job for us! I had the same need some time ago, and sql server did this for me. (By the way, don't we programmers often find it irritating to have datetime representations different in different data base providers and different programming languages? Yes. Exactly here is what I am pointing towards what sql server 2005 can do for us. Follow the rest of this article for the magic!)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This is the syntax:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CONVERT (&lt;em&gt;data-type&lt;/em&gt;, &lt;em&gt;date-time-string-input&lt;/em&gt;, &lt;em&gt;date-display-style&lt;/em&gt;)&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Parameters:&lt;br /&gt;    &lt;strong&gt;data-type&lt;/strong&gt;: Any data type from nchar, nvarchar, char, varchar, binary, varbinary [length is optional, e.g. varchar(20) or varchar(22)&lt;br /&gt;    &lt;strong&gt;date-time-string-input&lt;/strong&gt;: Date time string supplied as input (You can use GETDATE() function etc.)&lt;br /&gt;    &lt;strong&gt;date-display-style&lt;/strong&gt;: The string style (You need '2009.06.26' or 'June 26, 2009' etc. You can even use the useful style number. Read on.)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;Note: If you provide insufficient length, you may be trimming your result!&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;Now, here is a list of the sql query and the result to the query that will introduce a number of the ways to get desired date strings.&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="csharp"&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),100) &lt;br /&gt;Result: Jun 26 2009 5:53PM&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),101) &lt;br /&gt;Result: 06/26/2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),102) &lt;br /&gt;Result: 2009.06.26&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),103) &lt;br /&gt;Result: 26/06/2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),104) &lt;br /&gt;Result: 26.06.2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),105) &lt;br /&gt;Result: 26-06-2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),106) &lt;br /&gt;Result: 26 Jun 2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),107) &lt;br /&gt;Result: Jun 26, 2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),108) &lt;br /&gt;Result: 17:49:42&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),109) &lt;br /&gt;Result: Jun 26 2009 5:50:02&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),110) &lt;br /&gt;Result: 06-26-2009&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),111) &lt;br /&gt;Result: 2009/06/26&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),113) &lt;br /&gt;Result: 26 Jun 2009 17:51:24&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),114) &lt;br /&gt;Result: 17:51:44:397&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),120) &lt;br /&gt;Result: 2009-06-26 18:00:17&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),121) &lt;br /&gt;Result: 2009-06-26 18:01:14&lt;br /&gt;&lt;br /&gt;SELECT CONVERT(VARCHAR(20),GETDATE(),126) &lt;br /&gt;Result: 2009-06-26T18:02:00&lt;/pre&gt;&lt;p&gt;As you can see, I have used the select statement to retrieve the desired sql query result. You can use it with any combination of sql query to perform any of the CRUD (Create, Read, Update and Delete) operations.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You can comment to add to the above list. It may be incomplete. Remember your participation is very important to make it more complete and more useful. You are as always heartily welcome to post you suggestions, comments, rate this article or spread the words by adding it to the social bookmarks! Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;a rev="vote-for" href="http://dotnetshoutout.com/Convert-date-to-different-date-string-using-Convert-function-of-ms-sql-server-2005"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fconvert-date-to-different-date-string.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Convert-date-to-different-date-string-using-Convert-function-of-ms-sql-server-2005"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fconvert-date-to-different-date-string.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-1886695854890886487?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/sOXJN1B1pHQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/sOXJN1B1pHQ/convert-date-to-different-date-string.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/convert-date-to-different-date-string.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-2339115224732523435</guid><pubDate>Wed, 10 Jun 2009 12:25:00 +0000</pubDate><atom:updated>2009-06-10T06:11:53.740-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET GridView</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Highlight gridview row on mouse over in asp net web page: Adding effects to the gridview control</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Programmers heavily use the asp.net gridview control. Adding some effects to the gridview will change the appearance so that user interactivity increases. One of such effects is highlighting the gridview row on mouseover. With this short background let's go for the design markup of the example gridview.&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;asp:GridView ID=&amp;quot;gridTest&amp;quot; runat=&amp;quot;server&amp;quot; OnRowDataBound=&amp;quot;gridTest_RowDataBound&amp;quot; AutoGenerateColumns=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&lt;br&gt;     &amp;lt;asp:BoundField HeaderText=&amp;quot;Status&amp;quot; DataField=&amp;quot;Status&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;     &amp;lt;asp:BoundField HeaderText=&amp;quot;Name&amp;quot; DataField=&amp;quot;Name&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;     &amp;lt;asp:BoundField HeaderText=&amp;quot;Comment&amp;quot; DataField=&amp;quot;Comment&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;     &amp;lt;asp:BoundField HeaderText=&amp;quot;Date&amp;quot; DataField=&amp;quot;Date&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;/asp:GridView&amp;gt;&lt;/pre&gt;&lt;p&gt;Now we have the asp.net gridview, why not choose the highlighted row's color? Let's define a style sheet class for highlighted row. &lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="css"&gt;&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;        /*for gridview row hover, select etc*/&lt;br /&gt;&lt;br&gt;        .normalrow&lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                background-color:white;&lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;        .highlightrow&lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                background-color:#cccccc;&lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;    &amp;lt;/style&amp;gt;&lt;/pre&gt;&lt;p&gt;(The gridview markup shown above is only for example purpose. So you will not see any matches between the figure showing highlighted row and the example markup. Further you will also need to implement your own css styling, if you prefer any). Note the OnRowDataBound event handler in the gridview design markup. We will write some lines of code in this event handler to add the effect of highlighting gridview rows on mouse over. Here goes the code.&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="csharp"&gt;//row created event&lt;br /&gt;    protected void gridTest_RowCreated(object sender, GridViewRowEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (e.Row.RowType == DataControlRowType.DataRow)&lt;br /&gt;        {&lt;br /&gt;            e.Row.Attributes.Add("onmouseover", "this.className='highlightrow'");&lt;br /&gt;            e.Row.Attributes.Add("onmouseout", "this.className='normalrow'");&lt;br /&gt;        } &lt;br /&gt;    }&lt;/pre&gt;&lt;p&gt;We have specified the css class to adapt by the gridview row on mouse over. At the same time, we need to assign another css class on mouse out so that the gridview will be highlighted only on mouseover and on mouse out the effect will be void. Happy programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhighlight-gridview-row-on-mouse-over-in.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhighlight-gridview-row-on-mouse-over-in.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Highlight-gridview-row-on-mouse-over-in-asp-net-web-page-Adding-effects-to-the-gridview-control"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhighlight-gridview-row-on-mouse-over-in.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Highlight-gridview-row-on-mouse-over-in-asp-net-web-page-Adding-effects-to-the-gridview-control"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhighlight-gridview-row-on-mouse-over-in.html" style="border:0px"/&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-2339115224732523435?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/aAWZjTFfxWU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/aAWZjTFfxWU/highlight-gridview-row-on-mouse-over-in.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/highlight-gridview-row-on-mouse-over-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-8199403817389553604</guid><pubDate>Tue, 09 Jun 2009 12:06:00 +0000</pubDate><atom:updated>2009-06-11T05:39:05.944-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>22 Visual Studio Short Keys and 6 Short-cut Ways to Custom Jobs: A List of Tips and Tricks</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Efficient programmers use short keys in IDE like Visual Studio. This saves time and in many cases makes the work run faster also. I also love short keys. They are smart! And there also go some tricks that help make your visual studio days a party!  I have listed here some short cuts and some tips with the hope that this will be helpful to you all.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Visual Studio Short-cuts&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Ctrl+F5&lt;/strong&gt; to run the website without debugging. &lt;strong&gt;F5&lt;/strong&gt; only will run the website in debugging mode.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Stop Debugging: &lt;strong&gt;Shift+F5&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;Restart Debugging: &lt;strong&gt;Ctrl+Shift+F5&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;Break All: &lt;strong&gt;Ctrl+Alt+Break&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;strong&gt;F11&lt;/strong&gt; to debug line by line downwards from the toggle point. This works with &lt;strong&gt;F10&lt;/strong&gt; also. In fact you can see &lt;strong&gt;F10&lt;/strong&gt; assigned for this task. See Debug menu in the visual studio.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;F9&lt;/strong&gt; to toggle a break point. &lt;br /&gt;&lt;/li&gt;&lt;li&gt;To delete all the break points at once: &lt;strong&gt;Ctrl+Shift+F9&lt;/strong&gt;. If you only wish to disable the break points you can go down the Debug menu.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Ctrl+S&lt;/strong&gt; to save the current document. &lt;strong&gt;Ctrl+Shift&lt;/strong&gt;+S to save all the documents at once.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Print a document directly from the visual studio? Press &lt;strong&gt;Ctrl+P&lt;/strong&gt;. This will bring the print dialog.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Ctrl+F&lt;/strong&gt; to find a text. A find dialog will be displayed. Then you are left with a number of options.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Ctrl+H&lt;/strong&gt; or &lt;strong&gt;Ctrl+Shift+H&lt;/strong&gt; for find and replace.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Ctrl+G&lt;/strong&gt; to go to the specific line number in the current document.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Open the web browser right from within the visual studio? Press &lt;strong&gt;Ctrl+Alt+R&lt;/strong&gt;.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Irritated switching back and forth the design view and code behind page of a file? Use &lt;strong&gt;F7&lt;/strong&gt; to navigate back and forth the files of a page.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Press &lt;strong&gt;F4&lt;/strong&gt; to view the properties window for a control from the design page.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;To view the server explorer: &lt;strong&gt;Ctrl+Alt+S&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;To view the solution explorer: &lt;strong&gt;Ctrl+Alt+L&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;To view the output window: &lt;strong&gt;Ctrl+Alt+O&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;To view the toolbox: &lt;strong&gt;Ctrl+Alt+X&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;Press &lt;strong&gt;Shift+Alt+Enter&lt;/strong&gt; to view/undo full screen.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Press &lt;strong&gt;Ctrl+O&lt;/strong&gt; to open a document from the project folder.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Ctrl+F11 to view disassembly: the machine level code!&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Visual Studio Tips&lt;br /&gt;&lt;/p&gt;&lt;ol style='margin-left: 38pt'&gt;&lt;li&gt;To view the start page, navigate&lt;strong&gt; View-&amp;gt;Other Windows-&amp;gt;Start Page&lt;/strong&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;To initiate the start page to display feed from a website, &lt;strong&gt;Tools-&amp;gt;Options-&amp;gt;Startup&lt;/strong&gt;.  Choose show start page at start from the combo fox. Input the start page news channel rss feed.  Click Ok.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;To display line numbers in the documents, &lt;strong&gt;Tools-&amp;gt;Options-&amp;gt;Text Editor&lt;/strong&gt;. Now click the editor you need to display number in. Check Line Numbers at the right side of the window.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Initiate the home page for the web browser [opened by pressing &lt;strong&gt;Ctrl+Alt+R&lt;/strong&gt;]? Follow &lt;strong&gt;Tools-&amp;gt;Options-&amp;gt;Environment-&amp;gt;Web Brower&lt;/strong&gt;. Set the home page and optionally the search page from the right side of the window.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Know the class name or method name but confused the right namespace? Right click the class name or method name and click Resolve; you will see the reference you need to add. Click the reference. It will be added for the page.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Using find window and clicking Find button each time to go to next match? Leave the trend. Just press F3 to go to next match!!&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Shortcuts are the small but useful ladders of programming. You can use them to go up and down, left and right or south and north. I would like to heartily welcome to share your tips and tricks that you have learned from your dedicated play around with the visual studio. All the tips and shortcuts I have listed above are tested and learned from visual studio 2005. They may or may not work in visual studio 2008 and later versions. You can specify the compatibility of your trick that you are posting as comment in this article. Thank you very much. Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2f22-visual-studio-short-keys-and-6-short.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2f22-visual-studio-short-keys-and-6-short.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-22-Visual-Studio-Short-Keys-and-6-Short-cut-Ways-to-Custom-Jobs-A-List-of-Tips-and-Tricks"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2F22-visual-studio-short-keys-and-6-short.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-22-Visual-Studio-Short-Keys-and-6-Short-cut-Ways-to-Custom-Jobs-A-List-of-Tips-and-Tricks"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2F22-visual-studio-short-keys-and-6-short.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-8199403817389553604?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/rxQN1bFq8AU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/rxQN1bFq8AU/22-visual-studio-short-keys-and-6-short.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">11</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/22-visual-studio-short-keys-and-6-short.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-2267557685399409978</guid><pubDate>Mon, 08 Jun 2009 12:26:00 +0000</pubDate><atom:updated>2009-06-09T06:01:15.592-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Email</category><title>How to read email address, host, port number from smtp settings section of web.config file in asp.net</title><description>&lt;span xmlns=''&gt;&lt;p&gt;How can I read the email address, smtp host, port number from my mail settings section of the web.config file in an asp.net web application? Yeah, we can specify an email address in the mail settings section of web.config file and read it from asp.net web page in the time of sending an email. We can also read the smtp host and port number which is necessary while sending email from an asp.net web page. I have already discussed: How to send email from asp.net web page. So here I would just put the coding to read email address, host, port number from mail settings section of web.config file in asp.net web application.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Let's look into the mail setting portion of a web.config file.&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;system.net&amp;gt;&lt;br /&gt;&lt;br&gt;  &amp;lt;mailSettings&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;smtp from=support@test.com&amp;gt;&lt;br /&gt;&lt;br&gt;      &amp;lt;network host=&amp;quot;mymailhostaddress&amp;quot; port=&amp;quot;25&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/smtp&amp;gt;&lt;br /&gt;&lt;br&gt;  &amp;lt;/mailSettings&amp;gt;&lt;br /&gt;&lt;br&gt;&amp;lt;/system.net&amp;gt;&lt;/pre&gt;&lt;p&gt;While sending an email, we need from, to email addresses and an smtp client also. So the code snippet below puts them together.&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="csharp"&gt;using System.Net.Mail;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Web.Configuration;&lt;br /&gt;using System.Net.Configuration;&lt;br /&gt;&lt;br /&gt; //the method to send email&lt;br /&gt;        public void SendMail()&lt;br /&gt;        {&lt;br /&gt;           Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);&lt;br /&gt;           MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;&lt;br /&gt;           SmtpSection smtpSection = mailSettings.Smtp;&lt;br /&gt;           //read the from email of the web.config file&lt;br /&gt;           string fromEmail = smtpSection.From;&lt;br /&gt;           int port = mailSettings.Smtp.Network.Port;&lt;br /&gt;           string host = mailSettings.Smtp.Network.Host; &lt;br /&gt;                    &lt;br /&gt;           //..other code follows from here&lt;br /&gt;           //that sends the email&lt;br /&gt;&lt;br /&gt;           //create new mailmessage object&lt;br /&gt;           MailMessage message = new MailMessage(new MailAddress(fromEmail), new MailAddress("anup@best.com"));&lt;br /&gt;           message.Body = "Hi. This is test message.";&lt;br /&gt;           message.Subject = "Test Message!";&lt;br /&gt;           message.IsBodyHtml = false;&lt;br /&gt;&lt;br /&gt;           //create smtp client and send mail&lt;br /&gt;           SmtpClient client = new SmtpClient(host, port);&lt;br /&gt;           try&lt;br /&gt;           {&lt;br /&gt;               client.Send(message);&lt;br /&gt;               lblError.Text = "Email sent successfully!";&lt;br /&gt;               lblError.ForeColor = Color.Green;&lt;br /&gt;           }&lt;br /&gt;           catch (Exception ex)&lt;br /&gt;           {&lt;br /&gt;               lblError.Text = "Email could not be sent. " + ex.Message;&lt;br /&gt;               lblError.ForeColor = Color.Red;&lt;br /&gt;           }&lt;br /&gt;       }&lt;/pre&gt;&lt;p&gt;Using the code above, we easily accessed the important information from mail settings section of the web.config file. Please note again that I have just put the coding of reading information form web.config file. You can learn from here to Send Email in asp.net web page so that you can combine what this article provides with sending email in asp.net web application. Happy Programming!&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-read-email-address-host-port.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-read-email-address-host-port.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-How-to-read-email-address-host-port-number-from-smtp-settings-section-of-webconfig-file-in-aspnet"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-read-email-address-host-port.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-How-to-read-email-address-host-port-number-from-smtp-settings-section-of-webconfig-file-in-aspnet"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-read-email-address-host-port.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-2267557685399409978?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/1sWS-OrWKQE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/1sWS-OrWKQE/how-to-read-email-address-host-port.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/how-to-read-email-address-host-port.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-739906100665861873</guid><pubDate>Tue, 02 Jun 2009 05:38:00 +0000</pubDate><atom:updated>2009-06-09T06:17:59.548-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>How to extract data out of your datacontrol (asp.net formview, detailsview or gridview) using FindControl or ExtractValuesFromCell method?</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Most of the times asp.net programmers need to extract data out of the asp.net datacontrols like formview, &lt;a href='http://dotnetspidor.blogspot.com/search/label/asp.net%20DetailsView'&gt;detailsview&lt;/a&gt; or &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt;. Mostly we use FindControl method of the data control for this purpose. And another method ExtractValuesFromCell is also entertained to achieve the goal. It would be very interesting to throw a little light upon both of them.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Naturally I am familiar with the FindControl method of the datacontrols. For example, to find a dropdownlist in the formview or detailsview control, I would call:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='background-color:silver'&gt;DropDownList ddlTest=FormView1.FindControl("DropDownList1") as DropDownList;&lt;/span&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;Similarly, we could search for an asp.net control in a particular row of a gridview control. For example:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='background-color:silver'&gt;GridViewRow row=GridView1.Rows[5];  // here we are dealing with the fifth row&lt;br/&gt;TextBox textName=row.Cells[2].FindControl("textboxName") as TextBox;  //here, there is a textbox with id textboxName in the second cell of the row&lt;br/&gt;if(textName!=null)  //check if such textbox was found in the specified cell or the specified row&lt;br/&gt;{&lt;br/&gt;   string name=textName.Text;&lt;br/&gt;}&lt;/span&gt;&lt;br /&gt;   &lt;/p&gt;&lt;p&gt;Practically we need to get a control from the data control in special events of the control like inserting, inserted, updating, updated, deleting, deleted, selectedindexchanging, selectedindexchanged etc. Combining the FindControl method with such event handlers help customize data during data operations (add,edit,delete) and provides flexibility to display data from database or other data sources (&lt;a href='http://dotnetspidor.blogspot.com/search/label/xml'&gt;xml&lt;/a&gt;, csv, &lt;a href='http://dotnetspidor.blogspot.com/2008/07/how-to-create-datatable.html'&gt;programmatically created datatables&lt;/a&gt; etc).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Before discussing ExtractValuesFromCell, I would like to drop one note. Please note that some standard controls in some data controls may be available for extracting only in the particular mode of the data controls. Confusing? Don't worry. This simple example will clarify it. Say, we do have a textbox in the edititemtemplate of a detailsview. To reference this textbox and extract value from it, we can use the findcontrol method only if we are in edit mode. In other modes we will get null reference (and possibly null reference exception may be thrown when we try to extract text or other properties). That is why I have checked for the null in the code above before reading text value from the textbox.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now let's focus on ExtractValuesFromCell.  There goes a popular article on &lt;a href='http://weblogs.asp.net/davidfowler/archive/2008/12/12/getting-your-data-out-of-the-data-controls.aspx?CommentPosted=true'&gt;Extracting data out of your datacontrol&lt;/a&gt; which discusses ExtractValuesFromCell method to get data from the controls in datacontrols like gridview, formview or detailsview. (The title of this article is inspired from it! And I have tried to make it as useful as I can). Please refer to the heavily discussed article to understand what the author &lt;a href='http://weblogs.asp.net/members/davidfowl.aspx'&gt;davidfoul&lt;/a&gt; has  discovered and what are the benefits of using ExtractValuesFromCell method to extract data out of a datacontrol. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;After you have been through the article, you sure would like to ask which method to use- FindControl or this ExtractValuesFromCell? This is what I commented to the author:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;Hi dear author,&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;I came here following the discussion on the asp.net forum: &lt;a target='_new' href='http://forums.asp.net/t/1362718.aspx'&gt;forums.asp.net/.../1362718.aspx&lt;/a&gt;&lt;br /&gt;    &lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;I have always been using FindControl() method: much easier and handy. You need not to write (and call everytime) the functions to extract values (or cells) using ExtractValuesFromCell.&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;This ExtractValuesFromCell way of extracting values from cell is just another way around it. So what's wrong to go with FindControl. Please give your opinion (perhaps you could update the post to add a sections: Why to not use FindControl(); I am requesting this because the argument among developers would go longer!).&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;Hey, this could be the advantage: People sometimes ask how to get all the values from my gridview since I have been editing and updating it, so changing the original value from the datasource. In such case this trick could help a lot.&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;Thanks.&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;And our generous author &lt;a href='http://weblogs.asp.net/members/davidfowl.aspx'&gt;davidfoul&lt;/a&gt; has replied his kind views:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;@&lt;a href='http://dotnetspidor.blogspot.com/2009/05/about-me.html'&gt;sangam100&lt;/a&gt; I had this same question about FindControl on the forum. Here is what I said:&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;It's not the use of FindControl that makes my spine tingle its the MISuse and ABuse of it that does. FindControl is a good method and very useful, but look at the name of method, FindControl. Everything has a purpose right? If I'm trying to find a control then i'll call find control. If I'm trying to get data out of a control I might call find control or some other API that is better at getting data, i.e ExtractRowValues. I think that there is alot of knowledge out there, good and bad, about using these data controls and I just want to try to set some things straight by shedding some more light on how stuff works (I love that website). &lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;Before I go lemme show you what I mean by picking the right API.  Lets make a new control IntControl. IntControl has a method int GetValue(). Now OO principals tell us to not break the abstraction by letting consumers grab at the internals but IntControl derives from control, and by default, there is alot of other things exposed to the consumer that shouldn't be. Now we know that IntControl uses a textbox internally so I could never call GetValue and instead write:&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;int value;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;Int32.TryParse(((TextBox)IntControl.Controls[0]).Text, out value);&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;Everything will work fine until the author of IntControl decides to use a div instead of a textbox.&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;The REAL lesson to take away from the blog post is to try your best to follow the contract provided by a class or an interface (in this case the DataControl).&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;You can read comments, views, suggestions of so many enthusiastic asp.net web developers both in the original site by the author and a post in the &lt;a target='_new' href='http://forums.asp.net/t/1362718.aspx'&gt;forums.asp.net/.../1362718.aspx.&lt;/a&gt;&lt;/span&gt; Please comment in the respective sites to put your opinions to the articles. However you can comment as always on this article regarding my perspectives. Thank you. Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-extract-data-out-of-your.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-extract-data-out-of-your.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-How-to-extract-data-out-of-your-datacontrol-aspnet-formview-detailsview-or-gridview-using-FindControl-or-ExtractValuesFromCell-method"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-extract-data-out-of-your.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-How-to-extract-data-out-of-your-datacontrol-aspnet-formview-detailsview-or-gridview-using-FindControl-or-ExtractValuesFromCell-method"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-extract-data-out-of-your.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-739906100665861873?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/HiphMLOjCec" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/HiphMLOjCec/how-to-extract-data-out-of-your.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/how-to-extract-data-out-of-your.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-7948811710527407158</guid><pubDate>Mon, 01 Jun 2009 12:02:00 +0000</pubDate><atom:updated>2009-06-09T06:18:22.284-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Email</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>How to send email from asp.net? Basic C# code to send simple email</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Sending email in asp.net is very useful and customizable too. The powerful classes help you compose and send email in minute! The glamour has always fascinated me, but more important is the frequent questions that are asked in asp.net related forums on sending email in asp.net using C# or vb.net. We can send email using some smtp server. And if this is not viable (sometimes we don't have smtp accounts!) we can use our own gmail account to send email (Thank you &lt;a href='http://mail.google.com'&gt;gmail&lt;/a&gt;!)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Take one example- Here goes the question that was asked in &lt;a href='http://forums.asp.net/t/1429775.aspx'&gt;asp.net forum&lt;/a&gt;-&lt;br/&gt;&lt;br/&gt;&lt;span style='font-family:Times New Roman'&gt;&lt;em&gt;&lt;span style='color:black'&gt;&lt;span style='font-size:27pt; background-color:silver'&gt;"&lt;/span&gt;&lt;span style='font-size:12pt; background-color:silver'&gt;can someone give me code how to send an e-mail from c# code&lt;br/&gt; I am working with a company using Microsoft outlook for my mails. &lt;br/&gt;I want to send mail only to 1 person, also please help me in identifying "smtp hostname"&lt;/span&gt;&lt;span style='font-size:27pt; background-color:silver'&gt;"&lt;/span&gt;&lt;/span&gt;&lt;span style='font-size:27pt'&gt;&lt;br /&gt;      &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Here goes the simple and helpful answer.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Visiting all above listed links you must have realized that sending email in asp.net is quite fun and useful too. In fact, a lot of customizations exist depending on your requirement. My suggestion is to do the basic email sending first. After that you can play with the classes and objects to perform more actions. Let me show you the basic email sending using c#.&lt;/span&gt; &lt;pre name="code" class="csharp"&gt;//sending basic mail in asp.net &lt;br /&gt;    public void SendBasicMail()&lt;br /&gt;    {&lt;br /&gt;        //create new mailmessage object&lt;br /&gt;        MailMessage message = new MailMessage(new MailAddress("sangam@test.com"), new MailAddress("anup@best.com"));&lt;br /&gt;        message.Body = "Hi. This is test message.";&lt;br /&gt;        message.Subject = "Test Message!";&lt;br /&gt;        message.IsBodyHtml = false;&lt;br /&gt;&lt;br /&gt;        //create smtp client and send mail&lt;br /&gt;        SmtpClient client = new SmtpClient("mail.mysmtpserver.com", 25);&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            client.Send(message);&lt;br /&gt;            lblError.Text = "Email sent successfully!";&lt;br /&gt;            lblError.ForeColor = Color.Green;&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            lblError.Text = "Email could not be sent. " + ex.Message;&lt;br /&gt;            lblError.ForeColor = Color.Red;&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;This simple example will help you understand the basics of sending email in asp.net web application.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now interested in sending email using our own gmail account? Here goes the coding by &lt;a href='http://forums.asp.net/members/getchinna_5F00_sv.aspx'&gt; getchinna_sv&lt;/a&gt; (Thank you &lt;a href='http://forums.asp.net/members/getchinna_5F00_sv.aspx'&gt;getchinna_sv&lt;/a&gt;! Yours &lt;a href='http://forums.asp.net/members/sangam100.aspx'&gt;sangam100&lt;/a&gt;).&lt;/span&gt;&lt;pre name="code" class="csharp"&gt; protected void sendMail()&lt;br /&gt;    {&lt;br /&gt;        string from = "me@gmail.com"; //Replace this with your own correct Gmail Address&lt;br /&gt;        string to = "you@gmail.com"; //Replace this with the Email Address to whom you want to send the mail&lt;br /&gt;        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();&lt;br /&gt;        mail.To.Add(to);&lt;br /&gt;        mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);&lt;br /&gt;        mail.Subject = "This is a test mail";&lt;br /&gt;        mail.SubjectEncoding = System.Text.Encoding.UTF8;&lt;br /&gt;        mail.Body = "This is Email Body Text";&lt;br /&gt;        mail.BodyEncoding = System.Text.Encoding.UTF8;&lt;br /&gt;        mail.IsBodyHtml = true;&lt;br /&gt;        mail.Priority = MailPriority.High;&lt;br /&gt;&lt;br /&gt;        SmtpClient client = new SmtpClient();&lt;br /&gt;        //Add the Creddentials- use your own email id and password&lt;br /&gt;        client.Credentials = new System.Net.NetworkCredential(from, "Password");&lt;br /&gt;        client.Port = 587; // Gmail works on this port&lt;br /&gt;        client.Host = "smtp.gmail.com";&lt;br /&gt;        client.EnableSsl = true; //Gmail works on Server Secured Layer&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            client.Send(mail);&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Exception ex2 = ex;&lt;br /&gt;            string errorMessage = string.Empty;&lt;br /&gt;            while (ex2 != null)&lt;br /&gt;            {&lt;br /&gt;                errorMessage += ex2.ToString();&lt;br /&gt;                ex2 = ex2.InnerException;&lt;br /&gt;            }&lt;br /&gt;            HttpContext.Current.Response.Write(errorMessage);&lt;br /&gt;        } // end try &lt;br /&gt;    } &lt;/pre&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;client.Credentials = new System.Net.NetworkCredential(from, "Password"); in this statement... write your gmail password.... from address should be a gmail address....  &lt;br/&gt;&lt;br/&gt;Hope this post will help. Thank you. Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-send-email-from-aspnet-basic-c.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fhow-to-send-email-from-aspnet-basic-c.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-How-to-send-email-from-aspnet-Basic-C-code-to-send-simple-email"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-send-email-from-aspnet-basic-c.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-How-to-send-email-from-aspnet-Basic-C-code-to-send-simple-email"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fhow-to-send-email-from-aspnet-basic-c.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-7948811710527407158?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/AG2mzZ19b-g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/AG2mzZ19b-g/how-to-send-email-from-aspnet-basic-c.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/how-to-send-email-from-aspnet-basic-c.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-5430234710700525359</guid><pubDate>Mon, 01 Jun 2009 11:31:00 +0000</pubDate><atom:updated>2009-06-09T06:18:48.943-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">DropdownList</category><title>Dropdownlist selected item validation fails: the suggestion</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Today I got across a question in the &lt;a href='http://forums.asp.net'&gt;asp.net forum&lt;/a&gt; which seems simple but is still confusing for many beginners. So I am giving a place for it here:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;Question:&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Hi Everyone,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;I'm trying to set some error handling by returning a message when a button is clicked and the user has not selected an item from the dropdown menu. I'm using this but for some reason it is being ignored?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;pre name="code" class="csharp"&gt;protected void validatebtn_Click(object sender, ImageClickEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!(DropDownList1.SelectedValue == "Select Item"))&lt;br /&gt;        {&lt;br /&gt;            lblerrors.Text = "&lt;br&gt;You have not selected an item from the drop down list.";&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            //...continue with the code.&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;When I debug the code, it reads the first line:&lt;br/&gt;&lt;br /&gt;     &lt;span style='color:blue'&gt;if&lt;/span&gt; (!(DropDownList1.SelectedValue == &lt;span style='color:#a31515'&gt;"Select Item"&lt;/span&gt;)) &lt;br/&gt;and then skips to the else statement and misses my message?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Can anyone advise why this is happening?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Thanks.&lt;br/&gt;Chloe ~X~&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Among other suggestions, here is what I have suggested:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;em&gt;Answer:&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;Looking into your explanation and reading all the answers given by members, some questions came in my mind.&lt;br/&gt;&lt;br/&gt;1. Did you check what value is exactly selected from the dropdownlist? I mean DropDownList1.SelectedValue should be "Select Item" only then your comparision will be true.&lt;br/&gt;2. Are you adding this "Select Item" from design view or is it added programmatically from code behind? Did you only specify "text" or both text and value? See the markup below:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;asp:DropDownList ID=&amp;quot;ddlTest&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;asp:ListItem Text=&amp;quot;Select Item&amp;quot; Value=&amp;quot;Select Item&amp;quot; Selected=&amp;quot;True&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;span style='color:black'&gt;If you don't put Selected="true", this item may display at the first position, but is not selected yet. So don't forget to set this. Another thing to notice is you should have set both Text and Value. The "SelectedValue" corresponds to the "Value" in the markup. Only then your code will work. Don't forget to have both text and value if you add listitem to the dropdownlist from codebehind, like this one:&lt;pre name="code" class="csharp"&gt;ListItem item = new ListItem("Select Item", "Select Item");&lt;br /&gt;DropDownList1.Items.Add(item);&lt;/pre&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style='font-family:Times New Roman; font-size:12pt'&gt;&lt;span style='color:black'&gt;Hope this helps. Please feel free to ask if the problem persists or if further help is required. Thanks.&lt;/span&gt;&lt;span style='color:blue'&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fdropdownlist-selected-item-validation.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f06%2fdropdownlist-selected-item-validation.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Dropdownlist-selected-item-validation-fails-the-suggestion"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fdropdownlist-selected-item-validation.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Dropdownlist-selected-item-validation-fails-the-suggestion"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F06%2Fdropdownlist-selected-item-validation.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-5430234710700525359?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/nd_FipuCuYQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/nd_FipuCuYQ/dropdownlist-selected-item-validation.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/06/dropdownlist-selected-item-validation.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-7417957911881108811</guid><pubDate>Fri, 29 May 2009 12:52:00 +0000</pubDate><atom:updated>2009-06-09T06:24:58.329-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET GridView</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Check uncheck all rows of gridview (select or deselect all rows at once)</title><description>&lt;span xmlns=''&gt;&lt;p&gt;The asp.net &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt; data control offers lots of features, that we all know. Adding some cool effects may make this control more usable. For instance, we could check or uncheck all the checkboxes in a column of the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt; control. A column [leftmost column usually] consisting of checkbox control is generally used to select a row. Sometimes we may need to check (and uncheck) all the rows of the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt;. Purpose of doing so may be different depending upon the business requirement. And if we need to do so, we can!&lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/Sh_l1u53aPI/AAAAAAAAAFE/TWzWflJfOGM/s1600-h/check+uncheck+all+checkboxes+in+asp+net+gridview.bmp"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 355px; height: 88px;" src="http://3.bp.blogspot.com/_1sICTF7VWbI/Sh_l1u53aPI/AAAAAAAAAFE/TWzWflJfOGM/s400/check+uncheck+all+checkboxes+in+asp+net+gridview.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5341240394371262706" /&gt;&lt;/a&gt;&lt;br/&gt;Fig. Check Uncheck all rows in a gridview&lt;/p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Let's be quick to implement check/uncheck all the rows of &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt; at once in asp.net &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt;. Let's have the markup for the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt; first.&lt;pre name="code" class="xhtml"&gt;&amp;lt;asp:GridView ID=&amp;quot;gvTest&amp;quot; Width=&amp;quot;100%&amp;quot; runat=&amp;quot;server&amp;quot; AutoGenerateColumns=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;Columns&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;asp:TemplateField HeaderText=&amp;quot;Select&amp;quot; HeaderStyle-HorizontalAlign=&amp;quot;center&amp;quot; ItemStyle-HorizontalAlign=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;HeaderTemplate &amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;input id=&amp;quot;chkAll&amp;quot; onclick=&amp;quot;javascript:SelectDeselectAllCheckboxes(this);&amp;quot; &lt;br /&gt;&lt;br&gt;                          runat=&amp;quot;server&amp;quot; type=&amp;quot;checkbox&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;/HeaderTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;asp:CheckBox ID=&amp;quot;chkSelect&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;asp:BoundField HeaderText=&amp;quot;Name&amp;quot; DataField=&amp;quot;Name&amp;quot; ItemStyle-Width=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;asp:BoundField HeaderText=&amp;quot;Address&amp;quot; DataField=&amp;quot;Address&amp;quot; /&amp;gt;            &lt;br /&gt;&lt;br&gt;        &amp;lt;/Columns&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/asp:GridView&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Watched the checkbox control in the header template of the first column? We will use this checkbox to select or deselect all the rows in the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt;. Also mark that clicking this checkbox will call the &lt;a href='http://dotnetspidor.blogspot.com/search/label/JavaScript'&gt;javascript&lt;/a&gt; function &lt;span style='color:blue; font-family:Courier New; font-size:10pt'&gt;SelectDeselectAllCheckboxes. &lt;/span&gt;Now is the time to define some &lt;a href='http://dotnetspidor.blogspot.com/search/label/JavaScript'&gt;javascript&lt;/a&gt; snippets to get help from.&lt;pre name="code" class="javascript"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;  &lt;br /&gt;&lt;br&gt;     function SelectDeselectAllCheckboxes(spanChk){&lt;br /&gt;&lt;br&gt;       // Added as ASPX uses SPAN for checkbox&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;       var oItem = spanChk.children;&lt;br /&gt;&lt;br&gt;       var theBox= (spanChk.type==&amp;quot;checkbox&amp;quot;) ? spanChk : spanChk.children.item[0];&lt;br /&gt;&lt;br&gt;       xState=theBox.checked;&lt;br /&gt;&lt;br&gt;       elm=theBox.form.elements;&lt;br /&gt;&lt;br&gt;       for(i=0;i&amp;lt;elm.length;i++)&lt;br /&gt;&lt;br&gt;         if(elm[i].type==&amp;quot;checkbox&amp;quot; &amp;&amp; elm[i].id!=theBox.id)&lt;br /&gt;&lt;br&gt;         {&lt;br /&gt;&lt;br&gt;           //elm[i].click();&lt;br /&gt;&lt;br&gt;           if(elm[i].checked!=xState)&lt;br /&gt;&lt;br&gt;             elm[i].click();&lt;br /&gt;&lt;br&gt;           //elm[i].checked=xState;&lt;br /&gt;&lt;br&gt;         }&lt;br /&gt;&lt;br&gt;     }&lt;br /&gt;&lt;br&gt;    &amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The task done by the &lt;a href='http://dotnetspidor.blogspot.com/search/label/JavaScript'&gt;javascript&lt;/a&gt; function is simple.  It takes the checkbox itself as the input. If it is checked, it searches for all the checkboxes in the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt; and checks them. And reversely, if it is unchecked, all those checkboxes will be consequently unchecked.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;There is no need of any codebehind just for this functionality. So I am leaving other parts including databinding code. In fact, for most of the test purposes I do &lt;a href='http://dotnetspidor.blogspot.com/2008/07/how-to-create-datatable.html'&gt;Create DataTable Programmatically&lt;/a&gt; and bind the &lt;a href='http://dotnetspidor.blogspot.com/search/label/ASP.NET%20GridView'&gt;gridview&lt;/a&gt;, formview or &lt;a href='http://dotnetspidor.blogspot.com/search/label/asp.net%20DetailsView'&gt;detailsview&lt;/a&gt; to that &lt;a href='http://dotnetspidor.blogspot.com/search/label/DataTable'&gt;DataTable&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The only drawback with this technique is that it treats all the checkboxes in or outside the gridview control equal.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You can post your comment, rate this post or add this post to your favourites or share it. Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2fcheck-uncheck-all-rows-of-gridview.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2fcheck-uncheck-all-rows-of-gridview.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Check-uncheck-all-rows-of-gridview-select-or-deselect-all-rows-at-once"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Fcheck-uncheck-all-rows-of-gridview.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Check-uncheck-all-rows-of-gridview-select-or-deselect-all-rows-at-once"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Fcheck-uncheck-all-rows-of-gridview.html" style="border:0px"/&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-7417957911881108811?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/Tm9MX5f2giY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/Tm9MX5f2giY/check-uncheck-all-rows-of-gridview.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_1sICTF7VWbI/Sh_l1u53aPI/AAAAAAAAAFE/TWzWflJfOGM/s72-c/check+uncheck+all+checkboxes+in+asp+net+gridview.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/check-uncheck-all-rows-of-gridview.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-3488587372955713345</guid><pubDate>Wed, 27 May 2009 12:12:00 +0000</pubDate><atom:updated>2009-06-09T06:28:48.285-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET Control</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Fill asp.net formview textbox to initial value in insert mode</title><description>&lt;span xmlns=''&gt;&lt;p&gt;In most scenarios, the asp.net data controls like detailsview and formview have empty controls in insert mode. This means any field that requires [or at least expects] user input will not contain any data. But this default configuration sometimes needs to be modified. Say, we would like to fill the date field in a textbox to current date, so that it will be easier for user. This is just an example. This can be the asp.net dropdownlist from where we would like to select one value initially, or it may be other asp.net user input control like checkbox or radiobutton. In such scenario, we can set the control value to some default initial value. With datacontrols like formview and detailsview, it takes a little effort [simple and tricky!]. In this short post [In fact I am expecting to keep this post as such as possible since there is no need of much explanation: concept is crystal clear and implementation is also easy!] I am going to show the simple coding practice to initiate the formview or detailsview control to some value. I will be choosing formview to show the example.&lt;/p&gt;&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_1sICTF7VWbI/Sh0v0wSBUII/AAAAAAAAAE8/wj1QdYim18o/s1600-h/fill+formview+textbox+with+default+value+in+insert+mode.bmp"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 312px; height: 92px;" src="http://4.bp.blogspot.com/_1sICTF7VWbI/Sh0v0wSBUII/AAAAAAAAAE8/wj1QdYim18o/s400/fill+formview+textbox+with+default+value+in+insert+mode.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5340477316491464834" /&gt;&lt;/a&gt;&lt;br /&gt;Fig: Setting a textbox to an initial value in insert mode of an asp.net formview control&lt;/p&gt;&lt;p&gt;The formview can have one of three modes at one instance of time. They are Insert, Edit and ReadOnly modes. We should be careful about the current mode of the formview before we do reference any control. This is because a textbox in edit template may not be available in the read only mode, for instance. So we will check the current mode of the formview and search for the textbox with its ID. Then we can easily set the value of the control. Let's have a formview first.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;FormsView Design Markup&lt;br /&gt;&lt;/strong&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;asp:FormView ID=&amp;quot;FormView1&amp;quot; runat=&amp;quot;server&amp;quot; HeaderText=&amp;quot;Fill the Credentials below.&amp;quot; DefaultMode=&amp;quot;Insert&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;table&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;td&amp;gt;&lt;br /&gt;&lt;br&gt;                            Name: &amp;lt;asp:Label ID=&amp;quot;lblName&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;td&amp;gt;&lt;br /&gt;&lt;br&gt;                            Date of Test: &amp;lt;asp:Label ID=&amp;quot;lblTestDate&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;InsertItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;table&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;td&amp;gt;&lt;br /&gt;&lt;br&gt;                            Name: &amp;lt;asp:TextBox ID=&amp;quot;txtName&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;td&amp;gt;&lt;br /&gt;&lt;br&gt;                            Date of Test: &amp;lt;asp:TextBox ID=&amp;quot;txtTestDate&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;                &amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;/InsertItemTemplate&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;/asp:FormView&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;We simply have two fields in the formview: name and date of test. Our intension will be to initiate the value of the &lt;strong&gt;date of test &lt;/strong&gt;field to current date.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CodeBehind for the example&lt;br /&gt;&lt;/strong&gt;&lt;pre name="code" class="csharp"&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            //Call to filling textbox in the insert mode;&lt;br /&gt;            //I assume here that initially the formview&lt;br /&gt;            //is in insert mode&lt;br /&gt;            FillDefaultVaueInFormView();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void FillDefaultVaueInFormView()&lt;br /&gt;    {&lt;br /&gt;        //if the formview is in insert mode&lt;br /&gt;        if (FormView1.CurrentMode == FormViewMode.Insert)&lt;br /&gt;        {&lt;br /&gt;            //txtTestDate is the id of the 'date of text' textbox in formview&lt;br /&gt;            TextBox txtTest = FormView1.FindControl("txtTestDate") as TextBox;&lt;br /&gt;            if (txtTest != null)&lt;br /&gt;            {&lt;br /&gt;                txtTest.Text = DateTime.Now.ToShortDateString();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;Now the formview will have the date of test field initiated to the current date. Let me repeat- Simple and Tricky! You can post your comments and suggestions from the form below. You can rate this post as well. You can even share this post. Just add this post to the social sites! Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2ffill-aspnet-formview-textbox-to-initial.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2ffill-aspnet-formview-textbox-to-initial.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Fill-aspnet-formview-textbox-to-initial-value-in-insert-mode"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Ffill-aspnet-formview-textbox-to-initial.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/Fill-aspnet-formview-textbox-to-initial-value-in-insert-mode"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Ffill-aspnet-formview-textbox-to-initial.html" style="border:0px"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-3488587372955713345?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/_DVANBtyO24" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/_DVANBtyO24/fill-aspnet-formview-textbox-to-initial.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_1sICTF7VWbI/Sh0v0wSBUII/AAAAAAAAAE8/wj1QdYim18o/s72-c/fill+formview+textbox+with+default+value+in+insert+mode.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/fill-aspnet-formview-textbox-to-initial.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-7870474471709258209</guid><pubDate>Fri, 22 May 2009 13:15:00 +0000</pubDate><atom:updated>2009-06-09T06:34:07.200-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Click the button on keypress in asp.net TextBox</title><description>&lt;span xmlns=''&gt;&lt;p&gt;In this post, I am explaining the button click functionality on key press in a textbox. I am using javascript to link the input textbox and the associated button that has to be clicked when the enter key is pressed in the textbox. One can preview it by taking the example of search textbox and GO button!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://1.bp.blogspot.com/_1sICTF7VWbI/ShamfsmmgMI/AAAAAAAAAE0/kAafLYFdly8/s1600-h/button+click+on+pressing+enter+key+in+asp+net+web+page.bmp"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 341px; height: 49px;" src="http://1.bp.blogspot.com/_1sICTF7VWbI/ShamfsmmgMI/AAAAAAAAAE0/kAafLYFdly8/s400/button+click+on+pressing+enter+key+in+asp+net+web+page.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5338637471773524162" /&gt;&lt;/a&gt;&lt;br/&gt;&lt;i&gt;Fig. Clicking asp.net button on enter key press in textbox&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We have seen search textboxes in almost all of the websites which imply 'Go' or 'Search' button click when Return key (Enter key) is pressed. Naturally, users love to press enter key instead of clicking search button next to the input textbox. Wouldn't it be nice if we could do the same for our web pages also? Yeah, I have implemented the button click feature on keypress in textbox control many times. But the last time practice on a web application that added both the textbox and the search button dynamically via javascript was really interesting story that inspired me to re-share the code [since I also learnt it on Internet].&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Design Page Markup (SearchPage.aspx)&lt;br/&gt;&lt;/strong&gt;We do have one textbox and one button in the search page.&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;div&amp;gt;&lt;br /&gt;&lt;br&gt;    Search Text: &amp;lt;asp:TextBox ID=&amp;quot;txtSearchBox&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br&gt;     &amp;lt;asp:Button ID=&amp;quot;btnSearch&amp;quot; runat=&amp;quot;server&amp;quot; Text=&amp;quot;Search&amp;quot; OnClick=&amp;quot;btnSearch_Click&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;JavaScript Code    &lt;br/&gt;&lt;/strong&gt;This javascript code will be invoked when enter key is pressed in the textbox.&lt;pre name="code" class="javascript"&gt;&amp;lt;script&amp;gt;&lt;br /&gt;&lt;br&gt;        function clickButton(e, buttonid){ &lt;br /&gt;&lt;br&gt;          var evt = e ? e : window.event;&lt;br /&gt;&lt;br&gt;          var bt = document.getElementById(buttonid);&lt;br /&gt;&lt;br&gt;          if (bt){ &lt;br /&gt;&lt;br&gt;              if (evt.keyCode == 13){ &lt;br /&gt;&lt;br&gt;                    bt.click(); &lt;br /&gt;&lt;br&gt;                    return false; &lt;br /&gt;&lt;br&gt;              } &lt;br /&gt;&lt;br&gt;          } &lt;br /&gt;&lt;br&gt;        }&lt;br /&gt;&lt;br&gt;    &amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We put this javascript code snippet within the head section of the design page.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Code Behind (SearchPage.aspx.cs)&lt;br /&gt;&lt;/strong&gt;&lt;pre name="code" class="csharp"&gt;//page load event handler&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            //add attribute on the search textbox&lt;br /&gt;            //so that when enter key is pressed in the textbox,&lt;br /&gt;            //the search button will be fired&lt;br /&gt;            txtSearchBox.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSearch.ClientID + "')");                                               &lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //when search button is clicked&lt;br /&gt;    protected void btnSearch_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        //my function to perform search        &lt;br /&gt;    }&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;Here we add the onkeypress attribute to the textbox. When a key is pressed, the keycode will be passed to the javascript function. The javascript function checks if this is the enter key, and it is enter key then the button click is invoked by the javascript code.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;So far we implemented button click on enter key press from an asp.net web control. To add a little user interactivity in the search textbox, you can implement google search like watermark effect in the search textbox.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Don't forget to expose your views via comment box beneath this post. You can freely share this post! Happy Programming!&lt;/p&gt;&lt;/span&gt;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Click-the-button-on-keypress-in-aspnet-TextBox"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Fclick-button-on-keypress-in-aspnet.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Click-the-button-on-keypress-in-aspnet-TextBox"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Fclick-button-on-keypress-in-aspnet.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2fclick-button-on-keypress-in-aspnet.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2fclick-button-on-keypress-in-aspnet.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-7870474471709258209?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/Ynn7S5Aws1c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/Ynn7S5Aws1c/click-button-on-keypress-in-aspnet.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_1sICTF7VWbI/ShamfsmmgMI/AAAAAAAAAE0/kAafLYFdly8/s72-c/button+click+on+pressing+enter+key+in+asp+net+web+page.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/click-button-on-keypress-in-aspnet.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-4542250902423541654</guid><pubDate>Mon, 18 May 2009 13:52:00 +0000</pubDate><atom:updated>2009-05-19T06:56:11.822-07:00</atom:updated><title>Contact Me</title><description>&lt;iframe height="632" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none"  src="http://sangam.wufoo.com/embed/z7x4m1/"&gt;&lt;a href="http://sangam.wufoo.com/forms/z7x4m1/" title="Contact me!"&gt;Fill out my Wufoo form!&lt;/a&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-4542250902423541654?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/tnl9NBVqlHU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/tnl9NBVqlHU/contact-me.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/contact-me.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-3095645744100197541</guid><pubDate>Mon, 18 May 2009 13:26:00 +0000</pubDate><atom:updated>2009-05-18T06:26:58.733-07:00</atom:updated><title>Thank you!</title><description>&lt;span xmlns=''&gt;&lt;p&gt;Dear reader,&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Thank you for taking time to drop your feedback/suggestion/query. An email has been sent to you to confirm your action. I will be listening you very soon!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You can now go to &lt;a href='http://dotnetspidor.blogspot.com'&gt;dotNETspidor home page&lt;/a&gt; and enjoy your day!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Thank you very much. Have nice &lt;a href='http://dotnetspidor.blogspot.com'&gt;dotNETspidor&lt;/a&gt; surfing!&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-3095645744100197541?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/5Q2a-xpo5Lk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/5Q2a-xpo5Lk/thank-you.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/thank-you.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-4769000201103581122</guid><pubDate>Mon, 18 May 2009 13:13:00 +0000</pubDate><atom:updated>2009-05-19T07:14:20.665-07:00</atom:updated><title>About Me</title><description>&lt;a href="http://4.bp.blogspot.com/_1sICTF7VWbI/ShK-eCufM4I/AAAAAAAAAEs/O7QogvxdPNM/s1600-h/sangam+Uprety+asp.net+programmer.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5337537931724665730" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 315px; CURSOR: hand; HEIGHT: 400px" alt="" src="http://4.bp.blogspot.com/_1sICTF7VWbI/ShK-eCufM4I/AAAAAAAAAEs/O7QogvxdPNM/s400/sangam+Uprety+asp.net+programmer.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;span xmlns=""&gt;&lt;br /&gt;&lt;p&gt;My name is Sangam Uprety, a computer engineer from Nepal. For 2 years I have been programming &lt;a href="http://asp.net/"&gt;asp.net&lt;/a&gt; web applications. I do love playing with javascript and ajax for client side programming. I do program SQL Server and Oracle databases. I also code &lt;a href="http://dotnetnuke.com/"&gt;DotNetNuke (DNN)&lt;/a&gt; modules for portal development. In fact developing multi-featured portals is my passion!&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Besides programming, I love reading books. Songs? Obviously, all kinds! I don't find myself anywhere if there are no social activities in my life. I believe social works have always saved nations.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;I love watching football games. Ok..ok..did I mention I do write also? If I didn't, no problem. I love writing. Thanks goes to &lt;a href="http://en.wikipedia.org/wiki/Karl_Marx"&gt;Karl Marx&lt;/a&gt; who said that people who write diaries never fail! And I do run a blog. Yeah, &lt;a href="http://dotnetspidor.blogspot.com/"&gt;dotNETspidor: A dot net programming blog&lt;/a&gt; !&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Would like to contact me or just drop me some words? Ok, you are heartily welcome to &lt;a href="http://dotnetspidor.blogspot.com/2009/05/contact-me.html"&gt;Leave Your Valuable Message/Feedback/Suggestions &lt;/a&gt;right from this blog!&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Thank you for being interested about me!&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-4769000201103581122?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/_e_i8_dCmv8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/_e_i8_dCmv8/about-me.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_1sICTF7VWbI/ShK-eCufM4I/AAAAAAAAAEs/O7QogvxdPNM/s72-c/sangam+Uprety+asp.net+programmer.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/about-me.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-861194928933391682</guid><pubDate>Mon, 18 May 2009 12:16:00 +0000</pubDate><atom:updated>2009-05-18T05:39:00.139-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET GridView</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">Files</category><title>List all files in a folder in an asp.net gridview</title><description>&lt;span xmlns=''&gt;&lt;p&gt;We do have a folder (and a number of sub folders) with a number of various files in those folders (and sub folders). Now we do need to list all those files in an asp.net gridview control [for the purpose of organizing those files, or for the preview of files uploaded till now, say]. We can do it in asp.net using the System.IO namespace. In this article, I am going to show the coding for displaying all files in a folder in an asp.net gridview. In fact, as a bonus, we will do the listing of all files in a root folder and all its subfolders also. &lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_1sICTF7VWbI/ShFTRbQZPvI/AAAAAAAAAEk/tukR0EMJKZQ/s1600-h/display+all+file+in+folder+in+gridview+in+asp.net.bmp"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 272px;" src="http://2.bp.blogspot.com/_1sICTF7VWbI/ShFTRbQZPvI/AAAAAAAAAEk/tukR0EMJKZQ/s400/display+all+file+in+folder+in+gridview+in+asp.net.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5337138592250150642" /&gt;&lt;/a&gt;&lt;br /&gt;Fig: Snapshot of displaying all files in a folder and its subfolders in an asp.net gridview control&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Design Page Markup (ListFiles.aspx)&lt;br/&gt;We first need to have a web page with the gridview control in it.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;        &amp;lt;asp:GridView ID=&amp;quot;GridView1&amp;quot; runat=&amp;quot;server&amp;quot; AutoGenerateColumns=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;       &lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;Remember, we have set the AutoGenerateColumns field to true. So all the fields that is present in our source will be displayed by the gridview, each as a separate column. (I have removed the formatting of the gridview markup to make the code clear. Please your own formatting for the gridview.)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Code behind page (ListFiles.aspx.cs)&lt;br/&gt;Now here goes the actual code to bind all the files in the folder "Resources", that resides at the root of the web site, and all its subfolders.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="csharp"&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            GetFilesAndFolders();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void GetFilesAndFolders()&lt;br /&gt;    {&lt;br /&gt;        DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/Resources"));&lt;br /&gt;        FileInfo[] fileInfo = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);&lt;br /&gt;        GridView1.DataSource = fileInfo;&lt;br /&gt;        GridView1.DataBind();      &lt;br /&gt;    }&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;We have used the DirectoryInfo and FileInfo classes of the System.IO namespaces. The DirectoryInfo class will get the root directory of the provided folder name. And we have used the DirectoryInfo class's GetFiles method. This method has two overloads. We can specify the file patterns (e.g. "*.txt" for text files only, or "*.*" for all types of files etc) and the search option- if to list all the files in all the subdirectories of the root directory (in our case, "Resources" folder) provided as the input, or just to list the files in the root directory.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;When we browse the page, we see the gridview populated with 13 fields, which I hope need no explanation. However for your reference I have listed the fields here: LastAccessTimeUtc, Length, LastWriteTime, LastWriteTimeUtc, FullName, IsReadOnly, CreationTimeUtc, LastAccessTime, CreationTime, Name, Exists, Extention, and DirectoryName. For the description of each field, please visit &lt;a href='http://msdn.microsoft.com/en-us/library/system.io.fileinfo_properties(VS.80).aspx'&gt;FileInfo class Properties, msdn document&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now from those thirteen fields, we can choose and display the required ones. Please don't forget to share your views, suggestions or comments as always. Thank you. Happy programming!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2flist-all-files-in-folder-in-aspnet.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f05%2flist-all-files-in-folder-in-aspnet.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-List-all-files-in-a-folder-in-an-aspnet-gridview"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Flist-all-files-in-folder-in-aspnet.html" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-List-all-files-in-a-folder-in-an-aspnet-gridview"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F05%2Flist-all-files-in-folder-in-aspnet.html" style="border:0px"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-861194928933391682?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/okupjTQ79Zw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/okupjTQ79Zw/list-all-files-in-folder-in-aspnet.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_1sICTF7VWbI/ShFTRbQZPvI/AAAAAAAAAEk/tukR0EMJKZQ/s72-c/display+all+file+in+folder+in+gridview+in+asp.net.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/05/list-all-files-in-folder-in-aspnet.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-738632935313488597</guid><pubDate>Sat, 25 Apr 2009 07:21:00 +0000</pubDate><atom:updated>2009-05-05T05:37:33.611-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DataTable</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET Control</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">xml</category><title>Bind asp.net dropdownlist to xml file</title><description>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_1sICTF7VWbI/SfK8rKZ7nrI/AAAAAAAAAEc/ESZhnmrnpvY/s1600-h/bind+xml+file+to+asp+net+dropdownlist.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5328528758846234290" style="WIDTH: 391px; CURSOR: hand; HEIGHT: 125px" alt="" src="http://4.bp.blogspot.com/_1sICTF7VWbI/SfK8rKZ7nrI/AAAAAAAAAEc/ESZhnmrnpvY/s400/bind+xml+file+to+asp+net+dropdownlist.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Fig: Binding asp.net dropdownlist control to an xml file&lt;br /&gt;&lt;span xmlns=""&gt;&lt;p&gt;Today I am discussing the simple way to bind an asp.net dropdownlist control to an xml file. Besides binding the dropdownlist controls to an xml file, we will also sort the items in the ascending order.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Let us define the xml file first. This consists of Country object with properties ID and Name.&lt;br /&gt;&lt;pre class="xml" name="code"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;br /&gt;&amp;lt;Countries&amp;gt;&lt;br /&gt;  &amp;lt;Country&amp;gt;&lt;br /&gt;    &amp;lt;ID&amp;gt;1&amp;lt;/ID&amp;gt;&lt;br /&gt;    &amp;lt;Name&amp;gt;Nepal&amp;lt;/Name&amp;gt;&lt;br /&gt;  &amp;lt;/Country&amp;gt;&lt;br /&gt;  &amp;lt;Country&amp;gt;&lt;br /&gt;    &amp;lt;ID&amp;gt;2&amp;lt;/ID&amp;gt;&lt;br /&gt;    &amp;lt;Name&amp;gt;India&amp;lt;/Name&amp;gt;&lt;br /&gt;    &amp;lt;Country&amp;gt;&lt;br /&gt;      &amp;lt;ID&amp;gt;3&amp;lt;/ID&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;China&amp;lt;/Name&amp;gt;&lt;br /&gt;    &amp;lt;/Country&amp;gt;&lt;br /&gt;    &amp;lt;Country&amp;gt;&lt;br /&gt;      &amp;lt;ID&amp;gt;4&amp;lt;/ID&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;Bhutan&amp;lt;/Name&amp;gt;&lt;br /&gt;    &amp;lt;/Country&amp;gt;&lt;br /&gt;    &amp;lt;Country&amp;gt;&lt;br /&gt;      &amp;lt;ID&amp;gt;5&amp;lt;/ID&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;USA&amp;lt;/Name&amp;gt;&lt;br /&gt;    &amp;lt;/Country&amp;gt;&lt;br /&gt;  &amp;lt;/Country&amp;gt;&lt;br /&gt;&amp;lt;/Countries&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We place this xml file in the Resources folder of the root of our solution. Now let us define the markup for the asp.net dropdownlist control. &lt;pre class="xhtml" name="code"&gt;Select from the list of countries:&amp;lt;/b&amp;gt;&amp;amp;nbsp;&amp;lt;asp:DropDownList ID="ddlCountry" runat="server"&lt;br /&gt;            Width="160px"&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now in the load event of the page, we read the items from the xml file into a dataset. We will get the DataView for the default table in the dataset, and sort it. The table will consists of as many rows as there are country objects in the xml file. Each row has two columns: ID and Name. Now we can bind this dataview to the dropdownlist control, as in the code (in C#) below.&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;//page load event handler&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            //call to the function to populate dropdownlist from xml&lt;br /&gt;            PopulateDDLFromXMLFile();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //populates the dropdownlist from xml file&lt;br /&gt;    public void PopulateDDLFromXMLFile()&lt;br /&gt;    {&lt;br /&gt;        DataSet ds = new DataSet();&lt;br /&gt;        ds.ReadXml(MapPath("~/Resources/XMLFile.xml"));&lt;br /&gt;&lt;br /&gt;        //get the dataview of table "Country", which is default table name&lt;br /&gt;        DataView dv = ds.Tables["Country"].DefaultView;&lt;br /&gt;        //or we can use:&lt;br /&gt;        //DataView dv = ds.Tables[0].DefaultView;&lt;br /&gt;&lt;br /&gt;        //Now sort the DataView vy column name "Name"&lt;br /&gt;        dv.Sort = "Name";&lt;br /&gt;&lt;br /&gt;        //now define datatext field and datavalue field of dropdownlist&lt;br /&gt;        ddlCountry.DataTextField = "Name";&lt;br /&gt;        ddlCountry.DataValueField = "ID";&lt;br /&gt;&lt;br /&gt;        //now bind the dropdownlist to the dataview&lt;br /&gt;        ddlCountry.DataSource = dv;&lt;br /&gt;        ddlCountry.DataBind();&lt;br /&gt;    }&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;That simple! Happy Programming! &lt;/p&gt;&lt;/span&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f04%2fbind-aspnet-dropdownlist-to-xml-file.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f04%2fbind-aspnet-dropdownlist-to-xml-file.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/dotNETspidor-Bind-aspnet-dropdownlist-to-xml-file"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F04%2Fbind-aspnet-dropdownlist-to-xml-file.html&amp;textBackColor=2e0000" style="border:0px"/&gt;&lt;/a&gt;&amp;nbsp;&lt;a rev="vote-for" href="http://pimpthisblog.com/dotNETspidor-Bind-aspnet-dropdownlist-to-xml-file"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F04%2Fbind-aspnet-dropdownlist-to-xml-file.html" style="border:0px"/&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-738632935313488597?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/OZgTybT79Dw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/OZgTybT79Dw/bind-aspnet-dropdownlist-to-xml-file.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_1sICTF7VWbI/SfK8rKZ7nrI/AAAAAAAAAEc/ESZhnmrnpvY/s72-c/bind+xml+file+to+asp+net+dropdownlist.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/04/bind-aspnet-dropdownlist-to-xml-file.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-8241325296806617362</guid><pubDate>Sat, 14 Mar 2009 06:27:00 +0000</pubDate><atom:updated>2009-03-14T00:25:02.042-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">XMLHTTP</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Check UserName Availability Using XmlHttp in ASP.NET</title><description>&lt;span xmlns=""&gt;&lt;p&gt;Most email service providers like gmail, yahoo and hotmail provide live username availability checks. And this trend has been followed by other websites also. This is pretty simple in asp.net to check username availability before user submits the credentials. This saves time as well as increases user interactivity. In this article, I am going to show the simple username availability check mechanism using xmlhttp.&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/SbtT5ONpSyI/AAAAAAAAADI/JqdRcfbSGS0/s1600-h/Check+Username+Availability+Using+XMLHTTP.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5312932427946609442" style="WIDTH: 375px; CURSOR: hand; HEIGHT: 98px" alt="" src="http://3.bp.blogspot.com/_1sICTF7VWbI/SbtT5ONpSyI/AAAAAAAAADI/JqdRcfbSGS0/s400/Check+Username+Availability+Using+XMLHTTP.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;em&gt;Fig 1: UserName availability check using xmlhttp in asp.net web page&lt;/em&gt;&lt;/p&gt;&lt;p&gt;Let's define a simple user registration page. I am just showing the two fields: username and email for demonstration. Please note that this is not a complete code snippet. And I haven't implemented any other validation, for instance there could be one for email validation.&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;RegisterUser.aspx (add this markup after form element)&lt;/strong&gt;&lt;br /&gt;&lt;pre name="code" class="xhtml"&gt;&lt;br /&gt;&amp;lt;table cellpadding=&amp;quot;0&amp;quot; cellspacing=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;User Name:&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;asp:TextBox ID=&amp;quot;txtUserName&amp;quot; runat=&amp;quot;server&amp;quot; onkeydown=&amp;quot;CheckUserNameAvailability();&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br&gt;            &amp;lt;asp:Label ID=&amp;quot;lblMsg&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;Email:&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;&amp;lt;asp:TextBox ID=&amp;quot;txtEmail&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;        &amp;lt;td&amp;gt;&amp;lt;asp:Button ID=&amp;quot;btnRegister&amp;quot; runat=&amp;quot;server&amp;quot; Text=&amp;quot;Register&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br&gt;    &amp;lt;/tr&amp;gt;    &lt;br /&gt;&lt;br&gt;   &amp;lt;/table&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now we add the required xmlhttp snippet in the page. This code is to be added before head section of RegisterUser.aspx page.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre name="code" class="javascript"&gt;&lt;br /&gt;&amp;lt;script type = &amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;br&gt;        var xmlhttp;&lt;br /&gt;&lt;br&gt;        function CheckUserNameAvailability() &lt;br /&gt;&lt;br&gt;        {&lt;br /&gt;&lt;br&gt;            xmlhttp=null; &lt;br /&gt;&lt;br&gt;            var username=document.getElementById('&amp;lt;%=txtUserName.ClientID %&amp;gt;').value;&lt;br /&gt;&lt;br&gt;            if(username=&amp;quot;&amp;quot; || username.length&amp;lt;4)&lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                document.getElementById(&amp;quot;&amp;lt;%=lblMsg.ClientID%&amp;gt;&amp;quot;).innerHTML=&amp;quot;&amp;quot;;&lt;br /&gt;&lt;br&gt;                return false;&lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;            &lt;br /&gt;&lt;br&gt;            if (window.XMLHttpRequest) &lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                // code for all new browsers&lt;br /&gt;&lt;br&gt;                xmlhttp=new XMLHttpRequest(); &lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;            else if (window.ActiveXObject) &lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                // code for IE5 and IE6xmlhttp=&lt;br /&gt;&lt;br&gt;                new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;); &lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;            if (xmlhttp!=null) &lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                xmlhttp.onreadystatechange=state_Change;&lt;br /&gt;&lt;br&gt;                xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;CheckUserNameAvailabilityUsingJquery.aspx?UserName=&amp;quot;+username,true);&lt;br /&gt;&lt;br&gt;                xmlhttp.send(null); &lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;            else&lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;                alert(&amp;quot;Oops..Your browser does not support XMLHTTP.&amp;quot;); &lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;         }&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;        function state_Change() &lt;br /&gt;&lt;br&gt;        {&lt;br /&gt;&lt;br&gt;         if (xmlhttp.readyState==4) &lt;br /&gt;&lt;br&gt;         {&lt;br /&gt;&lt;br&gt;           // 4 = “loaded” &lt;br /&gt;&lt;br&gt;           if (xmlhttp.status==200) &lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;              //request was successful              &lt;br /&gt;&lt;br&gt;              //check if username is available and message&lt;br /&gt;&lt;br&gt;              var lblMesg = document.getElementById(&amp;quot;&amp;lt;%=lblMsg.ClientID%&amp;gt;&amp;quot;);&lt;br /&gt;&lt;br&gt;              if(xmlhttp.responseText==&amp;quot;True&amp;quot;)&lt;br /&gt;&lt;br&gt;              {&lt;br /&gt;&lt;br&gt;                lblMesg.style.color=&amp;quot;Green&amp;quot;;&lt;br /&gt;&lt;br&gt;                lblMesg.innerHTML=&amp;quot;Username available.&amp;quot;;&lt;br /&gt;&lt;br&gt;              }&lt;br /&gt;&lt;br&gt;              else&lt;br /&gt;&lt;br&gt;              {&lt;br /&gt;&lt;br&gt;                lblMesg.innerHTML=&amp;quot;Username already in use.&amp;quot;;&lt;br /&gt;&lt;br&gt;                lblMesg.style.color=&amp;quot;Red&amp;quot;;              &lt;br /&gt;&lt;br&gt;              }&lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;            else&lt;br /&gt;&lt;br&gt;            {&lt;br /&gt;&lt;br&gt;               alert(&amp;quot;Oops..username availability could not be checked.&amp;quot;);&lt;br /&gt;&lt;br&gt;            }&lt;br /&gt;&lt;br&gt;         }&lt;br /&gt;&lt;br&gt;        } &lt;br /&gt;&lt;br&gt;    &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Here goes the page that checks if the username already exists in the database and returns true (if the username does not exists) or false (if the username is already in use).&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;CheckUserAvailabilityUsingXMLHTTP.aspx&lt;/strong&gt;&lt;br /&gt;&lt;pre class="csharp" name="code"&gt;&lt;br /&gt; //page load event&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        CheckUserNameAvailability();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //checks if the username is available&lt;br /&gt;    //for demo, usename has been checked against the asp.net membership system&lt;br /&gt;    public void CheckUserNameAvailability()&lt;br /&gt;    {&lt;br /&gt;        if (Request.Params.Get("UserName") != null)&lt;br /&gt;        {&lt;br /&gt;            string username = Request.Params.Get("username");&lt;br /&gt;            string result = "False";&lt;br /&gt;            MembershipUser user = Membership.GetUser(username);&lt;br /&gt;            if (user != null)&lt;br /&gt;            {&lt;br /&gt;                result = "False";&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                result = "True";&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            Response.Clear();&lt;br /&gt;            Response.Write(result);&lt;br /&gt;            Response.End();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Please note the CheckUserNameAvailability.aspx page being called by the xmlhttp code in RegisterUser.aspx page. That's it. Happy Programming!&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fcheck-username-availability-using.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fcheck-username-availability-using.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a rev="vote-for" href="http://dotnetshoutout.com/Check-UserName-Availability-Using-XmlHttp-in-ASPNET"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdotnetspidor.blogspot.com%2F2009%2F03%2Fcheck-username-availability-using.html" style="border:0px"/&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-8241325296806617362?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/Qne5NvIJu2Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/Qne5NvIJu2Q/check-username-availability-using.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_1sICTF7VWbI/SbtT5ONpSyI/AAAAAAAAADI/JqdRcfbSGS0/s72-c/Check+Username+Availability+Using+XMLHTTP.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/03/check-username-availability-using.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-7632082202272762425</guid><pubDate>Wed, 11 Mar 2009 12:37:00 +0000</pubDate><atom:updated>2009-03-11T06:08:03.867-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Watermark Asp.NET Textbox Using JavaScript</title><description>&lt;span xmlns=""&gt;&lt;p&gt;Noticed the watermark implemented in custom google search TextBox, like one in the right side of this page (&lt;em&gt;under heading Search asp.net, C#, oracle, SQL Server related tips and solutions&lt;/em&gt;)? I am showing the simple and meaningful watermark implementation of a textbox in asp.net web page in this tipsticle (tips + article).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Truly saying, every time I come across a web page, I do naturally look for the searching textbox in the website. And I do usually find it in the left corner or the right upper corner of the website. Not all the search textboxes implement the watermark but they may initialize the text in the search textbox like &lt;em&gt;your search text here &lt;/em&gt;or just &lt;em&gt;search&lt;/em&gt;. And my enthusiasm always inspires me to click once and then just click out the textbox to see if watermark has been implemented. In my opinion, it is good to implement watermark for the sake of user-interactivity of a website. (And let me praise facebook homepage for this!)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Ok, lets start out with a search textbox in an asp.net web page.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;textarea readonly="readonly" style="WIDTH: 436px; HEIGHT: 49px" cols="47"&gt;&lt;asp:textbox id="txtSimpleSearch" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/textarea&gt;&lt;/blockquote&gt; &lt;/p&gt;&lt;p&gt;Now we add a javascript code snippet in the page.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;function WatermarkFocus(txtElem, strWatermark) {&lt;br /&gt;if (txtElem.value == strWatermark) txtElem.value = '';&lt;br /&gt;}&lt;br /&gt;function WatermarkBlur(txtElem, strWatermark) {&lt;br /&gt;if (txtElem.value == '') txtElem.value = strWatermark;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Now is the time to add onblur and onfocus properties to the asp.net TextBox, referencing the relevant javascript function.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;blockquote&gt;string strWatermarkSearch = "Search";&lt;br /&gt;txtSimpleSearch.Text = strWatermarkSearch;&lt;br /&gt;txtSimpleSearch.Attributes.Add("onfocus", "WatermarkFocus(this, '" + strWatermarkSearch + "');");&lt;br /&gt;txtSimpleSearch.Attributes.Add("onblur", "WatermarkBlur(this, '" + strWatermarkSearch + "');");&lt;br /&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We can see the perfect watermark implementation with our search textbox now! Happy Programming!&lt;br /&gt;&lt;br /&gt;Liked the post? You can share this post by submitting to dzone,digg,dotnetkicks etc. You can even leave your suggestions as the comment below.&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fwatermark-aspnet-textbox-using.html"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fwatermark-aspnet-textbox-using.html" border="0" /&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-7632082202272762425?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/lXZZWBXk2BY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/lXZZWBXk2BY/watermark-aspnet-textbox-using.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/03/watermark-aspnet-textbox-using.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-1955654467109120752</guid><pubDate>Fri, 06 Mar 2009 12:18:00 +0000</pubDate><atom:updated>2009-03-06T05:17:16.766-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Using JavaScript for Validation of Different Date Formats in Asp.NET Web Form</title><description>Most often asp.net web applications need to validate date in a form. It is not that easy to play with different format of dates at different places. Mostly the mm/dd/yyyy (alternatively, mm-dd-yyyy) format of date is used. But we may need to go dd/mm/yyyy (alternatively, dd-mm-yyyy) also, and yyyy/mm/dd (alternatively, yyyy-mm-dd) format is no exception too. This article will discuss how to validate date in all these formats using simple yet powerful javascript code snippet.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_1sICTF7VWbI/SbEXg_9X0eI/AAAAAAAAAC4/Mt6teTRh1tE/s1600-h/date+validation+in+asp+dot+net+using+javascript+2.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5310051291338625506" style="WIDTH: 318px; CURSOR: hand; HEIGHT: 207px" alt="" src="http://2.bp.blogspot.com/_1sICTF7VWbI/SbEXg_9X0eI/AAAAAAAAAC4/Mt6teTRh1tE/s400/date+validation+in+asp+dot+net+using+javascript+2.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;em&gt;Fig 1: Using ajax calendar extender to pick date into asp.net textbox in dd-mm-yyyy format&lt;br /&gt;&lt;/em&gt;&lt;div&gt;&lt;span xmlns=""&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/SbEXhKszyiI/AAAAAAAAADA/uNSgnGs5Gik/s1600-h/date+validation+in+asp+dot+net+using+javascript.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5310051294221945378" style="WIDTH: 341px; CURSOR: hand; HEIGHT: 151px" alt="" src="http://3.bp.blogspot.com/_1sICTF7VWbI/SbEXhKszyiI/AAAAAAAAADA/uNSgnGs5Gik/s400/date+validation+in+asp+dot+net+using+javascript.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Fig 2: Validation of the date in the textbox in dd-mm-yyyy format on form submit&lt;br /&gt;&lt;/em&gt;&lt;p&gt;Let's start with the addition of a TextBox and an ajax calendarextender in a page.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;textarea readonly="readonly" style="WIDTH: 552px; HEIGHT: 149px" rows="6" cols="59"&gt;Date of Purchase: &lt;asp:textbox id="txtPurchaseDate" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;&lt;cc1:calendarextender id="CalendarExtenderTo" format="dd-MM-yyyy" targetcontrolid="txtPurchaseDate" popupbuttonid="imgCalendarTo" runat="server"&gt;&lt;/cc1:CalendarExtender&gt;&lt;br /&gt;&lt;img id="imgCalendar" runat="server" src="SmallCalendar.gif" border="0" /&gt;&lt;br /&gt;&lt;asp:button id="btnSubmit" runat="server" text="Submit" onclientclick="ValidateForm();"&gt;&lt;/textarea&gt;&lt;/blockquote&gt;&lt;/p&gt;&lt;p&gt;Remember, we need ajax enabled page to use the calendar extender. Note that I have set the format in the calendarextender to dd-MM-yyyy. This will put the date in the targetcontrol (here, txtPurchaseDate) in dd-mm-yyyy format. On client click of the button btnSubmit, the javascript function ValidateForm() will validate the date in the textbox. If it is not in dd-mm-yyyy format, a message will be alerted as in the figures above. &lt;/p&gt;&lt;p&gt;Here are the functions Validateform() and validateInputDate().&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;function ValidateForm()&lt;br /&gt;{&lt;br /&gt;if(document.getElementById("txtPurchaseDate"))&lt;br /&gt;{&lt;br /&gt;if(validateInputDate(document.getElementById("txtPurchaseDate").value)==false)&lt;br /&gt;{&lt;br /&gt;alert("Please input purchase date in the format dd-mm-yyyy.");&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;} &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;//Validates date in the format dd-mm-yyyy (e.g. 19-10-2009)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(0[1-9][12][0-9]3[01])[\-.](0[1-9]1[012])[\-.](1920)[0-9]{2})$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;} &lt;/blockquote&gt;&lt;/p&gt;&lt;p&gt;Now we can change the validateInputDate() date validation function to validate other date formats. Listed below are the functions for validating different date formats.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;//Validates date in the format dd/mm/yyyy (e.g. 19/10/2009)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(0[1-9][12][0-9]3[01])[\/.](0[1-9]1[012])[\/.](1920)[0-9]{2})$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;//Validates date in the format dd-mm-yyyy or dd/mm/yyyy (e.g. 19-10-2009 or 19/10/2009)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(0[1-9][12][0-9]3[01])[\- \/.](0[1-9]1[012])[\- \/.](1920)[0-9]{2})$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;// Validates date in the format mm/dd/yyyy (e.g. 10/19/2009)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(0[1-9]1[012])[\/.](0[1-9][12][0-9]3[01])[\/.](1920)[0-9]{2})$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;// Validates date in the format yyyy-mm-dd or yyyy/mm/dd (e.g. 2009-10-19 or 2009/10/19)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(1920)[0-9]{2})[\- \/.](0[1-9]1[012])[\- \/.](0[1-9][12][0-9]3[01])$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;// Validates date in the format yyyy-mm-dd (e.g. 2009-10-19)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(1920)[0-9]{2})[\-.](0[1-9]1[012])[\-.](0[1-9][12][0-9]3[01])$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;// Validates date in the format yyyy/mm/dd (e.g. 2009/10/19)&lt;br /&gt;function validateInputDate(dateString){&lt;br /&gt;if (dateString.match(/^(?:(1920)[0-9]{2})[\/.](0[1-9]1[012])[\/.](0[1-9][12][0-9]3[01])$/))&lt;br /&gt;{&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt; Happy Programming!&lt;br /&gt;Liked the post? You can &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fusing-javascript-for-validation-of.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f03%2fusing-javascript-for-validation-of.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt; and &lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt; and &lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-1955654467109120752?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/u384f0NQSEg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/u384f0NQSEg/using-javascript-for-validation-of.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_1sICTF7VWbI/SbEXg_9X0eI/AAAAAAAAAC4/Mt6teTRh1tE/s72-c/date+validation+in+asp+dot+net+using+javascript+2.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/03/using-javascript-for-validation-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-1117507299109719370</guid><pubDate>Fri, 27 Feb 2009 13:01:00 +0000</pubDate><atom:updated>2009-02-27T06:13:42.244-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ajax</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Sys.InvalidOperationExceptio in UpdatePanel in asp.net ajax due to control structure</title><description>&lt;a href="http://3.bp.blogspot.com/_1sICTF7VWbI/SafnE0s25UI/AAAAAAAAACo/l23yW0b8wuo/s1600-h/update+panel+invalid+operation+error.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5307464755931702594" style="WIDTH: 320px; CURSOR: hand; HEIGHT: 83px" alt="" src="http://3.bp.blogspot.com/_1sICTF7VWbI/SafnE0s25UI/AAAAAAAAACo/l23yW0b8wuo/s320/update+panel+invalid+operation+error.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span xmlns=""&gt;&lt;br /&gt;&lt;p&gt;I recently got this error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_QuoteContent_UpdatePanelSiteAddress'. If it is being updated dynamically then it must be inside another UpdatePanel. And I fixed it too! I was using updatepanel in my page to update certain part from the page. I googled much. [I could sagoon too!]. They suggest that disabling event validation in the page would solve the problem. But nope. Some even told that removing UpdateMode="Conditional" for the upatepanel would solve the problem. And nope again!&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Why the Sys.InvalidOperationException with the above mentioned error occurred?&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This happened to occur because I had tried to access (and modify property of) a control outside the updatepanel's contenttemplate. Let me show this.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Here goes the design page: &lt;/p&gt;&lt;p&gt;1. I have one dropdownlist (ddlAddressType).&lt;br /&gt;2. Now I have a table with a row [row id trAddress]&lt;br /&gt;3. Within this row I have one updatepanel.&lt;br /&gt;4. In the updatepanel's ContenTemplate I have another table in which I have a gridview.&lt;br /&gt;5. I have added ddlAddressType as the asychronous postback control for the updatepanel.&lt;br /&gt;&lt;br /&gt;That's all. For quick preview, I want to hide the row trAddress which is outside the updatepanel itself. Got it?&lt;/p&gt;&lt;p&gt;&lt;asp:asyncpostbacktrigger eventname="SelectedIndexChanged" controlid="ddlAddressType"&gt;Now see here the code behind page:&lt;br /&gt;&lt;br /&gt;//on selected index changed&lt;br /&gt;protected void ddlAddressType_SelectedIndexChanged(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;if(ddlAddressType.SelectedValue.Contains("--"))&lt;br /&gt;{&lt;br /&gt;//Here I had tried to access the row (set visibility false)&lt;br /&gt;trAddress.Visible=false;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;//Here I had tried to access the row (set visibility true)&lt;br /&gt;trAddress.Visible=true;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Clearly, the row I am trying to make invisible is out of the scope of the updatepanel. So the error occurred.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Solution? In my case, I just set the table visible/invisible. Solved! Happy Programming&lt;/p&gt;&lt;p&gt;&lt;/span&gt;&lt;/asp:asyncpostbacktrigger&gt;&lt;/p&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f02%2fsysinvalidoperationexceptio-in.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdotnetspidor.blogspot.com%2f2009%2f02%2fsysinvalidoperationexceptio-in.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-1117507299109719370?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/yIqTR2gjHUA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/yIqTR2gjHUA/sysinvalidoperationexceptio-in.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_1sICTF7VWbI/SafnE0s25UI/AAAAAAAAACo/l23yW0b8wuo/s72-c/update+panel+invalid+operation+error.bmp" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/02/sysinvalidoperationexceptio-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6104185749662767834.post-6035885330312449907</guid><pubDate>Mon, 09 Feb 2009 06:53:00 +0000</pubDate><atom:updated>2009-02-10T05:29:16.694-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><title>Upload and Crop Images with jQuery, JCrop and ASP.NET</title><description>Need to crop image before uploading, in asp.net? Sounds like the alternative to thumbnail generation in asp.net web page, right? Here goes the handy code using jQuery, JCrop and ASP.NET. Good luck!&lt;br /&gt;&lt;br /&gt;I have coded a shopping cart in which there was the need of uploading images to the server, and keep the sizes as required by the content of the pages. In my case I had to hard-code the size of the thumbnail I generated. But wouldn't it be lovely if the site user could crop the image and fix the required size? So I have found one very useful way to  &lt;a href="http://www.mikesdotnetting.com/Article.aspx?ArticleID=95"&gt;Upload and Crop Images with jQuery, JCrop and ASP.NET&lt;/a&gt;. I hope this will be useful for all programmers.&lt;br /&gt;&lt;br /&gt;Happy Programming!&lt;div class="blogger-post-footer"&gt;For full article, tips and utilities, visit http://www.dotnetspidor.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6104185749662767834-6035885330312449907?l=dotnetspidor.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetspidor/~4/_xX_tZObgvU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/dotnetspidor/~3/_xX_tZObgvU/upload-and-crop-images-with-jquery.html</link><author>sangam.uprety@gmail.com (Sangam Uprety)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://dotnetspidor.blogspot.com/2009/02/upload-and-crop-images-with-jquery.html</feedburner:origLink></item></channel></rss>
