30 November 2013

Valdating data in Dataset

  • Validating data is the process of confirming that the values being entered into data objects conform to the constraints within a dataset's schema, as well as the rules established for your application.
  • Validating data prior to sending updates to the underlying database is a good practice that reduces errors as well as the potential number of round trips between an application and the database.
  • You can confirm that data being written to a dataset is valid by building validation checks into the dataset itself.
  • The dataset can check the data no matter how the update is being performed — whether directly by controls in a form, within a component, or in some other way. Because the dataset is part of your application, it is a logical place to build application-specific validation (unlike building the same checks into the database backend).


29 November 2013

TableAdapter in Windows Application

TableAdapter Overview:

  1. TableAdapters provide communication between your application and a database.
  2. TableAdapters are also used to send updated data from your application back to the database.
  3. ADO.NET Data Adapters were used for communicating between an application and a       database.
  4. TableAdapters typically contain Fill and Update methods to fetch and update data in a database.
  5. TableAdapters are created with the Dataset Designer inside of strongly typed datasets. 




28 November 2013

Fill a dataset with data

  • The phrase "filling a dataset with data" refers to loading data into the individual DataTable objects that make up the dataset.
  • You fill the data tables by executing TableAdapter queries or by executing data adapter (for example, SqlDataAdapter) commands.


23 November 2013

Local Temp Table vs Global Temp Table

Local Temp Table vs Global Temp Table
S.NoParticularsLocal Temp TableGlobal Temp Table
1Available SQL Server session or connection (means single user) all SQL Server sessions or connections (means all the user).
2deleted These are automatically deleted when the session that created the tables has been closedThese can be created by any SQL Server connection user and these are automatically deleted when all the SQL Server connections have been closed.
3stared with signLocal temporary table name is stared with single hash ("#") sign.Global temporary table name is stared with double hash ("##") sign.

22 November 2013

Object Oriented vs Object based Language

Object Oriented vs Object based Language
S.NoParticularsOOL[Object Oriented Language]OBL[Object Based Language]
1SupportAll Features of OOPSAll feature of OOPS
2Built ObjectNoYes
3LanguagesC,C#,JavaVB,Javascripts

21 November 2013

ASP.Net Web API vs ASP.NET MVC

ASP.Net Web API vs ASP.NET MVC
S.NoParticularsASP.NET WebAPIASP.NET MVC
1Create Web Appcreate full blown HTTP services with easy and simple way that returns only data not view.returns both views and data
2support content-negotiationYesNo
3returning dataJSON,XML or any other based upon the Accept header in the request and you don't worry about that.JSON format using JsonResult.
4request are mapped actions based on HTTP verbs mapped to actions name.
5assemblySystem.Web.HttpSystem.Web.Mvc
6mixed MVC and Web API controllerWeb API since boths are different.implement the authorization then you have to create two filters one for MVC

20 November 2013

Split Web Page Extention using C#.Net

Split Web Page Extention using C#.Net
using System.Text.RegularExpressions;

string  splitWebPageExtension(string webPage, string extension,int idx)
        {

            Regex Splitter = new Regex(extension);
            String[] Parts = Splitter.Split(webPage);
            string st = Parts[idx];
            return st;
        }
     string webPage = "http://dotnettechrocks.blogspot.in/ ";
     string str = splitWebPageExtension(webPage, ".in", 0);
     MessageBox.Show(str);

Result :http://dotnettechrocks.blogspot

19 November 2013

Cluster vs NON-Cluster Index

Cluster vs NON-Cluster Index
S.NoParticularsClusterNON-Cluster
1data rows sort and store the data rows in the table or view based on their key values.have a structure separate from the data rows.
2ReadFaster to read than NON-Cluster
3StorePhysically, Store Index Order
4Faster Insert/UpdateQucikly Insert and Update Data than a Cluster Index.
5TableOnly One Per Tablecan be used many time per Table
6OrderData is in Physical OrderLogical Order

Function vs Methods


