Showing posts with label Show all posts
Showing posts with label Show all posts


MVC vs Webforms


New technologies have knocked into market, it is very hard to select technologies when to use which technology, so there is very good question MVC vs Web forms emerging today. I have posted this article compare with traditional MVC vs Web forms.

MVC vs Webforms

Web form Advantage over MVC Patterns

1. Event Driven Programming

Traditional web forms is based mainly on events,  so when we have to operate any action then we require events. There are bundle of  events involved in traditional programming moreover Microsoft Visual studio have provided many facilities to handle event drive model. So it is very easy to handle developers & he can performs according to situation within limited time.

2. Aggressive State Management

Traditional web forms have great liquidity with him that he have a number of techniques to handle state management efficiently. We can forward our information from one web page to another efficiently & are developer friendly.

3. Controls, Library Availability

Traditional web forms have provided bunch of bundle of controls to deal with complex situations very efficiently. There are series of versions to use 3rd party controls to make application more interactive in less time. There are different script, utilities, open classes, methods & other techniques these help very much developer.

4. Rapid Development

I have overview in #3 that traditional web forms have a series of libraries & controls in the market so we have to reduce development time then we can use alternatively. Reduce time means simply reduce costly as well.

5. Interconnected (Tightly coupled) 

Traditional web forms provides the facility to interconnected the application, in short we can say that traditional web forms are tightly couples.

6. Layered Design

We can design the application architecture different layers i.e. Presentation Layer, Business logic layer, Data Access Layer, I have posted earlier 3 tier architecture

MVC Web Application Advantages

1. Loosely Coupling

MVC forms architecture is based on strongly 3 different layers Model, View & controller so these are different from each other, so these are not connected strongly as in traditional web forms. We can say that MVC web application have loosely couples.

2. Testing Friendly

MVC architecture provides 3 different layers so we can test separately each layers, this is easy task to developer.

3. URL Routing feature

MVC forms have great feature in build in architecture it supports fully URL routing so MVC forms application can appear quickly on major search engine.

4. Not Supported State Management

MVC patterns does not support state management so can avoid unusual requests to server.


MVC is my first choice because it is not event event driven, Loosely coupling, TDD and URL routing is key features of MVC. Web API has been introduced very robust features in MVC to develop HTML based web service (SOA), earlier working with simple web service or WCF (Windows Communication Foundation). Now Microsoft MVC has been enriched with new robust features to develop Hybrid apps and very mobile friendly. Owin security features is remarkable in MVC to overcom traditional ASP.Net.

Suggested Reading


PDF Component for


Today there is more general requirements to generate reports in PDF component. I have suggested some intelligent tools to generate tools, have not any default component to generate PDF reports so we have to rely on 3 party component as listed below:

PDF Component for ASP.Net

1) iTextSharp have very familiar tools to generate PDF reports earlier it was free before Version 5 but its latest version are paid in market. Here is iTextsharp download link . & also iTextsharp official website link.
here is my earlier article that shows How can we export datatable to PDF using iTextSharp.

 2) is another PDF Component for to generate PDF component in, it is cheaper to iTextsharp component, we can manipulate the data with this component & can show the report as per our desire.
3) There is more option to generate PDF Component for is SSRS, we can generate PDF reports using with SSRS.
4) PDF Clawn is one more option, with the help of PDF Clawn we can generate also PDF reports and this component is open sourced on internet. Here is link to download PDF Clawn


