Posts

Showing posts from 2011

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 Main(string[] arguments)         {             foreach (String arg in Enviro

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 ();         }           int fact( int num)         {               int temp = 1;               for ( int i = num; i > 1; i--)             {                 temp = temp * i;              }               return temp;         }     }

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.

Frame the SQL Query using String Function Format()

The main idea behind this FAQ is to frame our SQL Query using String Format Function. I think this is one of the best way to frame the SQL Query that i found. *** This code introduces SQL injection attacks and should not be used. *** The string.Format method is a static method that receives a string that specifies where the following arguments should be inserted, and these are called substitutions. In source code we need to use to frame the SQL Query public bool SaveData( string firstName, string lastName)     {           String connectionString = ConfigurationManager. ConnectionStrings [ "TESTDB" ]. ConnectionString ;          bool result = false ;          using ( SqlConnection connection = new SqlConnection (connectionString))         {            SqlCommand cmd = new SqlCommand ();             cmd. Connection = connection;              cmd. CommandText = String . Format ( "insert into Test _DB.dbo.Person

A New Approach To .NET Key Value pairs in Collections

A new approach has been evolved in the Collections ,i.e The LookUp is one the Class in the Collection which represents a collection of keys each mapped to one or more values. We are very familiar with the Dictonary Collection which maps only one value per key mapping.But when we come across to map the keys with more values.Then we have this LookUp Where TKey    ----> The types of the keys in the LookUp TValue ---->    The type of the elements of each IEnumerable value in the LookUp . I have worked out on this concept to understand the LookUp class. Before going in deeply , let's create a Custom Class like this Employee. cs using System.Collections.Generic; /// /// Summary description for Employee /// public class Employee {      public int ID { get; set; }      public string Email { get; set; }      public int Age { get; set; }      public string Name { get; set; }      public bool MartialStatus { get; set; }      public Employe

How to apply watermark to the textbox and dropdownlist?

Create a watermark effect on your TextBox and display instructions to users, without taking up screen space.This warkmark style can applied by using the CSS and append this to your control using jquery. Hi this is basic where we you use to get to apply watermark to the Textbox or DropDown.I have implemented this by using the jquery. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WaterMark.aspx.cs" Inherits="WaterMark" %> < html xmlns ="http://www.w3.org/1999/xhtml"> < head runat ="server">      < title > Water Mark using jquery title >      < style type ="text/css">         .watermarkOn         {             color: #CCCCCC;             font-style: italic;         }       style >      < script type ="text/javascript" src ="http://code.jquery.com/jquery-1.4.1.js"> script >      < script ty

ASP.NET Controls Calling using jQuery

As we all know the jQuery is one of the most powerful ja vascript libra ry whi ch simplifies the HTML DOM eleme nts traversing ,event handling e.t .c.  Please go through this where you can call the ASp.NET controls using jQuery.    One thing, while creating object of any ASP.NET control, always use ClientID. As when Master pages are used then the ID of the ASP.NET controls is changed at run time. 1. Getting the Label Text      E.g: $('#<%=Label1.ClientID%>').text(); 2. Set the lab el Text E.g:$('#<%=Label1.ClientID%>').text("New Value"); 3. Set TextBox Text E.g:$('#<%=TextBox1.ClientID%>').val("New Value"); 4. Get Dropdown value: E. g: $('#<%=DropDownList1.ClientID%>').val(); 5. Set Dropdown value: E. g:$('#<%=DropDownList1.ClientID%>').val("New Value"); 6. Get text of selected item in dropdown: E.g:$('#<%=DropDownList1.ClientID%> option:selected&

ASP.NET - Data insertion using jquery AJAX

The main idea behind this article is to insert data using jQuery AJAX to avoid postback. AJAX offers users a seamless way to work with your interface, no waiting for whole pages to load. jQuery has a set of tools to make it super simple to implement. Most everyone knows what iAJAX is. But for the beginners i would like to provide some information regarding the AJAX. W hat is AJAX? AJAX is a short hand for asynchronous JavaScript and XML.  Which plainly means that instead of waiting for the whole page to load, you can load only what you need to.  So if you only need to update one small text part of your site, you don’t have to worry about loading everything else on that page.  A vast majority of sites use this technology now.  Probably one of the most popular uses is an auto complete feature for the search box at Google and Yahoo. If you see another term XHR, which is shorthand for XML HTTP request, it’s the same thing. Don’t be afraid of this jargon; AJAX is n