Function vs Methods
S.NoParticularsFuncitonMethods
1independent existence they can be defined outside of the classthey are always defined with in class
2languages Structure languages object oriented languages
3independentlycalled independently.called using instance or object.
4Functions are self describing unit of code.Methods are used to manipuate instance variable of a class

Web Services vs WCF


Web Services vs WCF
S.NoParticularsWeb servicesWCF
1Support SOAPYesYes
2SupportHTTPTCP, HTTP, HTTPS, Named Pipes, MSMQ.
3Return DataXMLXML
4Open SourceNo, can be consumed by any client that understands xml.No, can be consumed by any client that understands xml.
5Hostonly IISIIS or Windows Services

Create Directory Date Format in C#.Net

This is a Code for "Create Directory Date Format in C#.net"

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.IO;
 namespace GetOfficeVersion
 {
class ClsDirectory
 {
 public static void CreateDirectory(string DesignationPath)
 {
 if (!Directory.Exists(DesignationPath))
 {
 Directory.CreateDirectory(DesignationPath);
 }
 }
 public static string currentYear()
 {
 string Year = string.Empty;
DateTime dt = DateTime.Now;
string format = "yyyy";
 Year = dt.ToString(format);
 return Year;
 }
 public static string currentMonth()
{
 string Month = string.Empty;
 DateTime dt = DateTime.Now;
 string format = "MM";
 Month = dt.ToString(format);
 return Month;
 }
 public static string currentDate()
 {
string day = string.Empty;
 DateTime dt = DateTime.Now;
string format = "dd";
day = dt.ToString(format); return day;
}
}
}

18 November 2013

Model View Controller


Today, we see What is mean by MVC [Model View Control]
Model:
  1.  Model is basically a C# or VB.Net Class.
  2.  Model is accessible by Both Controller and View.
  3.  Model can be used to pass data from Controller to View.
  4.  View can use model to display data in Page.
View:
  1.   View is an ASPX Page without having a Code Behide file.
  2.   All Pate specific HTML generation and formatting can be done inside view.
  3.   One can use inline Code(Server tags) to develop dynamic pages.
Controller:
  1.   Controller is a basically a C# or VB.net class which inherits System.MVC.Controller.
  2.   controller is a Heart of Entire MVC Architecture.
  3.   Inside Controller's Class action methods can be implemented which are responsible to responding to browser or calling views.
  4.   Controller can access and use model class to pass data to views
  5.   Controller uses ViewData to pass any data to view.
MVC Artchitecture :
Comparison Artchitecture:


17 November 2013

Mandatory Label

Introduction:
     Today , we discussed about Mandatory Label in C#.Net.  This label intimate to user ,It is a Mandatory Field.
 
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.Drawing;
 namespace StaffingSolutionV1.UtilityLayer
 {
 class MandatoryLable :Label
 {
 public enum StatusManLabel
 {
 False,
True
 };
 private StatusManLabel m_Status;
 public string AddSymbol
{
 get;
set;
 }
 public StatusManLabel StatusLabel
 {
 get
 {
return m_Status;
 }
 set
 {
 if (value == StatusManLabel.True)
 {
 this.Text = AddSymbol + " " + this.Text; }
 else
 {
 AddSymbol = ""; this.Text = "";
 }
 m_Status = value;
 }
 }
}
}


16 November 2013

Number TextBox