In short, I have suggested above best components to generate reports how can we generate PDF reports (PDF Component for


State Management in


Today State management have vital role to play maintain state in HTTP protocol is stateless and it can’t be save/preserve the information so it is brilliant requirement to maintain states on client side as well server side. Ever changing in technology  these days we have to follow some ideal techniques to maintain the states client side because when ASP.Net server disconnects from server then information are saved in controls called states. I have suggested below some good techniques to maintain state management in ASP.Net.
State Management in
State Management in

Client Based State Management options

1. View state: We can maintain view state in when render event is fired and now page can save the information & disconnected from the server. View state life cycle is only one page we can’t navigate the information to other page with help of view state technique.

ViewState["Technology_Crowds_Year"] = "2013";

2. Control state: Control state is also maintained to preserve the state management in but it can be possible only when we have enable view state is true otherwise it is not able to maintain state in

3. Hidden fields: Hidden field s are very good technique to maintain state in client side, hidden fields works likes repository  to save information In client side.

<asp:HiddenField id="hdTechnologyCrowds" runat="server" value='<%= Request.QueryString["TechID"] %>' />

Namespace: System.Web.UI.WebControls.HiddenField
Assembly: System.Web (System.Web.dll)

4. Cookies: Cookies is also used to maintain information at client side we can set life of cookies with expiration date as per our requirement.

5. Query strings: Query string is also good techniques to maintain state at the client side, Query string life cycle is from one page to next one only.
Example: =10
Querystring is most weak state in so don’t rely on it mostly because it can be tampered very easily.

Server Based State Management options

1. Application state:  This is very brilliant technique to maintain state in ASP.Net, we can share information globally through application state & can use also this state throughout the application. It have brilliant features to track application start, application end etc.

2. Session state: This technique is most ideal technique to maintain state management in, When any user open the browser & after authorization login then a new session is started & always different from other users. It is very good technique to track multiple browser session & multiple users.

3. Profile Properties: Profile properties is also ideal technique to maintain state in, profile properties is maintained until the session is preserves in the browser, we can store the information related to particular user & can user on all pages under user authorization.

Suggested Reading


Data manipulation Language (DML) is used to manage the schema in the database.  Data Manipulation Language (DML) provides great facility to manipulate the tables in the database, we can view the database according our objective.
SELECT :  Select statement have great facility to retrieve the columns from the table
INSERT: With the help of Insert statement we can save the data in the schema.
UPDATE:  This statement can have the ability to alter existing database.
DELETE: This statement can delete the existing data in the database.
MERGE: This statement can upsert operation (Insert or update)
CALL: This statement call PS/SQL
EXPLAIN PLAIN: It can explain path to database.
LOCK TABLE: This have the great ability to control concurrency in the database.




Data definition Language (DDL) has the ability to define the structure of the schema.
CREATE: It can create a new table schema in the database.
ALTER: This statement can alter object in the schema.
TRUNCATE: This statement can delete the data from the database including log files.
COMMENT: It have the ability create comment to data dictionary.
RENAME: This statement have the ability to rename the objects in the database.


Data Control Language (DCL) statements. Below have provided some examples of DCL.
GRANT:  It has the ability to provide privileges to the user.   
REVOKE: This statement have the facility to remove privileges provided by GRANT.


Transaction Control Statements (TCL) is used to handle the changes done by Data manipulation language.
COMMIT: This statement have the ability to commit data.
SAVEPOINT: This statement identifies point where we can roll back later.
ROLLBACK:  This statement can done changes in the object to earlier state.
SET TRANSACTION: This statement can control the changes in the objects, we can commit or rollback objects as per the query requirement.

Suggested Reading


How can we export datatable to PDF using iTextSharp


I have illustrated below with example how can we export data table to PDF using iTextSharp

Step 1. We can download itextsharp.dll from the website
Step 2. Please click on add exiting item to add iTextSharp.dll in the "Bin" folder.

Step 3. In the next step, put downloaded iTextSharp.dll in the project folder structure to add reference of the iTextSharp.dll in the application.


Step 4. You may check now that dll reference have been added in your application. 


Step 5. Now I have provided below c# code snippet as given below:

 protected void btnPDF_Click(object sender, ImageClickEventArgs e)
        DataTable dtn = new DataTable();
        dtn = GetDataTable();
        dtPDF = dtn.Copy();
        for (int i = 0; i <= dtn.Rows.Count - 1; i++)

 public void ExportToPdf(DataTable myDataTable)
        Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
            PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
            Chunk c = new Chunk("" + System.Web.HttpContext.Current.Session["CompanyName"] + "", FontFactory.GetFont("Verdana", 11));
            Paragraph p = new Paragraph();
            p.Alignment = Element.ALIGN_CENTER;
            string clientLogo = Server.MapPath(".") + "/logo/tpglogo.jpg";
            string imageFilePath = Server.MapPath(".") + "/logo/tpglogo.jpg";
            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
            //Resize image depend upon your need   
            jpg.ScaleToFit(80f, 60f);
            //Give space before image   
            jpg.SpacingBefore = 0f;
            //Give some space after the image   
            jpg.SpacingAfter = 1f;
            jpg.Alignment = Element.HEADER;
            Font font8 = FontFactory.GetFont("ARIAL", 7);
            DataTable dt = myDataTable;
            if (dt != null)
                //Craete instance of the pdf table and set the number of column in that table  
                PdfPTable PdfTable = new PdfPTable(dt.Columns.Count);
                PdfPCell PdfPCell = null;
                for (int rows = 0; rows < dt.Rows.Count; rows++)
                    for (int column = 0; column < dt.Columns.Count; column++)
                        PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8)));
                //PdfTable.SpacingBefore = 15f; // Give some space after the text or it may overlap the table            
                pdfDoc.Add(PdfTable); // add pdf table to the document   
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment; filename= SampleExport.pdf");
        catch (DocumentException de)
        catch (IOException ioEx)
        catch (Exception ex)

