Posts

Restrict the Textbox to enter only Numbers Using Javascript

Normally we get this type of requirement to accept only numbers in a text box.Suppose we have a Credit Card Number entry where we want to validate the key-press is number or not.Here i have simplified the way to enter only numbers in the text-box. Here i have written some logic to enter only numbers in textbox using javascript. < script type = " text/javascript " > function isNumberKey ( evt ) { var charCode = ( evt . which ) ? evt . which : event . keyCode if ( charCode > 31 && ( charCode < 48 || charCode > 57 ) ) return false ; return true ; } < script > Now we can call this fu nction in the events like keypress,keydown and keyup to validate the value is number or not. Happy Coding :-)

Recursive Function to find the Control in the Parent Controls

Image
Some times we need to find the child control in the parent control's using the loop structure.I have faced this issue many times and got a unique solution to find the child control in the Parent Controls. Recursive Function to find the Controls

Cascading Dropdown in Asp.Net using jQuery

Image
Cascading dropdown is the most common requirement we use to get in the real time world. So mainly beginners feel difficulty in doing this task. I have seen many of my friends and colleagues face this problem. Hope this could help those folks. Normally some folks posting the Question "How to get the Second Dropdown fill based on the first dropdown selection?” The processing of filling the second dropdown based on the first dropdown selection is called "Cascading Dropdown or Filtered Dropdown". Actually the data source I have used is XML file which contains the Country and State. In the source code this XML file is also given please check once you download the source code. Cascading dropdown can be done in many ways out of which I have chosen this using jQuery. I have taken the common example of Country and States. I have taken two Composite types as "Country" and "State" which contains properties as ID, Name. I have given the structure also. ...

Calling the UserControl Event from the WebForm

Image
The main theme behind this article is give the clear idea about the event and the event handling in .NET. An event is a message sent by an object to signal the occurrence of an action. This action caused by the user interaction such as button click,mouse click e.t.c.The Object that send the event is called the event sender. The object that receives the event and respond according to that is called the event receiver. Actually in communication between the sender and the receiver ,the sender does not know which method or object will receive the event it raises. The mediator between these two is called “Delegate”. A delegate is a class that can hold a reference to a method .The Delegate class has a signature and it can hold the reference only to the methods that match to its signature. Normally I found the requirement to save the main page data in the user control button click which led me to write this article. Here I have taken a user control which c...

Passing Command Line Arguments Using VS 2010

Image
Command line arguments are helpful to provide those parameters without exposing them to everybody. Even with modern UI, we often need a way to start our programs with specific parameters. Command line arguments are helpful to provide those parameters without exposing them to everybody. When developing with .NET and C# you can get the command line arguments from your Main(string[] Args) function. Args is in fact an array containing all the strings separated by spaces entered in the command line. Suppose we have the application which accepts some command line parameters to do some operations.We know how to pass the parameters from command prompt.I have that also some sample here. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2010 {      class CommandLineArgument     {           static void Ma...

Factorial Program using C#

This is the basic program for the beginners. Here's how to f ind the factorial of 3. Mathematically it follows like th is 3*2*1=6 class FactorialProgra m     {           static void Main ( string [] args)         {             var fp = new FactorialProgra m();            Console . Write ( "\n Enter the number:\t" );             var result = fp.fact( int . Parse ( Console . ReadLine ()));            Console . WriteLine (result);            Console . ReadLine ();         }           in...

How to Clear the Textbox Text using C#?

This is one of the common requirement we get in our projects.Text box has a wonderful method called " Clear ".This method is used to clear the text in the Text box.I have given a simple example to explain this .I have implemenetd a common method to clear the Text of few Controls .One of that is Textbox. void ClearInputs(ControlCollection ctrls) { foreach (Control ctrl in ctrls) { if (ctrl is TextBox) ((TextBox)ctrl).Text = string .Empty; ClearInputs(ctrl.Controls); } }   You can call this method where ever you want to clear the Text from the Textbox. For more information please click this link TextBox       Hope this would help the beginners. Cheers.