Hi All,
   Today ,we see how to Create Number TextBox?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace LaksUserControl.UtilityLayer
 {
 class NumberTextBox : TextBox
 {
 CustomErrorProvider objCEP = new CustomErrorProvider();
 public enum CheckStatus { True, False, };
 public enum CheckStatusBlank { True, False, };
 enum ValidatieonType { BLANK, CHARACTER, BLANKWITHCHARACTER, };
 private CheckStatus m_CheckStatus;
 private CheckStatusBlank m_CheckStatusBlank;
 public CheckStatus CheckErrorProvider
 {
 get
 {
 return m_CheckStatus;
 }
 set
 {
 m_CheckStatus = value;
 }
 }
 public CheckStatusBlank CheckEmptyBox
 {
 get
 {
 return m_CheckStatusBlank;
 }
 set
 {
 m_CheckStatusBlank = value;
 }
 }
 private bool CheckBlankTextBox()
 {
 if (string.IsNullOrEmpty(this.Text))
 return true;
 else
 return false;
 }
 private bool ValidateNumber(string str)
 {
 Regex regexAlphaNum = new Regex(@"^[0-9]*$");
 return regexAlphaNum.IsMatch(str);
 }
 bool checkBlank;
 private bool CheckBlankTextBox(ValidatieonType Mode)
 {
 switch (Mode)
 {
 case ValidatieonType.BLANK:
 if (string.IsNullOrEmpty(this.Text))
 checkBlank = true;
 else
 checkBlank = false;
 break;
 case ValidatieonType.CHARACTER:
 if (!ValidateNumber(this.Text))
 checkBlank = true;
 else
 checkBlank = false;
 break;
 case ValidatieonType.BLANKWITHCHARACTER:
 if (string.IsNullOrEmpty(this.Text) | !ValidateNumber(this.Text))
 checkBlank = true;
 else checkBlank = false;
 break;
 }
 return checkBlank;
 }
 bool chkdisplayEP;
 protected internal bool DisplayErrorProvider(string CheckErrorProvider, string CheckEmptyBox, string Message)
 {
 if (CheckErrorProvider == "true" && CheckEmptyBox == "true")
 {
 if (CheckBlankTextBox(ValidatieonType.BLANKWITHCHARACTER))
 {
 objCEP.SetError(this, Message);
 chkdisplayEP = true;
 }
 else
 {
 objCEP.SetError(this, "");
 chkdisplayEP = false;
 }
 }
 else if ((CheckErrorProvider == "true" && CheckEmptyBox == "false"))
 {
 if (CheckBlankTextBox(ValidatieonType.CHARACTER))
 {
 objCEP.SetError(this, Message);
 chkdisplayEP = true;
 }
 else
 {
 objCEP.SetError(this, "");
 chkdisplayEP = false;
 }
 }
 return chkdisplayEP;
 }
 }
 }


 using System;
using System.Collections.Generic;
using System.Linq;
 using System.Text;
using System.Windows.Forms;
 namespace LaksUserControl.UtilityLayer
{
 class CustomErrorProvider : ErrorProvider
 {
 public List GetControls()
 {
 return this.GetControls(this.ContainerControl);
 }
 public List GetControls(Control ParentControl)
 { 
 List ret = new List(); 
 if (!string.IsNullOrEmpty(this.GetError(ParentControl)))
 ret.Add(ParentControl); 
 foreach (Control c in ParentControl.Controls)
 {
 List child = GetControls(c);
 if (child.Count > 0)
 ret.AddRange(child);
 }
 return ret;
 }
 }
 }
</div>


15 November 2013

Get DataBase Exists or not using DataContext

   This is code for Get DataBase Exists or not using DataContext

DataContext context = new DataContext(GetConnectionString("YourSErverName"));
bool dbExists = context.DatabaseExists();
 if (dbExists)
{
MessageBox.Show("Database Exists");
 }
 else
 {
 MessageBox.Show("Database doesn't Exist");
}
 static string GetConnectionString(string serverName)
 {
 System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
 builder["Data Source"] = serverName; builder["integrated Security"] = true;
 builder["Initial Catalog"] = "Sample2"; Console.WriteLine(builder.ConnectionString); Console.ReadKey(true); return builder.ConnectionString;
 }

Base Directory vs Current Directory

 Base Directory vs Current Directory
S.NoBase DirectoryCurrent Directory
1returns the path where the executable file exists.returns the path that the current working directory from the executable file.

14 November 2013

Managed Resource vs Unmanaged Resource

Managed Resource vs Unmanaged Resource
S.NoManaged ResourceUnmanaged Resource
1Managed resources are those that are pure .NET code and managed by the runtime and are under its direct control.Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc.

LINQ -- I

1.      Difference between First vs FirstOrDefault in LINQ
  •    First: Gives first record from the collection, if collection doesn't have any object then throws error.
  • FirstOrDefault: FirstOrDefault extension method is used to retrieve the first element from the collection, if not then gives null.
