<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5240894832909925822</id><updated>2012-02-01T07:34:54.391+08:00</updated><category term='datagrid'/><category term='alert box'/><category term='redirecting'/><category term='VB.NET'/><category term='javascript'/><category term='button'/><category term='StringBuilder'/><title type='text'>Program Geek</title><subtitle type='html'>A collection of useful code snippets that are tested to be working. The codes are in javascript, VB.net, C# and in JAVA.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5240894832909925822.post-1608247527100553993</id><published>2008-12-12T23:31:00.002+08:00</published><updated>2008-12-12T23:35:38.824+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='StringBuilder'/><title type='text'>Proper use of StringBuilder</title><content type='html'>&lt;span style="font-family:arial;"&gt;'Declare the StringBuilder variable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Private body As New System.Text.StringBuilder("")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;'Append the string into the StringBuilder&lt;/span&gt;&lt;br /&gt;body.Append("Hello world!!&lt;br /&gt; ")&lt;br /&gt;body.Append("Hi!!&lt;br /&gt; ")&lt;br /&gt;'Retrieve the value of the StringBuilder&lt;br /&gt;body.toString&lt;br /&gt;&lt;br /&gt;OUTPUT:&lt;br /&gt;Hello world!!&lt;br /&gt;Hi!!&lt;br /&gt;&lt;br /&gt;Cool right? StringBuilder is much recommended than using the usual concatination symbols like + and &amp;amp;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5240894832909925822-1608247527100553993?l=program-geek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/1608247527100553993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5240894832909925822&amp;postID=1608247527100553993&amp;isPopup=true' title='41 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/1608247527100553993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/1608247527100553993'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/2008/12/proper-use-of-stringbuilder.html' title='Proper use of StringBuilder'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><thr:total>41</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5240894832909925822.post-5386119699398691418</id><published>2008-12-12T23:23:00.004+08:00</published><updated>2008-12-12T23:29:54.023+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='VB.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='redirecting'/><title type='text'>Method in .NET that uses javascript to display an alert box before redirecting to a new page</title><content type='html'>&lt;span style="font-family:arial;"&gt;Public Sub RedirectBox(ByVal page As System.Web.UI.Page, ByVal message As String, ByVal URL As String) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Dim Script As String = "&lt;script language="'javascript'"&gt; alert('" &amp;amp; message &amp;amp; "'); window.location = ('" &amp;amp; URL &amp;amp; "');&lt;/script&gt;&lt;br /&gt;" &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;page.ClientScript.RegisterStartupScript(Me.GetType, "RedirectBox", Script) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This method is very useful when programming in .NET and you want to display an alert message in your page before the page would redirect to another page. You could call this method for example to display the success message alert after a successful transaction before going back to the home page.&lt;/span&gt; Usually if we just use window.location after displaying alert, the tendency is that the alert box is not displayed and the page will immediately be redirected to the new URL. Using ClientScript.RegisterStartupScript, the alert will first display and the page will only redirect after clicking the OK button of the alert box.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5240894832909925822-5386119699398691418?l=program-geek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/5386119699398691418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5240894832909925822&amp;postID=5386119699398691418&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/5386119699398691418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/5386119699398691418'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/2008/12/public-sub-redirectboxbyval-page-as.html' title='Method in .NET that uses javascript to display an alert box before redirecting to a new page'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5240894832909925822.post-135172885930405510</id><published>2008-12-12T23:18:00.002+08:00</published><updated>2008-12-12T23:22:19.195+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='VB.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='alert box'/><title type='text'>Method to display an alert box in .NET using javascript</title><content type='html'>&lt;span style="font-family:arial;"&gt;Public Sub MessageBox(ByVal page As System.Web.UI.Page, ByVal message As String)               &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;  Dim Script As String = "&lt;script language="'javascript'"&gt; alert('" &amp;amp; message &amp;amp; "');&lt;/script&gt;"              &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;  page.ClientScript.RegisterStartupScript(Me.GetType, "MessageBox", Script)        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;This method is very useful when programming in .NET and you want to display an alert message in your page. You could call this method for example to display the success message alert after a successful transaction.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5240894832909925822-135172885930405510?l=program-geek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/135172885930405510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5240894832909925822&amp;postID=135172885930405510&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/135172885930405510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/135172885930405510'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/2008/12/method-to-display-alert-box-in-net.html' title='Method to display an alert box in .NET using javascript'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5240894832909925822.post-7387121625943394164</id><published>2008-12-06T22:42:00.003+08:00</published><updated>2008-12-12T23:04:01.561+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='button'/><title type='text'>Javascript to disable all controls upon Button click</title><content type='html'>&lt;span style="font-family:arial;"&gt;function DisableButton()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;document.forms[0].submit(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;window.setTimeout("disableButton()", 0); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;function disableButton() &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;for(i = 0; i &lt;= document.forms[0].elements.length; i++) &lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;elm = document.forms[0].elements[i]; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;elm.disabled=true; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;This is to prevent clicking the button more than once. This javascript code has already been tested to be working. All controls are disabled including the button itself after it is clicked. Remember to set the Submit behavior of the button to false so that it will not cause a postback when clicked.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5240894832909925822-7387121625943394164?l=program-geek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/7387121625943394164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5240894832909925822&amp;postID=7387121625943394164&amp;isPopup=true' title='68 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/7387121625943394164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/7387121625943394164'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/2008/12/javascript-to-disable-all-controls-upon.html' title='Javascript to disable all controls upon Button click'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><thr:total>68</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5240894832909925822.post-8824863008770434946</id><published>2008-12-06T22:32:00.003+08:00</published><updated>2008-12-12T23:01:53.703+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='datagrid'/><title type='text'>Javascript to check all datagrid checkboxes</title><content type='html'>&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;for(i = 0; i &lt;= document.forms[0].elements.length; i++)&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;elm = document.forms[0].elements[i] &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;if (elm.type == 'checkbox') &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;{ &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;elm.checked = checkVal; &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;} &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;} &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:Arial;"&gt;This code snippet has been tested to work on a datagrid with checkboxes named as aspCheckBoxID. The input parameter of checkVal is the value of the checkbox which is either true or false (true if you want to check all check box, and false if otherwise). &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5240894832909925822-8824863008770434946?l=program-geek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://program-geek.blogspot.com/feeds/8824863008770434946/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5240894832909925822&amp;postID=8824863008770434946&amp;isPopup=true' title='71 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/8824863008770434946'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5240894832909925822/posts/default/8824863008770434946'/><link rel='alternate' type='text/html' href='http://program-geek.blogspot.com/2008/12/javascript-to-check-all-datagrid.html' title='Javascript to check all datagrid checkboxes'/><author><name>James n_n</name><uri>http://www.blogger.com/profile/17621917969194897003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp3.blogger.com/_A_eL-2CHaq4/R2iOYKaJWuI/AAAAAAAAAHE/YkKpUu--Ay0/S220/images.jpg'/></author><thr:total>71</thr:total></entry></feed>