Suggested Reading


Login failed for user iis apppool default apppool System.Data.Sqlclient.Sqlexception


I am here highlighting the difficulty System.Data.Sqlclient.Sqlexception:Login failed for user iis apppool \default apppool usually encountering whereas working with ASP.Net application with IIS. I actually have been engaged on web application. Everything was going fine however suddenly I got the error “System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool’” and database connection couldn't open.

Error Description:

System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool

Know How About Application Pool Identity 

Application Pool Identity corresponds to security of your website whereas running your website under IIS. Application Pool Identity runs your website unique account. Network service is IIS default identity, it doesn't need password so caused low prevailed. You'll reconfigure IIS Application Pool Identities as per your specific demand.
I have below provided steps to resolve this issue.

Step 1: Go to Run (Win+R Shortcut) and then type “inetmgr” and hit “OK” button.

Step 2: Now you are in the IIS and now expand left pane and click on the “Application Pools

Login failed for user iis apppool
IIS (Application Pool)

Step 3: Now you can select “DefaultAppPool” and click on “Advance Settings”.

Step 4: Now open “Advance Settings” window and scroll down window to “Process Model”. Under the “Process Model” section select “Identity” property. Select “LocalSystem” from drop down list. Local Service works the computer on local system & over the local computer.

Application Pool Identity
Application Pool Identity
Step 5: Process Model Element was introduced with IIS 7.0
Step 6: "ApplicationPoolIdentity" runs under dynamically created application pools. identity account. "ApplicationPoolIdentity" pool access the resources from IIS AppPool\<AppPool>, It's nice feature to administrator who will impose security privileges to end users. This is often run mostly for remotely or public accessing the website.


Step 7: Now Click on "OK" button, you have to take optional Step 4 or step 6 to run your application smoothly.


By Command line, we can also provide complete access to DefaultAppPool (if Already complete access to production server)

ICACLS test.txt /grant "IIS AppPool\DefaultAppPool":F


Given above steps will provide you complete helpline, the way to resolve the error of “Login failed for user 'IIS APPPOOL\DefaultAppPool’”. Application pool identity need default permission to run your website under IIS perfectly for specific account access group.  I hope steps provided above will work to resolve your problem perfectly.

Relevant Reading:

Videologin failed for user


Downloader in


Today, I am demonstrating a down loader in using  with System.Web.WebRequest and System.Web.WebResponse method, if we need to start download on specific length then we can add request range using with Request.Addrange(10000,50000).
Downloader in C#
Down loader in ASP.Net
There is thousands of C# downloader available on internet. We can devise a program to download data from specific web location and put locally on our drive. Here I am providing a program which demonstrates how can we make a program to down loader in


Pick Gridview row cell in ASP.Net


How to pick grid view row cell in, below is written code snippet to pick grid view row cell.

Protected Sub Grd_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Grd.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
For i As Integer = 0 To Grd.Columns.Count - 1
'e.Row.Cells(i).Attributes.Add("onclick", "FillValue('" + e.Row.Cells(i).ClientID & "')")
e.Row.Cells(i).Attributes.Add("onclick", "FillValue('" + e.Row.Cells(0).ClientID & "','" + e.Row.Cells(1).ClientID & "','" & e.Row.Cells(2).ClientID & "','" & e.Row.Cells(3).ClientID & "','" & e.Row.Cells(4).ClientID & "','" & e.Row.Cells(5).ClientID & "','" & e.Row.Cells(6).ClientID & "')")
End If

End Sub