2.      Difference between Last vs LastOrDefault in LINQ?
  • Last:Last extension method gives last element from the collection. If there is no element in the collection, it throws error.
  • LastOrDefault:LastOrDefault extension method gives the last element form the collection, if not gives null.
3.     When will we use ThenBy in LINQ?
               ThenBy is used with OrderBy or OrderByDescending. It is used to apply sorting on already sorted collection using OrderBy or OrderByDescending.
4.     Where to Use SequenceEqual ?
                   SequenceEqual extension method is used to determine if both collections sequence are equal.
5.     what is mean by SkipWhile?
            SkipWhile extension method is used to skip the elements that satisfies the given filter criteria till it doens't get any element that doesn't satisfy.
6.     How to use Take Method in LINQ?
          Take extension method is used to take specified number of elements from the collection.
7.     What is mean by Lambda expression?
  • A lambda expression is an function that contain many expressions and statements.
  • Lambda expression used to create delegates or expression tree types.
  • All lambda expressions use the lambda operator =>, which is read as "goes to".
  • The left side of the lambda operator specifies the input parameters.
  • The right side holds the expression or statement block.

8.     What is ORM?
         ORM stands for Object-Relational Mapping. Sometimes it is called O/RM, or O/R mapping. It is a programming technique that contains a set of classes that map relational database entities to objects in a specific programming language.
9.     What is ODBC?
        ODBC (Open Database Connectivity) was developed to unify all of the communication protocols for various RDBMSs. ODBC was designed to be independent of programming languages, database systems, and Operating Systems. So with ODBC, an application could communicate with different RDBMSs by using the same code, simply by replacing the underlying ODBC drivers.
10. What is LINQ To SQL?
  •  LINQ to SQL is a component of the .NET Framework version 3.5 that provides a run-time infrastructure for managing relational data as objects.
  • LINQ to SQL fully supports transactions, views, Stored Procedures, and user-defined functions. It also provides an easy way to integrate data validation and business logic rules into your data model, and supports single table inheritance in the object model.
  • LINQ to SQL, ADO.NET SqlClient adapters are used to communicate with real SQL Server databases.
11. Difference between LINQ To SQL and LINQ To Object?
·        LINQ to SQL needs a Data Context object. The Data Context object is the bridge between LINQ and the database. LINQ to Objects doesn’t need any intermediate LINQ provider or API.
·        LINQ to SQL returns data of type IQueryable<T> while LINQ to Objects returns data of type IEnumerable<T>.
·        LINQ to SQL is translated to SQL by way of Expression Trees, which allow them to be evaluated as a single unit and translated to the appropriate and optimal SQL statements. LINQ to Objects does not need to be translated.
·        LINQ to SQL is translated to SQL calls and executed on the specified database while LINQ to Objects is executed in the local machine memory.




12. What is mean by Entity Framework?
·        ADO.NET Entity Framework (EF) was first released with Visual Studio 2008 and .NET Framework 3.5 Service Pack 1. So far, many people view EF as just another ORM product from Microsoft, though by design it is supposed to be much more powerful than just an ORM tool.
·        The conceptual data model schema is expressed in the Conceptual Schema Definition Language (CSDL), the actual storage model is expressed in the Storage Schema Definition Language (SSDL), and the mapping in between is expressed in the Mapping Schema Language (MSL).


13. Difference between LINQ To SQL and LINQ To Entities?
·        LINQ to Entities applications work against a conceptual data model (EDM). All mappings between the languages and the databases go through the new EntityClient mapping provider. The application no longer connects directly to a database or sees any database-specific construct; the entire application operates in terms of the higher-level EDM model.



14. What are all the Operator Type  in LINQ To Object?

