Monthly Archives: June 2008

4 posts

[JavaScript] Force user to check a box before clicking a button

This has been used a lot on those “sign up” forms. User has to select a check box indicating “I read and agree to the license agreement”, or something like that, before he/she can submit the form. Of course, with ASP.NET, you can let user submit the form and then check the state of the check box in the Button.Click event handler to prompt the user if the check bos is not checked. But my […]

[JavaScript]Clear the content of a textbox when it gets the focus

(I truly believe that a professional Web developer cannot live without JavaScript, and I have been busy playing with JavaScript lately and I will post some common but useful JavaScript code here.) Here is the JavaScript code: <script language=”javascript” type=”text/javascript”>        function clearBox(id)         {            var txt = document.getElementById(id);            if (txt.type != “text”)            {              alert(“Error: parameter type mismatch in clearBox function. TextBox type expected.”);            }            else           {                […]

Prevent browser from remembering inputted data in text box

Browser has a handy feature that remembers the information entered earlier in text boxes, and this feature can save you a lot of time when you fill up a form on-line. Sometimes, however, this feature may cause unwanted behaviors, even security concerns. For example, browser should not remember the credit card number that was entered. Another example is if you have a RegularExpressionValidator to validate a text box field, and if the text box has […]

Find the index of the GridView row where embeded CheckBox fired event

Say you have a GridView control with a CheckBox column embedded. When the check box is checked, it fires an event. How can you find out the index of the corresponding row that contains the check box? Here is the code snippet: VB.NET code: Protected Sub chkSelect_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim cb As CheckBox = CType(sender, CheckBox) Dim gr As GridViewRow = CType(cb.NamingContainer, GridViewRow) If (gr IsNot Nothing) Then Dim i […]