Posts

Showing posts from September, 2011

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

Different ways to use String Split Function in .NET

This method finds all the substrings in a string that are seperated by one or more characters, returning a string array. Split function has more number of overload method where you can specifiy the maximum number of elements in an array to return from the string. Here i have two important things about Split function of String class. Split function of the string class split the string in array of string. Split function to split string in array String.Split( char[]) string words = "apple,bat,cat,dog,,fox,Ghost." ; string [] split = words. Split ( new Char [] { ' ' , ',' }); O utput will be like this apple bat cat dog fox Ghost If you want to remove the Empty String Please make use of the Overloaded Methods. Overload method with option 1. String.Split(Char[], StringSplitOptions) string words = "apple,bat,cat,dog,,fox,Ghost."; string [] split = words. Split ( new Char [] { ' ' , ','