<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digicorp &#187; asp.net</title>
	<atom:link href="http://dev.digi-corp.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.digi-corp.com</link>
	<description>&#62;&#62; Developer Blog</description>
	<lastBuildDate>Wed, 22 Jun 2011 14:13:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CLR Stored Procedure in Linq based n-tier architecture</title>
		<link>http://dev.digi-corp.com/2009/09/clr-stored-procedure-in-linq-based-n-tier-architecture/</link>
		<comments>http://dev.digi-corp.com/2009/09/clr-stored-procedure-in-linq-based-n-tier-architecture/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 06:38:11 +0000</pubDate>
		<dc:creator>virat.kothari</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[clr stored procedure]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[n-tier]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[virat]]></category>
		<category><![CDATA[virat kothari]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=1472</guid>
		<description><![CDATA[Download Source Code &#8211; 143.73 KB Download SQL Script &#8211; 2.29 KB Table of contents Introduction Define Tiers for the Application Role of Tiers Implementing CLR Stored Procedure in LINQ based n-tier Architecture Step by Step Steps to Create Architecture Using the code Conclusion Points of Interest History Introduction This article is a sequence of [...]]]></description>
			<content:encoded><![CDATA[<div>
<ul class="Download">
<li><a title="Click to download demo" href="http://dev.digi-corp.com/wp-content/uploads/2009/09/ClrInNTierArchitecture.zip" target="_self">Download Source Code &#8211; 143.73 KB</a></li>
<li><a title="Click to download script" href="http://dev.digi-corp.com/wp-content/uploads/2009/09/Script.zip" target="_self">Download SQL Script &#8211; 2.29 KB</a></li>
</ul>
<h2><span style="color: #333399">Table of contents</span></h2>
<ol>
<li>Introduction</li>
<li>Define Tiers for the Application</li>
<li>Role of Tiers</li>
<li>Implementing CLR Stored Procedure in LINQ based n-tier Architecture Step by Step</li>
<li>Steps to Create Architecture</li>
<li>Using the code</li>
<li>Conclusion</li>
<li>Points of Interest</li>
<li>History</li>
</ol>
<h2><span style="color: #333399">Introduction</span></h2>
<p>This article is a sequence of my previous article about “<a title="Creating CLR Stored Procedures Step by Step" href="http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx" target="_blank">CLR Stored Procedure &amp; creating it step by step</a>”. In my previous article I have explained CLR Stored Procedure, benefits &amp; drawbacks of it and also how to implement it. CLR Stored Procedure is very powerful and gives better results while executing complex logic, intense string operation or string manipulations, cryptography, accessing system resources and file management, etc. Development of any project in n-tier architecture is different taste and having its own benefits and drawbacks. Microsoft has launched LINQ i.e. Language Integrated Query with .net framework 3.0. LINQ can be implemented in variety of ways for e.g. LINQ with SQL, LINQ with objects, LINQ with dataset and LINQ with xml etc. I have implemented simple n-tier architecture few years back in my company. It is suitable for both web as well as desktop applications. It is a centralized n-tier architecture i.e. all the objects are resides at the same place in the target system. I don’t claim this as best but I have implemented this architecture as I want at least following benefits out of it.</p>
<ol>
<li>It must be secure, easy to implement and easy to deploy</li>
<li>It must be tiered based and at least 3 tiered so that if we change code of any tier, we need to deploy dll of that tier only.</li>
<li>Single architecture for web and desktop application with standard application performance</li>
<li>Parallel development should be possible i.e. one developer can work with database, another can work with business logic and one more can work with user interface and so on</li>
<li>No in-line SQL queries</li>
<li>It must not be complex so that new developer can easily set on development without undergoing long training and existing developers can be easily migrated to and from any of the projects as basic development architecture of all the projects will remain same</li>
</ol>
<h2><span style="color: #333399">Define Tiers for the Application</span></h2>
<p align="baseline">Now, let me explain various tiers of the architecture. Any good architecture will consist at least 3 important tiers viz. 1) User Interface or Presentation Layer 2) Business Logic Layer 3) Data Layer. The architecture which I am going to explain have 5 tiers. Any architecture having more than 3 tiers is called n-tier architecture. Following image will clarify it.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/Architecture.png"><img class="alignnone size-large wp-image-1484" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/Architecture-865x1024.png" alt="Architecture" width="533" height="631" /></a></p>
<p>Following is the image showing architecture in our application. It contains following 4 tiers (see image) and 1 database so total 5 tiers.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/SolutionExplorer.png"><img class="alignnone size-full wp-image-1496" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/SolutionExplorer.png" alt="SolutionExplorer" width="533" height="948" /></a></p>
<h2><span style="color: #333399">Role of Tiers</span></h2>
<p>Let me explain each of above tier in brief.</p>
<ol>
<li><strong>Tier – 1: Presentation Layer:</strong> This layer will be responsible for various activities between Users and application. All the user interface related logic will reside at this layer. That means web forms or Win forms will reside here. This layer does not have direct access to the database or Data Access Layer. So, all the data goes in or comes out to Presentation Layer will be through the Business Logic Layer only. <em>A reference of Business Logic Layer will be added to this layer.</em> A separate project will be there for this layer.</li>
<li><strong>Tier – 2: Business Logic Layer:</strong> Business Logic Layer will perform all the Business Logics of the application. Business logic consists of two things viz., Core business logic and Data access logic. Data access logic is been segregated to different layer to provide more security and data encapsulation to the application. There will be a separate class for each table of the database to provide better management, in this layer. This class will have various methods. Business logic will be applied to data coming from or going to Presentation Layer and Data Access Layer. <em>A reference of Data Access Layer will be added to this layer</em>. A separate project will be there for this layer.</li>
<li><strong>Tier – 3: Data Access Layer:</strong> This layer is a part of Business logic but is separated from core business logic. All the data related operations between application and database will be performed over here. This layer will be created using “LINQ”. One LINQ to SQL class will be created over here and all the needed database tables or Stored Procedures will be dragged and dropped over here. This layer will have minimum manual coding. A separate project will be there for this layer.</li>
<li><strong>Tier – 4: CLR Stored Procedure Layer:</strong> This layer will be responsible for defining various CLR Stored Procedures. There will be a separate class for each table of the database to provide better management, in this layer. This layer is not directly associated with Presentation Layer, Business Logic Layer or Data Access Layer. CLR Stored Procedure will be deployed to SQL server. A separate project will be there for this layer. To know, what is CLR Stored Procedure and how to create it refer my article “<a title="Creating CLR Stored Procedures Step by Step" href="http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx" target="_blank">CLR Stored Procedure and Creating It Step by Step</a>”.</li>
<li><strong>Tier – 5: Database: </strong>This is core data and other objects to maintain and access it. For e.g. SQL server database. Core data is data in various tables and objects to maintain &amp; access such data are various tables, Stored Procedures, CLR Stored Procedures, Views and Functions etc.</li>
</ol>
<p>Physically there are 5 layers but logically they are 4 layers as assembly of CLR Stored Procedure will be the part of Database at the time of deployment.</p>
<p>To add reference of one project to another project is very simple. Just right click on the project &gt;&gt; Click on Add Reference. A dialog box will be displayed. Select &#8220;Projects&#8221; tab and select appropriate project in the list of projects. Click &#8220;OK&#8221; button. We can not add circular reference within project for e.g. In our case, Presentation Layer refers to Bussiness Layer and Business Layer refers to Data Access Layer. Now, we can not add reference of Presentation Layer to Data Access Layer as it will create circular reference.</p>
<h2><span style="color: #333399">Implementing CLR Stored Procedure in LINQ based n-tier Architecture Step by Step</span></h2>
<p>Let us implement CLR Stored Procedure in LINQ based n-tier architecture. I have listed all SQL statements used for creating database, creating table, inserting dummy records in the table, etc. in the script attached with this article.</p>
<p><strong>Application Development Specification</strong></p>
<ul>
<li>IDE: Visual Studio 2008</li>
<li>Framework: 3.5 with SP 1</li>
<li>Language: C# 3.0</li>
<li>Database: Microsoft SQL Server 2005 Express edition</li>
<li>Operating system: Windows XP with SP 2</li>
</ul>
<h2><span style="color: #333399">Steps to Create Architecture</span></h2>
<p>1. Open Microsoft Visual Studio 2008 &gt;&gt; Create New Project. A dialog box will be opened. Select, Visual C# &gt;&gt; Windows on left side “Project Types” panel. Select, “Windows Forms Application” on right side “Templates” panel. Give proper name to project, solution and select location to save this solution. This project will be our presentation layer. Following image will make it clear.</p>
<p align="baseline"><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/1.PNG"><img class="alignnone size-full wp-image-1481" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/1.PNG" alt="1" width="534" height="387" /></a></p>
<p align="baseline">A default form with the name “Form1” will be created with the project. Rename it to “Demo”. Design it as shown in following image. There is a Label control for heading, one Data Grid View control, a Group Box control to hold various buttons viz., Get Data, Insert Random Record, Delete Selected Record, Clear Grid and Exit. Following image will make it clear.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/BlankDemoForm.PNG"><img class="alignnone size-full wp-image-1485" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/BlankDemoForm.PNG" alt="BlankDemoForm" width="536" height="357" /></a></p>
<p align="baseline">
<p align="baseline">2.    Right click on Solution, click on Add &gt;&gt; New Project. A dialog box will be opened. Select, Database Projects &gt;&gt; Microsoft SQL Server &gt;&gt; SQL CLR on left side “Project Types” panel. Select, “SQL Server Project” on right side “Templates” panel. Give proper name to project and select location to save this solution. This project will be our CLR Stored Procedure Layer. Follow the steps I have explained in my article “<a title="CLR Stored Procedure and Creating It Step by Step" href="http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx" target="_blank">CLR Stored Procedure and Creating It Step by Step</a>” to add CLR Stored Procedure in this project. Following image will make it clear.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/SQLServerProject.PNG"><img class="alignnone size-full wp-image-1497" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/SQLServerProject.PNG" alt="SQLServerProject" width="533" height="367" /></a></p>
<p align="baseline">
<p align="baseline">Right click on the project &gt;&gt; Select Add &gt;&gt; Add New Items. A dialog box will be displayed as shown in following image. Select Visual C# Items from left &#8220;Categories&#8221; panel. Select Stored Procedure from right side &#8220;Templates&#8221; panel. Give proper name to it.</p>
<p align="baseline"><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/AddClrSP.PNG"><img class="alignnone size-full wp-image-1483" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/AddClrSP.PNG" alt="AddClrSP" width="532" height="344" /></a></p>
<p align="baseline">
<p align="baseline">3.    Right click on Solution, click on Add &gt;&gt; New Project. A dialog box will be opened. Select, Visual C# &gt;&gt; Windows on left side “Project Types” panel. Select, “Class Library” on right side “Templates” panel. Give proper name to project and select location to save this solution. This project will be our Business Logic Layer. I have added two classes to this project i.e. 1) “ConvertToDataTable” and 2) “CustomerSalesInformation”. “ConvertToDataTable” class has various methods to convert array of objects to DataTable or DataSet. CustomerSalesInformation class consist various methods to Insert a record, Delete a record and Get records from database. Following image will make it clear.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/BusinessLayer.PNG"><img class="alignnone size-full wp-image-1488" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/BusinessLayer.PNG" alt="BusinessLayer" width="534" height="368" /></a></p>
<p align="baseline">
<p>4.    Once again, Right click on Solution, click on Add &gt;&gt; New Project. A dialog box will be opened. Select, Visual C# &gt;&gt; Windows on left side “Project Types” panel. Select, “Class Library” on right side “Templates” panel (same as step 3). Give proper name to project and select location to save this solution. This project will be our Data Access Layer.</p>
<p align="baseline">
<p align="baseline">5.    Right click on “DataAccessLayer” project, Select Add &gt;&gt; New Item option from the menu. A dialog box shown in following image will be displayed. Select on Visual C# Items in left side “Categories” panel and “Linq to SQL Classes” in right panel “Templates”.</p>
<p align="baseline"><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/LinqToSqlDal.PNG"><img class="alignnone size-full wp-image-1493" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/LinqToSqlDal.PNG" alt="LinqToSqlDal" width="537" height="348" /></a></p>
<p align="baseline">
<p align="baseline">6.    Open Server explorer and click on “Connect to database” button given at<br />
top-middle of the server explorer window. It will start a new wizard to<br />
connect to the database. Now drag and drop Stored Procedures<br />
“CustomerSalesInformationDelete” and<br />
“CustomerSalesInformationInsertRandomRecord”. Do <strong>NOT</strong> drag and drop<br />
“CustomerSalesInformationGet” right now as we need to change it. I have<br />
added “AccessData” class to add various useful methods and variables to<br />
be used on Business Logic Layer. Write now I have declared one private<br />
object of “LinqToSqlDataContext” and exposed it using property “Call”.<br />
Following images will make it clear. Change the connection string I<br />
have statically wrote while declaring object of “LinqToSqlDataContext”.</p>
<p align="baseline"><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/Dbml.PNG"><img class="alignnone size-large wp-image-1491" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/Dbml-1024x621.PNG" alt="Dbml" width="532" height="330" /></a></p>
<p>7.    I have suggested not to drag and drop “CustomerSalesInformationGet” because it is a Stored Procedure which does not contain any SELECT query. That is why if you drag and drop it in .dbml file, the return type of the method of the said Stored Procedure will be “int” instead of ISingleResult and so it will not produce any result which we are expecting from this Stored Procedure. You can see this in .cs file of dbml. The work around I am going to explain is not the standard way but it works fine. Let me know if you find any better option. Following are the steps of the work around.</p>
<blockquote><p><strong>Step 1:</strong> Go to query analyzer and drop the Stored Procedure “CustomerSalesInformationGet” which was automatically created at the time of deploying CLR stored procedure, using following SQL statement.</p></blockquote>
<blockquote>
<pre>DROP PROCEDURE [dbo].[CustomerSalesInformationGet]</pre>
</blockquote>
<blockquote><p><strong>Step 2:</strong> Create new stored procedure with the same name as stored procedure created at the time of deploying CLR stored procedure, using following SQL statements.</p>
<pre>CREATE PROCEDURE [dbo].[CustomerSalesInformationGet]
AS
BEGIN
	SELECT * from CustomerSalesInformation
END</pre>
</blockquote>
<blockquote><p><strong>Step 3:</strong> Now come to the Visual Studio and refresh the “Stored Procedure” element of the tree view. You can simply right click on the element and click on “Refresh” option of the menu or cliking on refresh icon at the top-left of Server Explorer. Now drag and drop “CustomerSalesInformationGet” stored procedure to the .dbml file. This will create a method for the said stored procedure with the return type “ISingleResult”. You can verify this in .cs file of dbml. So this will return the result per our expectation.</p>
<p><strong>Step 4:</strong> Once again go to query analyzer and drop the manually created stored procedure “CustomerSalesInformationGet” using following SQL statement.</p>
<pre>DROP PROCEDURE [dbo].[CustomerSalesInformationGet]</pre>
</blockquote>
<blockquote><p><strong>Step 5:</strong> Now come to the Visual Studio and Right click on “ClrStoredProcedureLayer” project and click on “Deploy” option of the menu. This will deploy CLR stored procedure to the database once again. Now do NOT drag and drop this stored procedure to the dbml file otherwise we have to repeat this whole work around.</p></blockquote>
<p>8.    You have to change connection at two places while using my sample source code.</p>
<blockquote><p>1.    In the “AccessData.cs” file where we have declared an object of “LinqToSqlDataContext”. Following will clarify this.</p></blockquote>
<blockquote>
<pre>private static LinqToSqlDALDataContext objLinqToSqlDALDataContext = _
new LinqToSqlDALDataContext("Data Source=OM\\SQLEXPRESS;Initial Catalog=DbForClrDemo;User ID=sa;Password=airborne");</pre>
</blockquote>
<blockquote><p>2.    In the “CLRStoredProcedureLayer” project. Right click on the said project in solution explorer and click on “Properties”. A screen like following image will be displayed. Select “Database” tab and change the connection string at “Connection String” option where a textbox and Browse button is given.</p>
<p><a title="Changing connection string in CLR Stored Procedure project" href="CLR_SP_Linq_n-tier/ChangeConnectionInClrProject.png" target="_blank"></a><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/ChangeConnectionInClrProject.png"><img class="alignnone size-full wp-image-1489" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/ChangeConnectionInClrProject.png" alt="ChangeConnectionInClrProject" width="492" height="304" /></a></p></blockquote>
<p align="baseline">
<p align="baseline">9.    Save the whole solution. Right click on the solution in solution explorer and click on “Build” option. Now, you can run the application by hitting F5. A dialog box will be opened as shown in following image. Click on “Get Data” button, it will retrieves records from the database and loads in to the grid. “Insert Random Record” will insert random record in the table and once again retrieves records from the database and loads in to the grid. “Delete Selected Record” deletes the selected record. “Clear Grid” button clears the records from the grid. “Exit” button will close and exit the application. Following is the demo of the same.</p>
<p><a href="http://dev.digi-corp.com/wp-content/uploads/2009/09/DemoFormWithData.PNG"><img class="alignnone size-full wp-image-1492" src="http://dev.digi-corp.com/wp-content/uploads/2009/09/DemoFormWithData.PNG" alt="DemoFormWithData" width="531" height="354" /></a></p>
<h2><span style="color: #333399">Using the Code</span></h2>
<ol>
<li>Download the zip files for source code and sql script  and extract them</li>
<li> Create Database and tables using &#8220;Script to create Database and Table.sql&#8221;. Also, insert records in the table using same file</li>
<li>Change connections at 2 places in application as explained in Step 8</li>
<li>Run the demo.</li>
<li>When you hit &#8220;Get Data&#8221; button for the first time, it will take little time to fetch data from database. Now, hit &#8220;Clear Grid&#8221; button and hit &#8220;Get Data&#8221; button once again, you will realize the speed. Also, try to hit &#8220;Insert Random Record&#8221; button continuously for many time. It inserts record to the database and fills the grid at every hit, but still see the speed of it.</li>
<li>This will give little slow performance in web application than windows application.</li>
</ol>
<h2><span style="color: #333399">Conclusion</span></h2>
<p>Clr Stored Procedures can be efficiently implemented in n-tier architecture</p>
<h2><span style="color: #333399">Suggestion</span></h2>
<p>Refer my another article &#8220;<a title="Creating CLR Stored Procedures Step by Step" href="http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx" target="_blank">CLR Stored Procedure and Creating It Step by Step</a>&#8221;</p>
<h2><span style="color: #333399">Points of Interest</span></h2>
<ol>
<li>Exploring IMultipleResult in LINQ.</li>
</ol>
<h2><span style="color: #333399">History</span></h2>
<ol>
<li>08<sup>th</sup> September, 2009: Initial release</li>
</ol>
<p><!-- End Article --></div>
<div style="overflow: hidden; width: 1px; height: 1px;">using System;<br />
using System.Windows.Forms;<br />
using BusinessLayer;</p>
<p>namespace ClrInNTierPresentationLayer<br />
{<br />
/// &lt;summary&gt;<br />
/// Represents demo form for the application<br />
/// &lt;/summary&gt;<br />
public partial class frmDemo : Form<br />
{<br />
#region Constructor</p>
<p>/// &lt;summary&gt;<br />
/// Constructor of the application<br />
/// &lt;/summary&gt;<br />
public frmDemo()<br />
{<br />
InitializeComponent();<br />
}</p>
<p>#endregion</p>
<p>#region Event Handler</p>
<p>#region Buttons</p>
<p>/// &lt;summary&gt;<br />
/// Handles Click event of the button<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;sender&#8221;&gt;&lt;/param&gt;<br />
/// &lt;param name=&#8221;e&#8221;&gt;&lt;/param&gt;<br />
private void btnGetData_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
FillDataGridView();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>/// &lt;summary&gt;<br />
/// Handles Click event of the button<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;sender&#8221;&gt;&lt;/param&gt;<br />
/// &lt;param name=&#8221;e&#8221;&gt;&lt;/param&gt;<br />
private void btnInsertRandomRecord_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
CustomerSalesInformation.CustomerSalesInformationInsertRandomRecord();<br />
FillDataGridView();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>/// &lt;summary&gt;<br />
/// Deletes selected record from the database<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;sender&#8221;&gt;&lt;/param&gt;<br />
/// &lt;param name=&#8221;e&#8221;&gt;&lt;/param&gt;<br />
private void btnDeleteSelectedRecord_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
if (dgvData.Rows.Count &gt; 0)<br />
{<br />
if (MessageBox.Show(&#8220;Are you sure to delete selected record?&#8221;, &#8220;Confirmation&#8221;, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)<br />
{<br />
CustomerSalesInformation.CustomerSalesInformationDelete(Convert.ToDouble(dgvData.CurrentRow.Cells["ID"].Value.ToString()));<br />
FillDataGridView();<br />
}<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>/// &lt;summary&gt;<br />
/// Handles Click event of the button<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;sender&#8221;&gt;&lt;/param&gt;<br />
/// &lt;param name=&#8221;e&#8221;&gt;&lt;/param&gt;<br />
private void btnClearGrid_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
dgvData.DataSource = null;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>/// &lt;summary&gt;<br />
/// Handles Click event of the button<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;sender&#8221;&gt;&lt;/param&gt;<br />
/// &lt;param name=&#8221;e&#8221;&gt;&lt;/param&gt;<br />
private void btnExit_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
Application.Exit();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>#endregion</p>
<p>#endregion</p>
<p>#region Private Methods</p>
<p>/// &lt;summary&gt;<br />
/// Fills the data in the DataGridView<br />
/// &lt;/summary&gt;<br />
private void FillDataGridView()<br />
{<br />
try<br />
{<br />
//Filling the grid with data<br />
dgvData.DataSource = CustomerSalesInformation.CustomerSalesInformationGet();</p>
<p>//Formating the columns of the grid<br />
dgvData.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;<br />
dgvData.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;<br />
dgvData.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;</p>
<p>dgvData.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, &#8220;Error&#8221;, MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}</p>
<p>#endregion<br />
}<br />
}</p></div>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/09/clr-stored-procedure-in-linq-based-n-tier-architecture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to bind jQuery function to CSS</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-bind-jquery-function-to-css/</link>
		<comments>http://dev.digi-corp.com/2009/06/how-to-bind-jquery-function-to-css/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 06:52:00 +0000</pubDate>
		<dc:creator>nikunj.padaliya</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Css Stylesheet]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery validation]]></category>
		<category><![CDATA[numeric textbox]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=683</guid>
		<description><![CDATA[In this article I have explained how to use CSS and jQuery function together. I will give one example in which I have used CSS for textbox and one jQuery function for validation like numeric value and maximum 3 character allowed. Example: Create a CSS for textbox in which height, weight, border, font, text-align etc. [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I have explained how to use CSS and jQuery function together.</p>
<p>I will give one example in which I have used CSS for textbox and one jQuery function for validation like numeric value and maximum 3 character allowed.</p>
<p><strong>Example:</strong></p>
<p>Create a CSS for textbox in which height, weight, border, font, text-align etc. is defined.</p>
<p><!--[if gte mso 9]&gt;  Normal 0   false false false        MicrosoftInternetExplorer4  &lt;![endif]--><!--[if gte mso 9]&gt;   &lt;![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --></p>
<p><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 9pt; font-family: Verdana; color: #a31515;">style</span><span style="font-size: 9pt; font-family: Verdana;"> <span style="color: red;">type</span> <span style="color: blue;">=&#8221;text/css&#8221;</span> <span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: #a31515;">.txt1</span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span> </span><span style="color: red;">text-align</span> :<span style="color: blue;">center</span> ;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span> </span><span style="color: red;">width</span> :<span style="color: blue;">60px</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span> </span><span style="color: red;">height</span> :<span style="color: blue;">22px</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span> </span><span style="color: red;">border</span>: <span style="color: blue;">1px</span> <span style="color: blue;">solid</span> <span style="color: blue;">#000000</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span> </span><span style="color: red;">font-family</span>: <span style="color: blue;">verdana</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: red;">font-size</span>: <span style="color: blue;">10pt</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: red;">font-weight</span>:<span style="color: blue;">bold</span> ; </span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span></span><span style="font-size: 9pt; font-family: Verdana; color: blue;">&lt;/</span><span style="font-size: 9pt; font-family: Verdana; color: #a31515;">style</span><span style="font-size: 9pt; font-family: Verdana; color: blue;">&gt;</span></p>
<p>Write jQuery function for validation for numeric value and maximum length of the textbox. Bind this function to textbox stylesheet on keypress event.</p>
<p><!--[if gte mso 9]&gt;  Normal 0   false false false        MicrosoftInternetExplorer4  &lt;![endif]--><!--[if gte mso 9]&gt;   &lt;![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --></p>
<p><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 9pt; font-family: Verdana; color: #a31515;">script</span><span style="font-size: 9pt; font-family: Verdana;"> <span style="color: red;">type</span> <span style="color: blue;">=&#8221;text/javascript&#8221;</span> <span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>$(document).ready(<span style="color: blue;">function</span> (){</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>$(<span style="color: #a31515;">&#8220;.txt1&#8243;</span>).bind(<span style="color: #a31515;">&#8220;keypress&#8221;</span>,<span style="color: blue;">function</span>(){</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: blue;">var</span> str = (event.srcElement).value;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: blue;">var</span> len1 = str.length;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (len1 &gt; 2)</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>event.returnValue=<span style="color: blue;">false</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span style="color: blue;"> if</span>(!(event.keyCode==45||event.keyCode==46||event.keyCode==48||   event.keyCode==49||event.keyCode==50||event.keyCode==51||   event.keyCode==52||event.keyCode==53||event.keyCode==54||   event.keyCode==55||event.keyCode==56||event.keyCode==57))</span></p>
<p class="MsoNormal" style="text-align: left; "><span style="font-size: 9pt; font-family: Verdana;"><span> </span> {<br />
event.returnValue=<span style="color: blue;">false</span>;<br />
}</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;">});</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span>});</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 9pt; font-family: Verdana; color: blue;">&lt;/</span><span style="font-size: 9pt; font-family: Verdana; color: #a31515;">script</span><span style="font-size: 9pt; font-family: Verdana; color: blue;">&gt;</span></p>
<p>Now apply the CSS to the textbox.</p>
<p><!--[if gte mso 9]&gt;  Normal 0   false false false        MicrosoftInternetExplorer4  &lt;![endif]--><!--[if gte mso 9]&gt;   &lt;![endif]--><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">asp</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">:</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">TextBox</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;Textbox1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">CssClass</span><span style="color: blue;">=&#8221;txt1&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">&gt;</span></span></p>
<p>By applying this CSS on textbox user can only enter numeric value upto 3 characters and also we have a good looking textbox.</p>
<p>I hope this simple solution will help you somewhere in your project.</p>
<p><span id="more-683"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/06/how-to-bind-jquery-function-to-css/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building Composite Control Using ASP.NET 3.5</title>
		<link>http://dev.digi-corp.com/2009/06/building-composite-control-using-asp-net-3-5/</link>
		<comments>http://dev.digi-corp.com/2009/06/building-composite-control-using-asp-net-3-5/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 13:47:21 +0000</pubDate>
		<dc:creator>vivek.navadia</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Composite Control]]></category>
		<category><![CDATA[NumericTextBox]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=651</guid>
		<description><![CDATA[As we have discussed how to build the rendered control earlier, it is one step ahead in building custom controls. Earlier we have built the custom control starting from scratch. If you don’t want to start from scratch when building a custom control, you can build a composite control. When you create a composite control, [...]]]></description>
			<content:encoded><![CDATA[<p>As we have discussed how to build the rendered control earlier, it is one step ahead in building custom controls. Earlier we have built the custom control starting from scratch. If you don’t want to start from scratch when building a custom control, you can build a composite control. When you create a composite control, you create a new control from existing controls.</p>
<p>Every ASP.NET control has a Controls property that represents all of its child controls. If you add child controls to a control, then the child controls are automatically rendered when the parent control is rendered.</p>
<p>Lets start from the beginning, Creating <strong>NumericTextBox</strong> (Only accepts Numeric values, else it give error message through validator.) is shown below. Create new VB Web Application Project and let’s name it <strong>NHSWebApplication</strong>. After Creating Web Application project just right click on <strong>App_Code</strong> folder (if not in solution then first create folder named App_Code)  and add one class file named  <strong>NumericTextBox.vb</strong>.</p>
<p>Note: Any code added to the <strong>App_Code</strong> folder is compiled dynamically.</p>
<p>The Code of <strong>NumericTextBox.vb</strong> file is as shown below</p>
<p><span style="color: #993300;">Namespace NHSWebApplication</span></p>
<p><span style="color: #993300;"> Public Class NumericTextBox</span></p>
<p><span style="color: #993300;"> &#8221;Inherit the control from Base Class CompositeControl</span></p>
<p><span style="color: #993300;"> Inherits CompositeControl</span></p>
<p><span style="color: #993300;"> &#8221;Declaring TextBox Web Control</span></p>
<p><span style="color: #993300;"> Private NumericTextBox As TextBox</span></p>
<p><span style="color: #993300;"> &#8221;Declaring ReqularExpressionValidator Web Control</span></p>
<p><span style="color: #993300;"> Private NumericExpressionValidator As RegularExpressionValidator</span></p>
<p><span style="color: #993300;"> &#8221;Overriding CreateChildControlMethod</span></p>
<p><span style="color: #993300;"> Protected Overrides Sub CreateChildControls()</span></p>
<p><span style="color: #993300;"> &#8221;Instanciate TextBox Control</span></p>
<p><span style="color: #993300;"> NumericTextBox = New TextBox</span></p>
<p><span style="color: #993300;"> &#8221;Assigning ID to text box control</span></p>
<p><span style="color: #993300;"> NumericTextBox.ID = &#8220;txtNumericTextBox&#8221;</span></p>
<p><span style="color: #993300;"> &#8221;Adding control</span></p>
<p><span style="color: #993300;"> Me.Controls.Add(NumericTextBox)</span></p>
<p><span style="color: #993300;"> &#8221;Instanciate RegularExpression Control</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator = New RegularExpressionValidator</span></p>
<p><span style="color: #993300;"> &#8221;Assigning ID to RegularExpressionValidator Control</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator.ID = &#8220;vdtNumericExpressionValidator&#8221;</span></p>
<p><span style="color: #993300;"> &#8221;Assigning Basic Properties to RegularExpressionValidator</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator.ControlToValidate = &#8220;txtNumericTextBox&#8221;</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator.ValidationExpression = &#8220;[0-9]*&#8221;</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator.ErrorMessage = &#8220;Invalid Inputs&#8221;</span></p>
<p><span style="color: #993300;"> NumericExpressionValidator.Display = ValidatorDisplay.Dynamic</span></p>
<p><span style="color: #993300;"> &#8221;Adding Cotnrol</span></p>
<p><span style="color: #993300;"> Me.Controls.Add(NumericExpressionValidator)</span></p>
<p><span style="color: #993300;"> End Sub</span></p>
<p><span style="color: #993300;"> End Class</span></p>
<p><span style="color: #993300;">End Namespace</span></p>
<p><span style="color: #993300;"><span style="color: #000000;">Here Class <strong>NumericTextBox</strong> is inherited from the base class <strong>CompositeControl</strong>. Two webcontrols <strong>Textbox</strong> and <strong>RegularExpressioValidator</strong> are declared.</span></span></p>
<p><span style="color: #000000;">Typically one has to override a control’s <strong>CreateChildControls()</strong> method. This method is called when a control builds its collection of child controls. In this method the objects of Textbox and RegularExpressionValidator are initialized and the some of the properties are set in order to get desired output.</span></p>
<p><span style="color: #993300;">&#8221;Assigning ID to text box control<br />
</span></p>
<p><span style="color: #993300;">NumericTextBox.ID = &#8220;txtNumericTextBox&#8221;</span></p>
<p><span style="color: #993300;">&#8221;Assigning ID to RegularExpressionValidator Control</span></p>
<p><span style="color: #993300;">NumericExpressionValidator.ID = &#8220;vdtNumericExpressionValidator&#8221;</span></p>
<p><span style="color: #993300;">&#8221;ID of controls that needs to be validate</span></p>
<p><span style="color: #993300;">NumericExpressionValidator.ControlToValidate = &#8220;txtNumericTextBox&#8221;</span></p>
<p><span style="color: #993300;">&#8221; Regular Expression that only accepts numeric values (0 to 9)</span></p>
<p><span style="color: #993300;">NumericExpressionValidator.ValidationExpression = &#8220;[0-9]*&#8221;</span></p>
<p><span style="color: #993300;">&#8221; Informative Message that needs to display on wrong input</span></p>
<p><span style="color: #993300;">NumericExpressionValidator.ErrorMessage = &#8220;Invalid Inputs&#8221;</span></p>
<p><span style="color: #000000;">Now just build your application and then add new Web Form. Let’s say <strong>TestCustomControl.aspx</strong>. Open its design view or HTML view and see the Toolbox. You will find the custom control named NumericTextBox. Just drag it on Design view or html code. See sample code of ASPX Page below.</span></p>
<p><span style="color: #993300;">&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221; &gt;</span></p>
<p><span style="color: #993300;">&lt;head runat=&#8221;server&#8221;&gt;</span></p>
<p><span style="color: #993300;"> &lt;title&gt;Testing Composite Control&lt;/title&gt;</span></p>
<p><span style="color: #993300;">&lt;/head&gt;</span></p>
<p><span style="color: #993300;">&lt;body&gt;</span></p>
<p><span style="color: #993300;"> &lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;</span></p>
<p><span style="color: #993300;"> &lt;div&gt;</span></p>
<p><span style="color: #993300;"> &lt;cc2:NumericTextBox ID=&#8221;NumericTextBox1&#8243; runat=&#8221;server&#8221; /&gt;</span></p>
<p><span style="color: #993300;"> &lt;/div&gt;</span></p>
<p><span style="color: #993300;"> &lt;/form&gt;</span></p>
<p><span style="color: #993300;">&lt;/body&gt;</span></p>
<p><span style="color: #993300;">&lt;/html&gt;</span></p>
<p><span style="color: #000000;">It will render the Textbox in browser with RegularExpressionValidator. The regular expression restict user to input non-numeric values. If any non-numeric values entered in textbox then it will show message ‘Invalid Inputs’. Here in this example, the message is kept static. You can always make it dynamic by creating properties of composite control and passed it from HTML.</span></p>
<p><span style="color: #000000;">By extending the properties of existing web control you can create more helpful composite controls. Hope this article will help to understand building custom composite control.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/06/building-composite-control-using-asp-net-3-5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building Custom Control Using ASP.NET 3.5</title>
		<link>http://dev.digi-corp.com/2009/06/building-custom-control-using-aspnet-35/</link>
		<comments>http://dev.digi-corp.com/2009/06/building-custom-control-using-aspnet-35/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 12:04:26 +0000</pubDate>
		<dc:creator>vivek.navadia</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Composite Control]]></category>
		<category><![CDATA[Custom Control]]></category>
		<category><![CDATA[HtmlTextWriter]]></category>
		<category><![CDATA[Rendered Control]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=609</guid>
		<description><![CDATA[The two basic types of controls are fully rendered and composite controls. When you build a fully rendered control, you start from scratch. You specify all the HTML content that the control renders to the browser. When you create a composite control, on the other hand, you build a new control from existing controls. Typically, [...]]]></description>
			<content:encoded><![CDATA[<p>The two basic types of controls are fully rendered and composite controls. When you build a fully rendered control, you start from scratch. You specify all the HTML content that the control renders to the browser. When you create a composite control, on the other hand, you build a new control from existing controls.</p>
<p class="MsoNormal">Typically, when building a basic control, you inherit your new control from one of the following base classes:</p>
<p class="MsoNormal"><strong>System.Web.UI.Control</strong></p>
<p class="MsoNormal"><strong>System.Web.UI.WebControls.WebControl</strong></p>
<p class="MsoNormal"><strong>System.Web.UI.WebControls.CompositeControl</strong></p>
<p class="MsoNormal">The CompositeControl class inherits from the WebControl class, which inherits from the Control class. Each of these base classes adds additional functionality.</p>
<p class="MsoNormal"><strong>Building Rendered Controls</strong></p>
<p class="MsoNormal">Let’s start by creating a simple fully rendered control. When you create a fully rendered control, you take on the responsibility of specifying all the HTML content that the control renders to the browser.</p>
<p class="MsoNormal">Create new VB Web Application Project from File Menu and let’s name it <strong>NHSWebApplication. </strong>After Creating Web Application project just right click on <strong>App_Code </strong>folder (if not in solution then first create folder named <strong>App_Code) </strong>and add one class file name <strong>TestControl.vb.</strong></p>
<p class="MsoNormal"><strong>Note: </strong>Any code added to the <strong>App_Code</strong> folder is compiled dynamically.</p>
<p>The Code of <strong>TestControl.vb</strong> file is as shown below</p>
<p class="MsoNormal"><span style="color: #993300;">‘Namespace Declared</span></p>
<p class="MsoNormal"><span style="color: #993300;">Namespace NHSWebApplication</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘TestContril Class is inherited from base class </span><strong><span style="color: #993300;">CONTROL</span></strong></p>
<p class="MsoNormal"><span style="color: #993300;">Public Class TestControl</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Inherits Control</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘Declaring Local Variables for Getting and Setting Value of ROWS and COLUMNS attribute</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘assigned from HTML code of ASPX page</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Private _Rows As Integer</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Private _Columns As Integer</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘Declaring Properties (Attributes) of control to set ROWS from HTML code of ASPX Page</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Public Property Rows() As Integer</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Get</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Return _Rows</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Get</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Set(ByVal value As Integer)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">_Rows = value</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Set</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Property</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘Declaring Properties (Attributes) of control to set COLUMNS from HTML code of ASPX Page</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Public Property Columns() As Integer</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Get</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Return _Columns</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Get</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Set(ByVal value As Integer)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">_Columns = value</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Set</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Property</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘Overrides the RENDER method to draw html content </span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Table)</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘First loop to create Rows</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">For i As Integer = 0 To _Rows &#8211; 1</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Tr)</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘Inner loop to Create Columns</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">For j As Integer = 0 To _Columns &#8211; 1</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.AddAttribute(&#8220;Style&#8221;, &#8220;border:solid 1px #000000&#8243;)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;"> </span><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Td)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.Write(&#8220;Rendering Costom Control&#8221;)</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.RenderEndTag()</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Next</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">writer.RenderEndTag()</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">Next</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Sub</span></p>
<p class="MsoNormal"><span style="color: #993300;">‘End of the Rendering of Custom control</span></p>
<p class="MsoNormal"><span style="color: #993300;"> </span><span style="color: #993300;">End Class</span></p>
<p class="MsoNormal"><span style="color: #993300;">End Namespace</span></p>
<p class="MsoNormal"><span style="color: #000000;">As we see in above code </span><strong><span style="color: #000000;">RENDER </span></strong><span style="color: #000000;">method is override and the object of HtmlTextWriter class is passed to HTML Tag that needs to be rendered. For example</span></p>
<p class="MsoNormal"><span style="color: #000000;"><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Table)</span> same as &lt;Table&gt;</span></p>
<p class="MsoNormal"><span style="color: #000000;"><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Tr)</span> same as &lt;tr&gt;</span></p>
<p class="MsoNormal"><span style="color: #000000;"><span style="color: #993300;">writer.RenderBeginTag(HtmlTextWriterTag.Td)</span> same as &lt;td&gt;</span></p>
<p class="MsoNormal"><span style="color: #000000;">Attributes of each of the Tag is added using </span></p>
<p class="MsoNormal"><span style="color: #993300;">writer.AddAttribute(&#8220;Style&#8221;, &#8220;border:solid 1px #000000&#8243;)</span></p>
<p class="MsoNormal"><span style="color: #000000;">and it is same as </span></p>
<p class="MsoNormal"><span style="color: #993300;">style=”border:solid 1px #000000)</span></p>
<p class="MsoNormal"><span style="color: #000000;">so After each iteration it will create specified row and columns with specified format.</span></p>
<p><span style="color: #000000;">Now just build your application and then add new Web Form. Let’s say </span><strong>TestCustomControl.aspx. </strong>Open its design view or HTML view and see the Toolbox. You will find the custom control named <strong>TestControl. </strong>Just drag it on Design view or html code. See sample code of ASPX Page below.</p>
<p class="MsoNormal"><span style="color: #993300;">&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221; &gt;<br />
</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;head runat=&#8221;server&#8221;&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;title&gt;Untitled Page&lt;/title&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;/head&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;body&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;div&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;cc2:TestControl ID=&#8221;TestControl1&#8243; runat=&#8221;server&#8221; Rows=&#8221;2&#8243; Columns=&#8221;3&#8243;&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;/cc2:TestControl&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;/div&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;"> &lt;/form&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;/body&gt;</span></p>
<p class="MsoNormal"><span style="color: #993300;">&lt;/html&gt;</span></p>
<p class="MsoNormal">It will render a custom control on web form with Table having 2 rows and 3 columns with 1px Black border</p>
<table class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
</tr>
<tr>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
<td width="197" valign="top">
<p class="MsoNormal">Rendering Costom Control</p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal">Hope, this article will help you to understand how to build custom rendered control. I will write about building composite control soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/06/building-custom-control-using-aspnet-35/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Overview of Flex</title>
		<link>http://dev.digi-corp.com/2009/05/overview-of-flex/</link>
		<comments>http://dev.digi-corp.com/2009/05/overview-of-flex/#comments</comments>
		<pubDate>Sat, 30 May 2009 05:49:26 +0000</pubDate>
		<dc:creator>nishant.shah</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[macromedia]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=444</guid>
		<description><![CDATA[What is Adobe Flex ? Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flash Builder or by using the freely available Flex compiler from Adobe. Adobe Flex takes you [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 	 	 --></p>
<p><span style="text-decoration: underline;"><strong>What is Adobe Flex ?</strong></span></p>
<p><strong> </strong></p>
<p><strong> </strong>Adobe Flex is a software development kit released by <strong>Adobe Systems </strong>for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flash Builder or by using the freely available Flex compiler from Adobe.</p>
<p><strong>Adobe Flex</strong> takes you to the next level of web application development with the concept of <strong>Rich Internet Application</strong>(RIAs).You may have seen applications developed natively in Flash itself and realized that it offers a much more robust experience for the user where productivity is bolstered by ease of use,streamlined workflow,and real time interactivity that is impossible to accomplish in HTML itself. However developing rich applications in Flash for those who are core developers is daunting and unintuitive. The Flash development tool is geard for designers, and developing on a timeline is a strange concept. Flex removes that barrier entry by providing a programmatic way for developing these RIAs.</p>
<p>Flex is very prominent and familiar with professional developers. Flex is a set of products designed in an effective way based on efficient delivery of high performance.</p>
<p>Flex is a standard-based programming model for high performance rich internet applications. Flex application will take advantage of adobe flash player 9 and this will enable developer to extend the capabilities enables the client with richer applications in real time.</p>
<p>Flex is a cross-platform development framework for creating Rich Internet Applications(RIAs). A component based tool that you can use to develop apps that run using Flash player or Adobe Air. Adobe Flex Builder software is an Eclipse based IDE for developing RIAs.</p>
<p><span style="text-decoration: underline;"><strong>Basics of Flex :</strong></span></p>
<ul>
<li>Runs in the Flash 	Player or AIR.</li>
<li>Tag based markup MXML 	serves as the basis for Flex Projects.</li>
<li>MXML is a custom XML 	namespace,looks like &lt;mx:MyTag&gt;&lt;/mx:MyTag&gt;.</li>
<li>Component based 	development : Containers / Layouts Components , UI Elements , Data 	Connectors.</li>
<li>ActionScript 3 can be 	used to add behaviors or other interactivity not covered by MXML.</li>
<li>Supports common OOP 	practices like MVC patterns,code behind,etc.</li>
<li>MXML components can be 	brought onto the canvas via the GUI similar to Dreamweaver or 	VisualStudio.</li>
<li>Markup can be written 	by hand with code assist, too. Again, similar to Dreamweaver or 	VisualStudio.</li>
<li>MXML components have 	attributes that allow for modification of appearance or behavior.</li>
<li>Components can be 	extended for additional capabilities or reuse via MXML or AS or a 	combo of both.</li>
<li>Containers control 	layout (Canvas, Vertical Box, Horizontal Box)</li>
<li>UI components display 	data, control interactivity or display states or other visual 	feedback (Datagrids, lists, buttons, selects menus,radio buttons, etc.).</li>
<li>Data components load 	or send data (Services, XML, Remoting, etc).</li>
<li>Other tags include: 	Script, Style, etc.</li>
<li>Tags can be nested 	similar to HTML/XML.</li>
</ul>
<p><span style="text-decoration: underline;"><strong>Release history :</strong></span></p>
<ul>
<li>Flex 1.0 &#8211; March 	2004</li>
<li>Flex 1.5 &#8211; October 	2004</li>
<li>Flex 2.0(Alpha) &#8211; 	October 2005</li>
<li>Flex 2.0 Beta 1 &#8211; 	February 2006</li>
<li>Flex 2.0 Beta 2 &#8211; 	March 2006</li>
<li>Flex 2.0 Beta 3 &#8211; 	May 2006</li>
<li>Flex 2.0 Final &#8211; 	June 28,2006</li>
<li>Flex 2.0.1 &#8211; January 	5,2007</li>
<li>Flex 3.0 Beta 1 &#8211; 	June 11,2007</li>
<li>Flex 3.0 Beta 2 &#8211; 	October 1,2007</li>
<li>Flex 3.0 Beta 3 &#8211; 	December 12,2007</li>
<li>Flex 3.0 &#8211; February 	25,2008</li>
<li>Flex 3.1 &#8211; August 	15,2008</li>
<li>Flex 	3.2 &#8211; November 17,2008</li>
<li>Flex 3.3 &#8211; March 	4,2009</li>
</ul>
<p align="left"><span style="text-decoration: underline;"><strong>What is Flex Builder ?</strong></span></p>
<p>Macromedia recently released Flex Builder (formerly known as &#8220;Brady&#8221;), an IDE based on Macromedia Dreamweaver MX 2004. Bundled with the Flex application server, Flex Builder provides a WYSIWYG environment for creating Flex applications, an integrated debugger, and code hinting for ActionScript and MXML (plus all of the features supported by Dreamweaver).</p>
<p>The IDE still shows some rough edges. For example, clicking &#8220;Help&#8221; in the &#8220;Manage Sites&#8221; dialog launches &#8220;Using Dreamweaver,&#8221; not &#8220;Using Flex Builder.&#8221; So, if you get stuck in the middle of defining a new Flex site, you won&#8217;t have access to Flex Builder&#8217;s excellent support documents. In test instances, opening any &#8220;On Demand&#8221; video tutorials launched Mozilla-even though it wasn&#8217;t set as the default browser.</p>
<p>Perhaps the best way to get a sense of the productivity benefits of Flex Builder is to compare it to Macromedia&#8217;s other Flash IDE, Macromedia Flash MX 2004 Professional. Both IDEs support a component called &#8220;Accordion&#8221; that provides a compact interface widget for showing and hiding information. A Flash developer can drag the Accordion component to the stage, but to populate it with data must use the ActionScript <code>Accordion.createChild()</code> method to instantiate a <code>UIObject</code> or link an existing symbol. It&#8217;s not rocket science, but it <em>is</em> time consuming. A developer working with Flex Builder, on the other hand, can simply drag an Accordion container to the stage and populate it with drag-and-drop controls such as form widgets or images. The difference in productivity is an order of magnitude. Think of Flex Builder as Visual Studio.NET Light for Flash.</p>
<p align="left"><span style="text-decoration: underline;"><strong>Advantages of Flex :</strong></span></p>
<ul>
<li>
<p align="left">Flex applications can 	be intuitive, easy to use, and almost have the feel of the desktop.</p>
</li>
<li>
<p align="left">Easy to program and 	deploy.</p>
</li>
<li>
<p align="left">Can be deployed right 	now on 50% or more of the world&#8217;s browsers, with ubiquity 	increasing daily.</p>
</li>
<li>
<p align="left">Dedicated IDE based on 	Dreamweaver available now.</p>
</li>
<li>
<p align="left">Doesn&#8217;t require a 	large client installation like the .NET runtime.</p>
</li>
<li>
<p align="left">Extensive Visual 	component library.</p>
</li>
<li>
<p align="left">Powerful coding tools.</p>
</li>
<li>
<p align="left">Scalable and reliable 	solution.</p>
</li>
<li>
<p align="left">Superb Flex 	programming model.</p>
</li>
<li>
<p align="left">Easy Integration into 	a server application.</p>
</li>
<li>
<p align="left">High performance data 	synchronization engine.</p>
</li>
<li>
<p align="left">Interactivity due to 	video, audio, streaming and messaging components.</p>
</li>
</ul>
<p align="left"><span style="text-decoration: underline;"><strong>Disadvantages of Flex :</strong></span></p>
<ul>
<li>
<p align="left">Macromedia has poor 	track record with servers and server tools.</p>
</li>
<li>
<p align="left">Expensive.</p>
</li>
<li>
<p align="left">No free developer 	download.</p>
</li>
</ul>
<p align="left"><span style="text-decoration: underline;"><strong>Examples :</strong></span></p>
<ul>
<li>
<p align="left">To 	get record from DataGrid from particular row and column :</p>
<ul>
<li>var 			SelectedData:String = 			DataGrid.dataProvider[event.rowIndex][DataGrid.columns[event.columnIndex].dataField];</li>
</ul>
</li>
<li>
<p align="left">To 	create Custome Menu on right click :</p>
<ul>
<li>private 			var cm:ContextMenu = new ContextMenu();
<p align="left">cm.hideBuiltInItems();</p>
<p align="left">var 			newMenu:ContextMenuItem =</p>
<ul>
<p align="left">new 				ContextMenuItem(&#8220;View Item&#8221;,true);</p>
</ul>
<p align="left">newMenu.addEventListener(ContextMenuEvent.Menu_ITEM_SELECT,</p>
<p align="left">doMenuFunction);</p>
<p align="left">cm.customItems.push(newMenu);</p>
</li>
<li>private 			function doMenuFunction():void
<p align="left">{</p>
<ul>
<p align="left">Alert.show(event.currentTarget.caption.toString());</p>
</ul>
<p align="left">}</p>
<p align="left">It 			Shows Selected Menu Item.</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/05/overview-of-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET Security</title>
		<link>http://dev.digi-corp.com/2009/05/aspnet-security/</link>
		<comments>http://dev.digi-corp.com/2009/05/aspnet-security/#comments</comments>
		<pubDate>Sat, 30 May 2009 05:41:11 +0000</pubDate>
		<dc:creator>nikunj.padaliya</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ASP.NET Security]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Authorization]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=335</guid>
		<description><![CDATA[Security is one of the most important concerns in application software development. Building a robust security model is one of the most important factors that drive the success of application software. As far as security in ASP.NET is concerned, three terms come into my mind, i.e., Authentication, Authorization and Impersonation. Put simply, authentication authenticates the [...]]]></description>
			<content:encoded><![CDATA[<p>Security is one of the most important concerns in application software development. Building a robust security model is one of the most important factors that drive the success of application software. As far as security in ASP.NET is concerned, three terms come into my mind, i.e., Authentication, Authorization and Impersonation. Put simply, authentication authenticates the user’s credentials and authorization relates to the resources that an authenticated user has access to. This article is the first in a series of articles on ASP.NET security and discusses these concepts and their applicability.</p>
<p>Let us start our discussion with a brief outline on the sequence of events are as far as authentication and authorization are concerned when a new request comes in. When a new request arrives at IIS, it first checks the validity of the incoming request. If the authentication mode is anonymous (default) then the request is authenticated automatically. But if the authentication mode is overridden in the web.config file settings, IIS performs the specified authentication check before the request is passed on to ASP.NET.</p>
<p><strong>Authentication</strong></p>
<p>Authentication determines whether a user is valid or not based on the user’s credentials. Note that a user can be authorized to access the resources provided the user is an authenticated user. The application’s web.config file contains all of the configuration settings for an ASP.NET application. An authentication provider is used to prove the identity of the users in a system. There are three ways to authenticate a user in ASP.NET:</p>
<p>Forms authentication<br />
Windows authentication<br />
Passport authentication<br />
 </p>
<p><strong>Forms Authentication</strong></p>
<p>This is based on cookies where the user name and the password are stored either in a text file or a database. It supports both session and persistent cookies. After a user is authenticated, the user’s credentials are stored in a cookie for use in that session. When the user has not logged in and requests for a page that is secured, he or she is redirected to the login page of the application. The following code snippet illustrates how this can be implemented in ASP.NET.</p>
<p>&lt;configuration&gt;<br />
&lt;system.web&gt;<br />
&lt;authentication mode=&#8221;Forms&#8221;/&gt;<br />
&lt;forms name=&#8221;LoginForm&#8221; loginUrl=&#8221;LoginForm.aspx&#8221; /&gt;<br />
&lt;authorization&gt;<br />
&lt;deny users=&#8221;?&#8221;/&gt;<br />
&lt;/authorization&gt;<br />
&lt;/system.web&gt;<br />
&lt;/configuration&gt;</p>
<p> </p>
<p><strong>Windows Authentication</strong></p>
<p>Windows Authentication is used to validate a user based on the user’s Windows Account; however, this is only applicable in intranet environments where the administrator has full control over the users in the network. The following code snippet illustrates how we can implement Windows Authentication in ASP.NET.</p>
<p>&lt;authentication mode=&#8221;Windows&#8221;/&gt;<br />
&lt;authorization&gt;<br />
&lt;allow users =&#8221;*&#8221; /&gt;<br />
&lt;/authorization&gt;<br />
 </p>
<p><strong>Passport Authentication</strong></p>
<p>Passport authentication is a centralized authentication service that uses Microsoft&#8217;s Passport Service to authenticate the users of an application. It allows the users to create a single sign-in name and password to access any site that has implemented the Passport single sign-in (SSI) service. The following code snippet illustrates how we can implement Passport Authentication in ASP.NET.</p>
<p>&lt;configuration&gt;<br />
&lt;system.web&gt;<br />
&lt;authenticationmode=&#8221;Passport&#8221;&gt;<br />
&lt;passportredirectUrl=&#8221;LoginForm.aspx&#8221; /&gt;<br />
&lt;/authentication&gt;<br />
&lt;authorization&gt;<br />
&lt;deny users=&#8221;?&#8221; /&gt;<br />
&lt;/authorization&gt;<br />
&lt;/system.web&gt;<br />
&lt;/configuration&gt;</p>
<p> </p>
<p><strong>Authorization</strong></p>
<p>Authorization is the process of determining the accessibility to a resource for a previously authenticated user. Note that authorization can only work on authenticated users, hence ensuring that no un-authenticated user can access the application. The syntax for specifying authorization in ASP.NET is as follows.</p>
<p>&lt;authorization&gt;<br />
&lt; [ allow | deny ] [ users ] [ roles ] [ verbs ] /&gt;<br />
&lt;/authorization&gt;<br />
In ASP.NET, there are the following types of authorizations.</p>
<p>URL Authorization<br />
File Authorization<br />
Authorization based on ACL (Access Control List)<br />
 </p>
<p><strong>Impersonation</strong></p>
<p>According to MSDN, &#8220;When using impersonation, ASP.NET applications can optionally execute with the identity of the client on whose behalf they are operating. The usual reason for doing this is to avoid dealing with authentication and authorization issues in the ASP.NET application code. Instead, you rely on Microsoft Internet Information Services (IIS) to authenticate the user and either pass an authenticated token to the ASP.NET application or, if unable to authenticate the user, pass an unauthenticated token. In either case, the ASP.NET application impersonates whichever token is received if impersonation is enabled. The ASP.NET application, now impersonating the client, then relies on the settings in the NTFS directories and files to allow it to gain access, or not. Be sure to format the server file space as NTFS, so that access permissions can be set”.</p>
<p>Note that Impersonation is disabled by default and can be specified in the web.config file as shown in the code snippet given below.</p>
<p>&lt;identity impersonate=&#8221;true&#8221;/&gt;<br />
or<br />
&lt;identity impersonate=&#8221;false&#8221;/&gt;</p>
<p>To impersonate a particular identity, specify the following in your application’s web.config file.</p>
<p>&lt;identity impersonate=&#8221;true&#8221; username=&#8221;joydip&#8221; password=&#8221;jude&#8221;/&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/05/aspnet-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