<script type="text/javascript">
function FillValue(cellId, GLAccountNumber, GLDescription, LineItemDescription, ProjectID, Amount, PaymentDetailID)
document.getElementById('txtID').value = document.getElementById(cellId).innerHTML;
document.getElementById('GLAccountNumber').value = document.getElementById(GLAccountNumber).innerHTML;
document.getElementById('GLDescription').value = document.getElementById(GLDescription).innerHTML;
document.getElementById('LineItemDescription').value = document.getElementById(LineItemDescription).innerHTML;
document.getElementById('ProjectID').value = document.getElementById(ProjectID).innerHTML;
document.getElementById('Amount').value = document.getElementById(Amount).innerHTML;
document.getElementById('PaymentDetailID').value = document.getElementById(PaymentDetailID).innerHTML;

Suggested Reading

Gridview Row Backcolor in ASP.NET


I am writing in this article how to change row color of Gridview on the condition basis. Gridview is used to display data in tabular form. ASP.Net provides flexibility Grdiview to perform numerous operations, we can play data as per our requirement and finally can display in GUI Gridview Server Control.   

Define Gridivew in ASPX page

In ASPX page, here I am defining Gridview server control to display data, we can define here height, width of Gridview, also with styling.


Calling Method on Page Load

On page load, I am calling method BindGridview(), where I bind data to Gridview control.

if (!Page.IsPostBack)
   // Calling method to bind gridview

Binding Data to Gridview

Here I am adding data to Datatable then binding Datatable to Gridview.
using System.Data;

private void BindGridview()
        // declaring datatable
 DataTable _dt_TC_Grd_color = new DataTable();
 // add column to datatable
 _dt_TC_Grd_color.Columns.Add("Row_no", typeof(Int32));
 _dt_TC_Grd_color.Columns.Add("Fruit_Name", typeof(string));
 _dt_TC_Grd_color.Columns.Add("Price", typeof(Decimal));

 // assigning value
 _dt_TC_Grd_color.Rows.Add(1, "Orange", 10);
 _dt_TC_Grd_color.Rows.Add(2, "Apple",20);
 _dt_TC_Grd_color.Rows.Add(3, "Mango",30);
 _dt_TC_Grd_color.Rows.Add(4, "Banana", 40);
 _dt_TC_Grd_color.Rows.Add(4, "Papaya", 50);
 _dt_TC_Grd_color.Rows.Add(4, "Guava", 60);

 // binding datatable to gridview control
 grdBackgroundColor.DataSource = _dt_TC_Grd_color;

Changing Gridview Row Back Color to Yellow

Here I am changing Gridview back color to yellow on the condition basis where price is less than 20.
  decimal price = decimal.Parse(e.Row.Cells[2].Text);

  // change row color to yellow
  if (price < 20)
     e.Row.BackColor = System.Drawing.Color.Yellow;

Gridview yellow row color

Changing Gridview Row Back Color to Blue

Here I am changing Gridview back color to blue where price greater than twenty and price less than equal to forty.
 // change row color to blue
 if (price > 20 && price <= 40)
    e.Row.BackColor = System.Drawing.Color.Blue;
Changing Gridview Row Back Color to Red
Here I am changing Gridview back color to Red where price greater than forty.

// change row color to red
if (price > 40)
  e.Row.BackColor = System.Drawing.Color.Red;
Gridview red row color

Gridview RowDataBound Event Firing

Here is complete view of RowDataBound, where we have applied conditions to price to change the color of rows Yellow, Blue, Red etc.
protected void grdBackgroundColor_RowDataBound(object sender, GridViewRowEventArgs e)
 // checking for gridview row
 if (e.Row.RowType == DataControlRowType.DataRow)
     decimal price = decimal.Parse(e.Row.Cells[2].Text);

     // change row color to yellow
     if (price < 20)
        e.Row.BackColor = System.Drawing.Color.Yellow;
     // change row color to blue
     if (price > 20 && price <= 40)
       e.Row.BackColor = System.Drawing.Color.Blue;

     // change row color to red
     if (price > 40)
       e.Row.BackColor = System.Drawing.Color.Red;


Now Rows are changed according to condition i.e. Yellow, Blue and Red. In the same way, we can apply conditions to change row back color.

Download Sample in Zip Format

Download Sample

Suggested Reading