OnKeyPress event – event.keyCode and event.which (validating for numarics)

I am trying to validate textbox for numeric entry, while I added this code to accomplish in page_load event:

textbox.Attributes.Add(“onkeypress”, “return (window.event.keyCode == 45 || window.event.keyCode == 13 || window.event.keyCode == 8 || window.event.keyCode == 9 || window.event.keyCode == 189 || window.event.keyCode == 109 || (window.event.keyCode >= 48 && window.event.keyCode <= 58) )”);

It worked fine in IE7 and IE8, but it didnt work for FF though. A bit googling gave me conclusion that….

Read More

Strip out space from user input using JavaScript (ReplaceAll)

While I was trying to strip out all space from user input using JavaScript, First I tried with using simple replace function like var strDest = strSrc.replace(” “,”"). But, I see the result that it only replaces the first occurance of the space in source string. Intrestingly, I googled and found one solution to remove all the spaces from a string that is ” / /gi” parameter. Here is the JavaScript to strip out spaces from a string/user input..

Read More…

JavaScript to Maximize/Restore HTML image

Many web pages feature images that can be maximized and restored within the same page. There is a simple way to display an image on your web page with maximization and restoration capabilities. I have taken a test image and set the initial height and width. On Click of this image I am calling MaximizeRestore() Script which will simply set the height and width based on restored boolean Flag value. Check out complete JavaScript example below:

Read More…

Asynchronous Request to Server (JavaScript)

I have seen posts today asking for Asynchronous Request to Server which will Query the Database for certain information.
Here, I am giving one example, which will send an Asynchronous Request to server for Checking the availablity of the UserName entered by the user against database.

Below is my WebPage:

<div>
<asp:Label ID=”Label1″ runat=”server” Text=”UserName:”></asp:Label>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClientClick=”return CheckUserNameAvailablity1()” />
</div>

Here, I have attached a JavaScript Function CheckUserNameAvailablity1() with OnClientClick Property of the Button Control. Below is that JavaScript Function:

Read More…

(CheckBox in HeaderTemplate to) Select All CheckBoxes inside a GridView using JavaScript

In one of my previous blog post, I Described about Mutually Exclusive CheckBox inside GridView.

In this example, there is a “Select All” checkbox in header to select/deselect all the checkboxes inside GridView. MoreOver, if user select all the checkboxes manually one by one, then header checkbox should automatically be selected and vice versa.

Here is the Scenario; There is one TemplateColumn in GridView which is used to Select Row within GridView. So, There will be CheckBox inside ItemTemplate of that TemplateColumn. User would be able to select more than one CheckBox in that Column. And to Select All the CheckBoxes of that colum, There will be a “Select All” CheckBox in HeaderTemplate of that GridView. When user check “Select All” CheckBox in Header, all the checkboxes should be selected and vice versa.

Read More…

Mutually Exclusive CheckBox inside GridView

I was having a development requirement in which i have to implement CheckBoxes inside GridView.
Scenario is like, There is one TemplateColumn in GridView which is used to Select any Row within GridView. So, There will be CheckBox inside ItemTemplate of that TemplateColumn.

User would be able to select only one CheckBox (Mutually Exclusive) in that Column. If user select any other CheckBox in that Column, then Previously Selected CheckBox should be unchecked.
Here, I cant use RadioButton, as User should also be able to deselect the selected CheckBox, which is not possible with RadioButton.

Read More…

Vertically Scrollable Repeater with fixed Headers

I had to find some work-a-round for a scrollable repeater. The way I want it to be is to have fix headers with able to vertically scrollable. I found lots of example dealing for this solution with CSS and JavaScript. Luckily, I found one which works in both IE and FF. I managed to make one example here.. Read More…

TreeView: Automatically check all ChildNode CheckBoxes on Checking ParentNode CheckBox using JavaScript

Below, is the JavaScript code function snippet I used in one of my web application; to provide the functionality of “Select All Child” when ParentNode CheckBox is Checked; means to automatically Check all the ChildNode CheckBoxes, when you Check the ParentNode. I used the TreeView Control with ShowCheckBoxes Property.. Read More…

Follow

Get every new post delivered to your Inbox.