·        Aggregation Aggregate, Average, Count, LongCount, Max, Min, Sum
·        Conversion Cast, OfType, ToArray, ToDictionary, ToList, ToLookup, ToSequence
·        Element DefaultIfEmpty, ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault
·        Equality EqualAll
·        Generation Empty, Range, Repeat
·        Grouping GroupBy
·        Joining GroupJoin, Join
·        Ordering OrderBy, ThenBy, OrderByDescending, ThenByDescending, Reverse
·        Partitioning Skip, SkipWhile, Take, TakeWhile
·        Quantifiers All, Any, Contains
·        Restriction Where
·        Selection Select, SelectMany
·        Set Concat, Distinct, Except, Intersect, Union



HTML Tag with Support Browsers













S.NoTagDescriptionIEFFOperaChormeSafariDifferenceSupportRemarksSolution
1<!...>Comment TagYYYYYN******************
2Instructs to the WebBrowser (HTML 5)YYYYYYHTML 5.0************
3Hyperlink(One Page to another Page)YYYYYN******************
4Abbraviation or acronymYYYYYN******************
5Abbraviation******************************YHTML 4.01************
6
Contact informationYYYYYN******************
7appletEmbedded applet******************************YHTML 4.01************
8Inside an Image-MapYYYYYYHTML 5.0attributes are difference(nohref --Not supported in HTML 5.0).New attributes in HTML 5.0 :type,media rel,hreflang)******
9


Independent,self contained contentYYYYYYHTML 5.0New in HTML 5.0******
10


some content aside from the content it is placed itYYYYYYHTML 5.0New in HTML 5.0******
11audio strams,sound and musicYYYYYYHTML 5.0New in HTML 5.0******
12makes text BoldYYYYYN******************
13default url/target for all element with a Url(Hyperlink,Image)YYYYYN******Inside the******
14used to define default font color,size and familyYYYYYYHTML 4.01************
15bidirectional overrideYYYYYN******************
16text is biggerYYYYYYHTML 4.01************
17
takes from a another SourceYYYYYN******************
18Document's BodyYYYYYYHTML 5.0specific attributes are removed, while in HTML 4.01 they were deprecated.******
19
single line a breakYYYYYN******************
20Push ButtonYYYYYYHTML 5.0Attributes:autofocus,form, formaction, formenctype, formmethod, formnovalidate, and formtarget.******
21Display GraphicsYYYYYYHTML 5.0************
22
defines a table captionYYYYYYHTML 5.0The "align" attribute which was deprecated in HTML 4.01, is not supported in HTML5. Use CSS instead.Use CSS
23
center align textYYYYYYHTML 5.0************
24defines a citationYYYYYN******************
25defines a Computer CodeYYYYYN******************
26
One or More Columns in a tableYYYYYYHTML 5.0Most of the attributes from 4.01 are not supported in HTML5.(Attributes are :align,char,charoff,valign,width[Not supported in HTML 5.0])******
27
Group Columns in a TableYYYYYYHTML 5.0Most of the attributes from 4.01 are not supported in HTML5.(Attributes are :align,char,charoff,valign,width[Not supported in HTML 5.0])******
28command button like Radio buttton,Check Box or a ButtonYNNNYYHTML 5.0New in HTML 5.0******
29Defines list of options NNYNNYHTML 5.0New in HTML 5.0******
30


describe the Items in a Definition listYYYYYN******************
31Text has been deleted from a DocumentsYYYYYN******************
32spcified additional details or controls which can be hidden or shown on demandNNNYNYHTML 5.0New in HTML 5.0******
33Defines a definition termsYYYYYN******************
34


define a directoryYYYYYYHTML 5.0Not supportedUse CSS
35
Define a Division or section in an HTML DocumentYYYYYYHTML 5.0The "align" attribute is deprecated in HTML 4.01, and not supported in HTML5. Use CSS to align the div's content.******
36
Define a Definition listYYYYYN******************
37


define a start of a term in the Difintion listYYYYYN******************
38deifne a Emphasized TextYYYYYN******************
39defines Embedded content ,such as a plug inYYYYYYHTML 5.0New in HTML 5.0******
40group together elements in a formYYYYYYHTML 5.0HTML5 has the attributes disabled, form, and name, which was not supported in HTML 4.01.******
41


contain a caption for a


Tag
YYYYYYHTML 5.0New in HTML 5.0******
42


Self contained flow contentYYYYYYHTML 5.0New in HTML 5.0******
43Specify font family,size and color of textYYYYYYHTML 5.0Not supportedUse CSS
44


footer of the section or DocumentYYYYYYHTML 5.0New in HTML 5.0******
45
create an HTML Form for an user inputYYYYYYHTML 5.0New Attributes are in the HTML 5.0 (autocomplete and novalidate)******
46One Particulare window within a FramesetYYYYYYHTML 5.0Not supported******
47org Mulitiple WindowYYYYYYHTML 5.0Not supported******
48

to

define headersYYYYYYHTML 5.0Not supportedUse CSS
49contains all head elements.Inside theYYYYYYHTML 5.0The profile attribute is not supported in HTML5******
50


specifies an introduction ,or a group of navigation elementsofr the DocumentsYYYYYYHTML 5.0New in HTML 5.0******
51


heading of a section or a DocumentsYYYYYYHTML 5.0New in HTML 5.0******
52
Horizonal line in an HTML PageYYYYYYHTML 5.0
tag displays a horizontal rule, and defines a change in the content.All attributes in HTML 4.01 (align, noshade, size, and width) are deprecated in HTML 4.01, and not supported in HTML5. You should use CSS to style the hr element.
Use CSS
53tells the browser that this is an HTML DocumentYYYYYYHTML 5.0New Attribute is in the HTML 5.0(Manifest)******
54renders test in ItalicsYYYYYN******************
55










































































































































































































































































































































































































































































































































































































































































Character Textbox in C#.Net

Introduction:
        Today, we discussed about Character TextBox in C#.Net.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace LaksUserControl.UtilityLayer
{
 class NCharacterTextBox :TextBox
 {
 CustomErrorProvider objCEP = new CustomErrorProvider();
public enum CheckStatus { True, False, };
 public enum CheckStatusBlank { True, False, };
 public enum ValidatieonType { BLANK, CHARACTER, BLANKWITHCHARACTER, };
 private CheckStatus m_CheckStatus;
 private CheckStatusBlank m_CheckStatusBlank;
 public CheckStatus CheckErrorProvider
 { get { return m_CheckStatus; } set { m_CheckStatus =value; }
 }
public CheckStatusBlank CheckEmptyBox
 { get { return m_CheckStatusBlank; } set { m_CheckStatusBlank = value; }
 }
 private bool ValidateAlphabet(string str)
 {
 Regex regexAlphaNum = new Regex(@"^[a-zA-Z]*$"); return regexAlphaNum.IsMatch(str); }
bool checkBlank;
 private bool CheckBlankTextBox(ValidatieonType Mode)
 {
 switch (Mode)
 {
 case ValidatieonType.BLANK:
 if (string.IsNullOrEmpty(this.Text)) checkBlank= true; else checkBlank=false;
 break;
case ValidatieonType.CHARACTER:
 if (!ValidateAlphabet(this.Text)) checkBlank=true; else checkBlank=false;
break;
case ValidatieonType.BLANKWITHCHARACTER:
 if (string.IsNullOrEmpty(this.Text) | !ValidateAlphabet(this.Text)) checkBlank=true; else checkBlank=false; break;
}
 return checkBlank;
 }
 bool chkdisplayEP;
 protected internal bool DisplayErrorProvider(string CheckErrorProvider, string CheckEmptyBox, string Message)
 {
 if (CheckErrorProvider == "true" && CheckEmptyBox == "true")
 {
 if (CheckBlankTextBox(ValidatieonType.BLANKWITHCHARACTER))
 {
 objCEP.SetError(this, Message);
 chkdisplayEP=true;
 }
 else
 {
 objCEP.SetError(this, ""); chkdisplayEP=false;
 }
 }
 else if ((CheckErrorProvider == "true" && CheckEmptyBox == "false"))
 {
 if (CheckBlankTextBox(ValidatieonType.CHARACTER))
 {
 objCEP.SetError(this, Message); chkdisplayEP = true;
 }
 else
 {
 objCEP.SetError(this, ""); chkdisplayEP = false;
 }
 }
 return chkdisplayEP;
 }
 }
 }

Error Provider Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 namespace LaksUserControl.UtilityLayer
 {
 class CustomErrorProvider : ErrorProvider
 {
 public List GetControls()
 {
 return this.GetControls(this.ContainerControl);
 }
 public List GetControls(Control ParentControl)
 {
 List ret = new List();
 if (!string.IsNullOrEmpty(this.GetError(ParentControl)))
 ret.Add(ParentControl);
 foreach (Control c in ParentControl.Controls) 
 {
 List child = GetControls(c); if (child.Count > 0) ret.AddRange(child);
 }
 return ret; 
 }
 }
 }

Validation TextBox with Error Provider in C#.Net

HI All,
    Today, We discussed about TextBox Validation with Error Provider in C#.Net


using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.Text.RegularExpressions;
 namespace LaksUserControl.UtilityLayer
{
 class NCharacterTextBox :TextBox
 {
 CustomErrorProvider objCEP = new CustomErrorProvider();
 public enum CheckStatus { True, False, };
 public enum CheckStatusBlank { True, False, };
 public enum ValidatieonType { BLANK, CHARACTER, BLANKWITHCHARACTER, };
 private CheckStatus m_CheckStatus;
 private CheckStatusBlank m_CheckStatusBlank;

public CheckStatus CheckErrorProvider
 {
 get { return m_CheckStatus; } set { m_CheckStatus =value; }
 }
 public CheckStatusBlank CheckEmptyBox { get { return m_CheckStatusBlank; } set { m_CheckStatusBlank = value; }
 }
 private bool ValidateAlphabet(string str)
 {
 Regex regexAlphaNum = new Regex(@"^[a-zA-Z]*$"); return regexAlphaNum.IsMatch(str);
}
 bool checkBlank;
 private bool CheckBlankTextBox(ValidatieonType Mode)
 {
 switch (Mode)
 {
 case ValidatieonType.BLANK:
 if (string.IsNullOrEmpty(this.Text))
 checkBlank= true;
 else checkBlank=false;
 break;
 case ValidatieonType.CHARACTER:
 if (!ValidateAlphabet(this.Text))
 checkBlank=true;
 else
 checkBlank=false;
 break;
 case ValidatieonType.BLANKWITHCHARACTER:
 if (string.IsNullOrEmpty(this.Text) | !ValidateAlphabet(this.Text))
 checkBlank=true;
 else
 checkBlank=false;
 break;
 }
 return checkBlank;
 }
 bool chkdisplayEP;
 protected internal bool DisplayErrorProvider(string CheckErrorProvider, string CheckEmptyBox, string Message)
 {
 if (CheckErrorProvider == "true" && CheckEmptyBox == "true")
 {
 if (CheckBlankTextBox(ValidatieonType.BLANKWITHCHARACTER))
 {
 objCEP.SetError(this, Message);
 chkdisplayEP=true;
 }
 else
 {
 objCEP.SetError(this, "");
 chkdisplayEP=false;
 }
 }
 else if ((CheckErrorProvider == "true" && CheckEmptyBox == "false"))
 {
 if (CheckBlankTextBox(ValidatieonType.CHARACTER))
 {
 objCEP.SetError(this, Message);
 chkdisplayEP = true;
 }
 else
 {
 objCEP.SetError(this, "");
 chkdisplayEP = false;
 }
 }
 return chkdisplayEP;
 }
 }
 }

Error Provider
using System;
using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 namespace LaksUserControl.UtilityLayer
 {
 class CustomErrorProvider : ErrorProvider
 {
 public List GetControls()
 {
 return this.GetControls(this.ContainerControl); 
 }
 public List GetControls(Control ParentControl)
 { 
 List ret = new List();
 if (!string.IsNullOrEmpty(this.GetError(ParentControl))) ret.Add(ParentControl);
 foreach (Control c in ParentControl.Controls) 
 {
 List child = GetControls(c); if (child.Count > 0) ret.AddRange(child); } return ret;
 }
 }
 }