<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1194836729866470946</atom:id><lastBuildDate>Wed, 25 Jan 2012 22:09:50 +0000</lastBuildDate><category>LINQ</category><category>Visual Studio</category><category>Bulk Insert</category><category>Dictionary</category><category>foreach</category><category>OpenXML</category><category>REST</category><category>SilverLight</category><category>Asp.Net</category><category>Image</category><category>Sql Server</category><category>Business Application</category><category>collection</category><category>Cross Domain</category><category>Beginner</category><category>Ajax</category><category>JAVA SCRIPT / JQUERY</category><category>Testing</category><category>string</category><category>c#</category><category>split</category><category>Exception</category><category>Intermediate</category><category>WCF</category><category>Database</category><category>HTML / CSS</category><category>Lazy initialization</category><category>Linq to SQL</category><category>Certificate</category><category>Debugging</category><category>Entity Framework</category><title>GMind Solution</title><description /><link>http://pranayamr.blogspot.com/</link><managingEditor>noreply@blogger.com (pranay)</managingEditor><generator>Blogger</generator><openSearch:totalResults>88</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GmindSolution" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="gmindsolution" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:copyright>Pranay Rana @2010 Gmind Solution</media:copyright><media:thumbnail url="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1326.snc4/161669_100000480841158_3237723_n.jpg" /><media:keywords>net,wcf,linq,sql,jquery,javascript,c</media:keywords><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Software How-To</media:category><itunes:owner><itunes:email>pranayamr@gmail.com</itunes:email><itunes:name>Pranay Rana</itunes:name></itunes:owner><itunes:author>Pranay Rana</itunes:author><itunes:explicit>no</itunes:explicit><itunes:image href="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1326.snc4/161669_100000480841158_3237723_n.jpg" /><itunes:keywords>net,wcf,linq,sql,jquery,javascript,c</itunes:keywords><itunes:subtitle>Gmind Solution</itunes:subtitle><itunes:category text="Technology"><itunes:category text="Software How-To" /></itunes:category><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6899808732783847888</guid><pubDate>Mon, 23 Jan 2012 13:33:00 +0000</pubDate><atom:updated>2012-01-23T05:33:30.739-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Bug in Gridview Editing</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bX0v_FzntuL5vd_GV1X0OytGf1Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bX0v_FzntuL5vd_GV1X0OytGf1Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bX0v_FzntuL5vd_GV1X0OytGf1Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bX0v_FzntuL5vd_GV1X0OytGf1Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In This small post is about the bug I found when we do inline editing in GridView control of ASP.Net in web application. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;To understand this fully follwing is my gridview code in AspX file&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&lt;gridview autogeneratecolumns="false" autogenerateeditbutton="True" gridlines="both" id="grdView" onrowcancelingedit="grdView_RowCancelingEdit" onrowdatabound="grdView_RowDataBound" onrowediting="grdView_RowEditing" onrowupdating="grdView_RowUpdating" runat="server" width="100%"&gt;
        &lt;rowstyle cssclass="contentframework-aligncentre"&gt;
        &lt;alternatingrowstyle cssclass="contentframework-formdatalabel"&gt;
        &lt;headerstyle cssclass="contentframework-dataheadertop"&gt;
        &lt;columns&gt;
            &lt;templatefield headerstyle-font-bold="true" headertext="Rate" horizontalalign="Right" itemstyle-=""&gt;
                &lt;itemtemplate&gt;
                    &lt;label id="lblRate" runat="server" text="&amp;lt;%#Bind(&amp;quot;Currency_Rate&amp;quot;) %&amp;gt;"&gt;&lt;/label&gt;
                &lt;/itemtemplate&gt;
                &lt;edititemtemplate&gt;
                    &lt;textbox id="txtRate" maxlength="10" runat="server" text="&amp;lt;%# Bind
                          (&amp;quot;Currency_Rate&amp;quot;) %&amp;gt;"&gt;&lt;/textbox&gt;
                    &lt;requiredfieldvalidator controltovalidate="txtRate" errormessage="*" id="reqRate" runat="server"&gt;
                    &lt;/requiredfieldvalidator&gt;
                &lt;/edititemtemplate&gt;
            &lt;/templatefield&gt;
        &lt;/columns&gt;
        &lt;emptydatatemplate&gt;
            &lt;label id="lblEmptyRow" runat="server" text="No Data Found"&gt;&lt;/label&gt;
        &lt;/emptydatatemplate&gt;
    &lt;/gridview&gt;
&lt;/pre&gt;As you see in code I have attahced RowDataBound which fires when data get bound with the each row of the grid and RowEditing which get fire when user press edit button of the row in gridview.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code in .Aspx.cs File&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;#region Grid Events
    protected void grdView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grdFXRate.EditIndex = e.NewEditIndex;
        BindGrid();
    }

    protected void grdView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grdView.EditIndex = -1;
        BindGrid();
    }

    protected void grdView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //get data and update
        int Currency_Rate = 0;
        TextBox txtRate = row.FindControl("txtRate") as TextBox;
        if (txtRate != null)
            Currency_Rate = Convert.ToDouble(txtRate.Text);

        saveDetails();
        grdView.EditIndex = -1;
        BindGrid();
    }

    protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowState == DataControlRowState.Edit )
        {
            GridViewRow row = e.Row;
            TextBox txtRate = row.FindControl("txtRate") as TextBox;
            if (txtRate != null)
                txtRate.Attributes.Add("onKeypress", "IntegerAndDecimal(event,'" + txtRate.ClientID + "',true)");
        }
    }
    #endregion Grid Events
&lt;/pre&gt;&lt;br /&gt;
As you see in code I have written code RowDataBound which find textbox control and attach javascript with it.&amp;nbsp; And second thing to &lt;em&gt;notedown&lt;/em&gt; is that it finds textbox and attach script with it when row is in edit mode. This code works fine its attach script wwith the textbox when row is in edit mode.&lt;br /&gt;
&lt;b&gt;Problem&lt;/b&gt;&lt;br /&gt;
But this code dont work when I click on edit butoon of alternet row which means that it not satisfy if condition. In Edit mode alternet row sate is "Alternet | Edit" where as when you click edit of non-alternetrow rostate is "Edit" which statify the if condition.&lt;br /&gt;
&lt;br /&gt;
You weill get edit by below image where in immediate window it shows sate of alternet row.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-DGnsAevdVJw/TxKEzdTAY-I/AAAAAAAACm0/cAwzCGGwM1U/s1600/Grid%2BAlternet%2Bedit.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="295px" src="http://2.bp.blogspot.com/-DGnsAevdVJw/TxKEzdTAY-I/AAAAAAAACm0/cAwzCGGwM1U/s400/Grid%2BAlternet%2Bedit.jpg" width="400px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
Following is solution to avoid problem with the alternet row edit.&lt;br /&gt;
&lt;pre class="bush: csharp"&gt;protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
{
     if ((e.Row.RowState &amp;amp; DataControlRowState.Edit) &amp;gt; 0)
     {
          GridViewRow row = e.Row;
          TextBox txtRate = row.FindControl("txtRate") as TextBox;
          if (txtRate != null)
               txtRate.Attributes.Add(
                    "onKeypress", "IntegerAndDecimal(event,'" + txtRate.ClientID + "',true)");
     }
}
&lt;/pre&gt;As you see in code&amp;nbsp;condtion&amp;nbsp;&lt;em&gt;e.Row.RowState &amp;amp; DataControlRowState.Edit&lt;/em&gt; satisfy the for both alternet and non-alternet row and works fine.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6899808732783847888?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/01/bug-in-gridview-editing.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://2.bp.blogspot.com/-DGnsAevdVJw/TxKEzdTAY-I/AAAAAAAACm0/cAwzCGGwM1U/s72-c/Grid%2BAlternet%2Bedit.jpg" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5675857384776247981</guid><pubDate>Wed, 18 Jan 2012 18:59:00 +0000</pubDate><atom:updated>2012-01-22T09:32:36.258-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Exposing Custom event from custom control</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BkSfYN_fMziSHpOHxMp3nfw4Gi4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BkSfYN_fMziSHpOHxMp3nfw4Gi4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BkSfYN_fMziSHpOHxMp3nfw4Gi4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BkSfYN_fMziSHpOHxMp3nfw4Gi4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I m going to discuss about registering custom event in custom control. Recently In my project I have created user control it’s consist of one label control and dropdown box. This user control is common control which can be used in whole project to avoid writing repeated code for binding and also validation code for the same. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Ascx file i.e user control file&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="CommonDropDownControl.ascx.cs"
    Inherits="ValidDropDown" %&amp;gt;
&lt;div&gt;&lt;span id="spnRequired" runat="server"&gt;&lt;b class="contentframework-required-asterisk"&gt;*&lt;/b&gt;&lt;/span&gt;
    &lt;asp:label id="lblText" runat="server" wrap="false"&gt;&lt;/asp:label&gt;
     &lt;asp:dropdownlist id="ddlDropDown" onselectedindexchanged="ddlDropDown_SelectedIndexChanged" runat="server" width="137px"&gt;
                    &lt;/asp:dropdownlist&gt;
     &lt;asp:requiredfieldvalidator controltovalidate="ddlDropDown" enableclientscript="False" errormessage="Selection Invalid!" forecolor="#FF0000" id="valList" initialvalue="0" runat="server"&gt;
 
&lt;/asp:requiredfieldvalidator&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
Now as you can see in above code I have attached as requirefieldvalidator to validate the control which get fire when no value is selected by user. &lt;br /&gt;
But the important thing to note here is I have written &lt;i&gt;SelectedChange&lt;/i&gt; event with the dropdown control which I want to expose, so that I can write different code on each page where it utilize. Because the problem with the usercontrol is when I attached event with the any control that is part of usercontrol event get encapsulated in the code of that usercontrol and that's why we cannot able to write different code on each page where it is utilize and require to expose. &lt;br /&gt;
So in following code I will show how you can expose the change event and how you can utilize it on your page when using usercontrol.  &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 1 : Register event&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public event EventHandler DrpChange;
&lt;/pre&gt;&lt;br /&gt;
as you see in above code I have registered event of delegate type EventHandler and name of it is DrpChange. On the page I need to register DrpChange which get fire when user do change the selection in the dropdown box of the usercontrol. How I do this will so later on in this post.  &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 2 : Virtual function to handle raised event&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public virtual void OnDropDownChange()
    {
        if (DrpChange != null)
        {
            this.DrpChange(this, EventArgs.Empty);
        }
    }
&lt;/pre&gt;above code there is virtual function which handle the event raise from the page by the control. This function is responsible for calling the code written on page i.e event code written on the page.  &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 3 : Register on Change Event of dropdown in ASCX.CS file&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;protected void ddlDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.OnDropDownChange();
    }
&lt;/pre&gt;&lt;br /&gt;
above code written in OnChage event of the dropdown box in ASCX.Cs file so when use made selection and raise event it call this event and than custom register event. As you can see &lt;i&gt;OnDropDownChange&lt;/i&gt; is called from the event and in turn custom written code of the page. &lt;/div&gt;&lt;br /&gt;
In following step we are going to utilize created custom control and the custom event&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 4 : Use User control on page and utilize expose custom event .Aspx page&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Register src="Controls/CommonDropDownControl.ascx" 
   tagname="CommonDropDownControl" tagprefix="uc" %&amp;gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;form id="form1" runat="server"&gt;&lt;div&gt;&lt;uc1:commondropdowncontrol autopostback="true" drpchange="usrDrp_DrpChange" id="usrDrp" labletext="Country" runat="server"&gt;
    &lt;/uc1:commondropdowncontrol&gt;&lt;/div&gt;&lt;/form&gt;&lt;/pre&gt;&lt;br /&gt;
code register the event which is going to be fire when the selection in dropdown box of user control change. &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 5 : write code on page for the custom event .Aspx.CS file&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;protected void usrDrp_DrpChange(object sender, EventArgs e)
    {
        Response.Write("event called.");
    }
&lt;/pre&gt;so last there is code of register custom event which get executed on change of dropdwon box of user control. Note that this code is written on the page where I am utilizing the control.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For referance full code of ascx.cs file&lt;/b&gt;  &lt;pre class="brush: csharp"&gt;using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
 
////////////////////////////////////////////////////////////////////////////////////
//
//    File Description  :  Common Dropdown box control
// ---------------------------------------------------------------------------------
//    Date Created            : Month DD, YYYY (Dec 01, 2011)
//    Author                      : Pranay Rana
// ---------------------------------------------------------------------------------
//    Change History
//    Date Modified           : Month DD, YYYY (e.g Jan 01, 2000)
//    Changed By        :
//    Change Description   :
//
/////////////////////////////////////////////////////////////////////////////////
public partial class ValidDropDown : System.Web.UI.UserControl
{
    #region property
    public string LableText
    {
        get
        {
            return lblText.Text;
        }
        set
        {
            lblText.Text = value;
        }
    }
   
    public bool IsRequired
    {
        get
        {
            return spnRequired.Visible;
        }
        set
        {
             valList.Visible = value;
            spnRequired.Visible = value;
        }
    }
    public bool Enabled
    {
        get
        {
            return ddlDropDown.Enabled;
        }
        set
        {
            ddlDropDown.Enabled = value;
        }
    }
    public int Count
    {
        get
        {
            return ddlDropDown.Items.Count;
        }      
    }
    public bool Clear
    {
        set
        {
            if (value)
            {
                ddlDropDown.Items.Clear();
                ddlDropDown.Items.Add(new ListItem(UIConstants.SELECT, "0"));
            }
        }
    }
  
    public string SelectedValue
    {
        get
        {
 
            return ddlDropDown.SelectedValue;
 
        }
        set
        {
            ddlDropDown.ClearSelection();
            ListItem li = ddlDropDown.Items.FindByValue(value.ToString());
            if (li != null)
                li.Selected = true;
        }
    }
    public ListItem SelectedItem
    {
        get
        {
 
            return ddlDropDown.SelectedItem;
 
        }
        set
        {
            ddlDropDown.ClearSelection();
            ListItem li = ddlDropDown.Items.FindByText(value.ToString());
            if (li != null)
                li.Selected = true;
        }
    }
    public string SelectedText
    {
        get
        {
 
            return ddlDropDown.SelectedItem.Text;
 
        }
        set
        {
            ddlDropDown.ClearSelection();
            ListItem li = ddlDropDown.Items.FindByText(value.ToString());
            if (li != null)
                li.Selected = true;
        }
    }
    public int SelectedIndex
    {
        get
        {
 
            return ddlDropDown.SelectedIndex;
 
        }
        set
        {
            ddlDropDown.SelectedIndex = value;
        }
    }
  
    public bool AutoPostBack
    {
        get
        {
            return ddlDropDown.AutoPostBack;
        }
        set
        {
            ddlDropDown.AutoPostBack = value;
        }
    }
    #endregion property
 
    #region public methods
 
    /// &lt;summary&gt;
    /// Add Item to combo box
    /// &lt;/summary&gt;
    /// &lt;param name="pName"&gt;Name of the item&lt;/param&gt;/// &lt;param name="pValue"&gt;Value of the item&lt;/param&gt;public void AddItem(string pName, string pValue)
    {
        ddlDropDown.Items.Add(new ListItem(pName, pValue));
    }
 
 
    /// &lt;summary&gt;
    /// Bind List to combo box , i.e data soruce for the combo box
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;Type of list &lt;/typeparam&gt;
    /// &lt;param name="pLstItemInfo"&gt;List of Items to bind&lt;/param&gt;/// &lt;param name="pDataText"&gt;Name of the property display as text combo&lt;/param&gt;/// &lt;param name="pDataValue"&gt;Value Name of the property bind with the item&lt;/param&gt;public void BindList&lt;t&gt;(IList&lt;t&gt; pLstItemInfo, string pDataText, string pDataValue)
    {
 
        ddlDropDown.ClearSelection();
        ddlDropDown.Items.Clear();
        if (pLstItemInfo != null)
        {
            ddlDropDown.DataSource = pLstItemInfo;
            ddlDropDown.DataTextField = pDataText;
            ddlDropDown.DataValueField = pDataValue;
            ddlDropDown.DataBind();
        }
 
        ddlDropDown.Items.Insert(0, new ListItem(UIConstants.SELECT, "0"));
 
    }
 
    #endregion public methods
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (LableText == string.Empty)
                tdLabel.Visible = false;
            if(ddlDropDown.Items.Count == 0)
                ddlDropDown.Items.Add(new ListItem(UIConstants.SELECT, "0"));
        }
    }
 
 
    public event EventHandler DrpChange;
 
    public virtual void OnDropDownChange()
    {
        if (DrpChange != null)
        {
            // CustomArgs  e = new CustomArgs(this.ddlDropDown);
            this.DrpChange(this, EventArgs.Empty);
        }
    }
    protected void ddlDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.OnDropDownChange();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-5675857384776247981?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/01/exposing-custom-event-from-custom.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6397738696384814429</guid><pubDate>Mon, 16 Jan 2012 19:17:00 +0000</pubDate><atom:updated>2012-01-18T09:28:02.639-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">Ajax</category><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Calling Server Side function from Client Side Script</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/orDwcilOausitkScCyD2vR6rQoo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/orDwcilOausitkScCyD2vR6rQoo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/orDwcilOausitkScCyD2vR6rQoo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/orDwcilOausitkScCyD2vR6rQoo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
The post is about how you can call your code behind file function i.e server side written function from your client side code i.e using jQuery.&lt;br /&gt;
Recently I got requirement in my project that I have to check that ApplicationCode i.e Value entered by user is already available in database or not i.e unique value.&lt;br /&gt;
&lt;br /&gt;
Output of the will look like as below if record exists its shows error "Record exists" otherwise it doesn't display any record.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-OBXjN6N3wBk/TxWrNYVtTYI/AAAAAAAACm8/JwdELWfNarY/s1600/control+img.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="97" src="http://4.bp.blogspot.com/-OBXjN6N3wBk/TxWrNYVtTYI/AAAAAAAACm8/JwdELWfNarY/s320/control+img.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now in following post I am going to discuss about the what are the prerequisite need and why to use that.&amp;nbsp; 

&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Server Code&lt;/b&gt;
&lt;br /&gt;
Below method get called from the client side script, as you can see there are some changes in the method attribute, declaration and definition which I am going to discuss&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;    [WebMethod]
    public static string IsExists(string value)
    {
        //code to check uniqe value call to database to check this
        return "True";
    }
&lt;/pre&gt;
&lt;b&gt;WebMethod Attribute&lt;/b&gt;&lt;br /&gt;
Attached WebMethod attribute with Public method indicates that the method exposed as part of the XML Web service. The attribute tells .NET that a particular public method is exposed as a web-callable method. To make use of this attribute you need to make use of &lt;i&gt;System.Web.Services&lt;/i&gt; 
You can read about this attribute at : &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.aspx"&gt;WebMethodAttribute Class&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Static method&lt;/b&gt;&lt;br /&gt;
Static method is not associated with the instance of the class which get called by using only classname.methodname() i.e no need to create instance.&lt;br /&gt;
So that's why I marked method as static one. It cannot interact with the instance properties and methods of your Page class, because a page method call creates no instance of the Page or any of its controls.
Page methods are roughly equivalent to shorthand for standalone web services.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;.CS file &lt;/i&gt; &lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;//needed for the webmethod attribute
public

partial class _Default : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {
          if (!IsPostBack)
               txtData.Attributes.Add("onblur", "focuslost()");
     }

     [WebMethod]
     public static string IsExists(string value)
     {
          return "True";
     }
}
&lt;/pre&gt;
in above code I have registered client event with &lt;i&gt;onblur &lt;/i&gt;and attahced function &lt;i&gt;focuslost&lt;/i&gt;.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Client Code on .ASPX page code &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;jQuery .ajax() call&lt;/b&gt;&lt;br /&gt;
To called method from the client side code I made use of the jQuery function called ajax to get more details about this function you can read about my blog post : Jquery &lt;a href="http://pranayamr.blogspot.com/2011/07/jquery-ajax-calling-functions.html"&gt;Ajax Calling functions&lt;/a&gt; 

&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;function IsExists(pagePath, dataString, textboxid, errorlableid) {
 
$.ajax({
     type:"POST",
     url: pagePath,
     data: dataString,
     contentType:"application/json; charset=utf-8",
     dataType:"json",
     error:
          function(XMLHttpRequest, textStatus, errorThrown) {
               $(errorlableid).show();
               $(errorlableid).html("Error");
          },
     success:
          function(result) {
               var flg = true;
               if (result != null) {
                    flg = result.d;
                    if (flg == "True") {
                         $(errorlableid).show();
                    }
                    else {
                         $(errorlableid).hide();
                    }
          }
     }
    });
}
&lt;/pre&gt;
&lt;b&gt;In client script :&lt;/b&gt;&lt;br /&gt;
As I have to check code is exists or not I attached focusout() event with my textbox control, so when the focus get lost it make ajax call to the TextChanged event of code behind file.&lt;br /&gt;
&lt;i&gt;url &lt;/i&gt; - &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Contains path of the page which is get called from the client side code i.e from aspx page.&lt;br /&gt;
&lt;i&gt;data &lt;/i&gt;- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Data sent to server from the client it basically json string.&lt;br /&gt;
&lt;i&gt;contentType &lt;/i&gt;- Content type sent to server.&lt;br /&gt;
&lt;i&gt;dataType &lt;/i&gt;- &amp;nbsp; &amp;nbsp; &amp;nbsp;Expected data format from server&lt;br /&gt;
&lt;i&gt;error &lt;/i&gt;- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Called when call to server method fails&lt;br /&gt;
&lt;i&gt;success &lt;/i&gt;- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Called when call to server method is successes and return data from called method can be&amp;nbsp;processed in this method&lt;br /&gt;
&amp;nbsp;&lt;b&gt;&lt;i&gt;.Aspx page code&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Async="true" Inherits="_Default" %&amp;gt;



&lt;title&gt;&lt;/title&gt;
&lt;script src="JavaScript/jquery.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
function IsExists(pagePath, dataString, textboxid, errorlableid) {
 
$.ajax({
     type:"POST",
     url: pagePath,
     data: dataString,
     contentType:"application/json; charset=utf-8",
     dataType:"json",
     error:
          function(XMLHttpRequest, textStatus, errorThrown) {
               $(errorlableid).show();
               $(errorlableid).html("Error");
          },
     success:
          function(result) {
               var flg = true;
               if (result != null) {
                    flg = result.d;
                    if (flg == "True") {
                         $(errorlableid).show();
                    }
                    else {
                         $(errorlableid).hide();
                    }
          }
     }
    });
}
function focuslost() {
     var pagePath = window.location.pathname + "/IsExists";
     var dataString = "{ 'value':'" + $("#&lt;%= txtData.ClientID%&gt;").val() + "' }";
     var textboxid = "#&lt;%= txtData.ClientID%&gt;";
     var errorlableid = "#&lt;%= lblError.ClientID%&gt;";
     IsExists(pagePath, dataString, textboxid, errorlableid);
}
&lt;/script&gt;


     
          &lt;form id="form1" runat="server"&gt;
&lt;asp:label id="lbl" runat="server" text="Enter unique value : "&gt;&lt;/asp:label&gt;                                         
               &lt;asp:textbox id="txtData" runat="server"&gt;&lt;/asp:textbox&gt;
               &lt;br /&gt;
&lt;div id="lblError" runat="server" style="display: none;"&gt;
Record exsits&lt;/div&gt;
&lt;/form&gt;
&lt;/pre&gt;
as in above code &lt;i&gt;focuslost&lt;/i&gt; function get call &lt;i&gt;IsExists&lt;/i&gt; function which in-turn call the serverside function and inform the entered value is unique or not.
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6397738696384814429?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/01/calling-server-side-function-from.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://4.bp.blogspot.com/-OBXjN6N3wBk/TxWrNYVtTYI/AAAAAAAACm8/JwdELWfNarY/s72-c/control+img.jpg" height="72" width="72" /><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-287797599399218978</guid><pubDate>Fri, 30 Dec 2011 07:02:00 +0000</pubDate><atom:updated>2011-12-29T23:02:07.515-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Make your code Speak by using C# Region</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Hl0cAaaJ6GTZ-MtczHHMZkaZwsY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hl0cAaaJ6GTZ-MtczHHMZkaZwsY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Hl0cAaaJ6GTZ-MtczHHMZkaZwsY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hl0cAaaJ6GTZ-MtczHHMZkaZwsY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Post for the beginner developer or for the developer who want their code to speak and easy to&amp;nbsp;understand&amp;nbsp;to other developer who is going to maintain the code, review the code etc. &lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;To achive this thing most of the people talks about commenting class,method, property etc.but no one talks about the making region in the code which make code compact and easy to understand in form of regions. Region allow to block of the code which you can expand and minimize.&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Syntax to define the region in you code is &lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;pre class="brush: csharp"&gt;#region Properties
//your code
#endregion&amp;nbsp;Properties
&lt;/pre&gt;&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;So above code defines the region with name Properties. What ever code you write between between region and endregion get minimize and&amp;nbsp;expand&amp;nbsp;in visual studio you can see the + when minimize and - when maximize the code block.&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Example of the file with the region related to BAL or DAL layer of code &amp;nbsp;:&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" dir="ltr" style="clear: both; text-align: center;" trbidi="on"&gt;&lt;a href="http://3.bp.blogspot.com/-U3xXd7aOsZY/TvxJbfGIbVI/AAAAAAAACl8/R9c8jvqXq1c/s1600/Regiondiaplay.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="225px" rea="true" src="http://3.bp.blogspot.com/-U3xXd7aOsZY/TvxJbfGIbVI/AAAAAAAACl8/R9c8jvqXq1c/s640/Regiondiaplay.bmp" width="640px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Example of Aspx file i.e presentation layer file&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" dir="ltr" style="clear: both; text-align: center;" trbidi="on"&gt;&lt;a href="http://1.bp.blogspot.com/-Uz9aovNoE5I/Tv1V_B6hZQI/AAAAAAAACmI/5o-IgH4Sp64/s1600/regiondiaplaypage.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="196px" rea="true" src="http://1.bp.blogspot.com/-Uz9aovNoE5I/Tv1V_B6hZQI/AAAAAAAACmI/5o-IgH4Sp64/s640/regiondiaplaypage.bmp" width="640px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;strong&gt;Why to use Region in your code&lt;/strong&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;It allow to group the member which is related to same functionality&amp;nbsp;&lt;/li&gt;
&lt;ul&gt;&lt;li&gt;For Example in above code : Insert/Update method , Get Method&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;It to group Class members (private, public, methods, properties, etc.) , which you can easily see in above image&lt;/li&gt;
&lt;li&gt;With the help of region long code blocks can be minimize to small block, which you can expand when you want to see the code and minimize when work done with it.&lt;/li&gt;
&lt;/ul&gt;&lt;strong&gt;SortCut keys and&amp;nbsp; Context menu for&amp;nbsp;Region &lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Shortcut key for&amp;nbsp; region is (MSDN link for this : &lt;a href="http://msdn.microsoft.com/en-us/library/td6a5x4s.aspx"&gt;http://msdn.microsoft.com/en-us/library/td6a5x4s.aspx&lt;/a&gt;&amp;nbsp;)&lt;/li&gt;
&lt;ul&gt;&lt;li&gt;CTRL+M CTRL+M (that's two key presses!) - collapse/open the current parent region &lt;/li&gt;
&lt;li&gt;CTRL+M CTRL+L - Collapse/Open all regions in document recursively (meaning you might get only one line in the document - one big namespace region which is collapsed or you'll see the entire page code uncollapsed &lt;/li&gt;
&lt;li&gt;CTRL+M CTRL+O - Collapse all regions not recursively &lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;You can also make use of Context menu for that in you text editor&lt;/li&gt;
&lt;ul&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-cadxKBuCOxQ/Tv1dJfiBYUI/AAAAAAAACmU/60Sk_ByOG9c/s1600/toggle+the+block+of+region.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="351px" rea="true" src="http://4.bp.blogspot.com/-cadxKBuCOxQ/Tv1dJfiBYUI/AAAAAAAACmU/60Sk_ByOG9c/s400/toggle+the+block+of+region.bmp" width="400px" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;strong&gt;When not to use Region in your code &lt;/strong&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;To Hide 'ugly code' that is more complicated.&lt;/li&gt;
&lt;li&gt;To hide misc. code so that lazy reviewers don't look and ask about that part of code.&lt;/li&gt;
&lt;li&gt;Make region to hide the Commented code.&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-287797599399218978?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/12/make-your-code-speak-by-using-c-region.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-U3xXd7aOsZY/TvxJbfGIbVI/AAAAAAAACl8/R9c8jvqXq1c/s72-c/Regiondiaplay.bmp" height="72" width="72" /><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-8155573331619160942</guid><pubDate>Sat, 17 Dec 2011 18:32:00 +0000</pubDate><atom:updated>2011-12-17T10:32:16.934-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Sql Server</category><category domain="http://www.blogger.com/atom/ns#">OpenXML</category><category domain="http://www.blogger.com/atom/ns#">Bulk Insert</category><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Bulk Insertion of Data Using C# DataTable and SQL server OpenXML function</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/RhvcAJOUyuXS6AuOZpJ2c-8vSdI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RhvcAJOUyuXS6AuOZpJ2c-8vSdI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/RhvcAJOUyuXS6AuOZpJ2c-8vSdI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RhvcAJOUyuXS6AuOZpJ2c-8vSdI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to show how you can insert bulk data by using DataTable of C# and OpenXML function available in Sql Server.&lt;br /&gt;
&lt;br /&gt;
I got requirement that "Read data from the Excel file and than after validating data&lt;br /&gt;
push all record in the database table". Other thing is when inserting data in database if there is failure during insertion of record, I have to rollback all inserted record.&lt;br /&gt;
&lt;br /&gt;
To achieve the task I did as following &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;OpenXML&lt;/b&gt;&lt;br /&gt;
I created procedure which make use of OpenXML function of the sql server which allow to insert multiple record in one time. OpenXML require xml string of record to insert data in the database.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;ALTER PROCEDURE [dbo].[Ins_Employee]    
(    @XmlString text    )    
AS    
BEGIN    
 SET NOCOUNT ON    
 BEGIN TRANSACTION    
 Begin Try    

  DECLARE @XMLDocPointer INT    
  EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @XmlString    

   INSERT INTO Employee
   (Name, Email, PhoneNo)    
   SELECT Name,Email,PhoneNo   
   FROM OPENXML(@XMLDocPointer,'/ROOT/DATA',2)    
   WITH  (Name VARCHAR(50),-- '@Name',     
         Email VARCHAR(50),-- '@Email',     
         PhoneNo VARCHAR(50) --'@PhoneNo')     

   EXEC sp_xml_removedocument @XMLDocPointer    
   COMMIT TRANSACTION    
   Return 0;     
 End Try    
 Begin Catch    
   ROLLBACK TRANSACTION    
 End Catch    
END 
&lt;/pre&gt;As you see in above procedure OpenXML make use of xmlDocument as input which is get created by system define procedure sp_xml_preparedocument which take xmlString as input and return XmlDocument.&lt;br /&gt;
Once OpenXML done task of insertion sp_xml_removedocument system proceudre is require to remove that element.&lt;br /&gt;
All record get inserted in once by the OpenXML function as I used transaction if the one record insertion fails all inserted record get rollback.&lt;br /&gt;
&lt;br /&gt;
Following line of the code used to execute code i.e stored procedure&lt;br /&gt;
As you see in I am passing Element centric xml to the proceudre.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Exec Ins_Employee
 '&lt;root&gt;
  &lt;data&gt;
    &lt;name&gt;pranay&lt;/name&gt;
    &lt;email&gt;pranayamr@gmail.com&lt;/email&gt;
    &lt;phoneno&gt;99007007&lt;/phoneno&gt;
  &lt;/data&gt;
 '
&lt;/root&gt;&lt;/pre&gt;&lt;b&gt;Note&lt;/b&gt;&lt;br /&gt;
If you are passing XML string as Attribute centric in it as in procedure than you need to  define variable so the select statement in procedure will be &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;SELECT Name,Email,PhoneNo   
   FROM OPENXML(@XMLDocPointer,'/ROOT/DATA',2)    
   WITH  (Name VARCHAR(50) '@Name',     
         Email VARCHAR(50) '@Email',     
         PhoneNo VARCHAR(50) '@PhoneNo')
&lt;/pre&gt;&lt;pre class="brush: csharp"&gt;Exec Ins_Employee
  '&lt;root&gt;     
   &lt;data email="pranayamr@gmail.com" name="pranay" phoneno="99007007"&gt;    
  &lt;/data&gt;&lt;/root&gt;'
&lt;/pre&gt;&lt;br /&gt;
Now after done with the database , code part of the application is as below.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Uploaded Excel File which contains Employee data&lt;/b&gt; &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-SFk3Lard1aA/Tuze99qvJHI/AAAAAAAACls/dEsx2fIiVFc/s1600/execel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="231" src="http://3.bp.blogspot.com/-SFk3Lard1aA/Tuze99qvJHI/AAAAAAAACls/dEsx2fIiVFc/s320/execel.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Presentation layer&lt;/b&gt;&lt;br /&gt;
Following function in presentation layer read data from the excel file, which is uploaded on server. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void ReadAndInsertExcelData()
{
     int i;
     bool blValid = true;
     OleDbCommand ocmd;
     OleDbDataAdapter oda;
     DataTable dtDetails;
     DataSet dsDetails;

     OleDbConnection oconn = new OleDbConnection     
          (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + 
               Server.MapPath("~/Upload/MonthlyActual.xls") + ";Extended 
               Properties='Excel 8.0;HDR=YES;IMEX=1'");
     try
     {
          ocmd = new OleDbCommand("select * from [Sheet1$]", oconn);
          oda = new OleDbDataAdapter(ocmd);
          dsDetails = new DataSet();
          oda.Fill(dsDetails, "DATA");
          dtDetails = dsDetails.Tables[0];
          dsDetails.DataSetName = "ROOT";
          i = 0;

          DataRow[] drLst = dtDetails.Select("(Name is null) or (Email is 
                              null) or (PhoneNo is null)");
          if (drLst.Count() &amp;gt; 0)
               blValid = false;
          if (blValid)
          {
               XMLController xMLController = new XMLController();
               xMLController.Ins(BaseLineType, dtDetails);
          }
     }
     catch 
     {
          lblMsg.Text = ex.Message;
          lblMsg.ForeColor = System.Drawing.Color.Red;
     }
     finally
     {
          lblMsg.Text = "Data Inserted Sucessfully";
          oda = null;
          dtDetails = null;
          dsDetails = null;
     }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Business Layer&lt;/b&gt;&lt;br /&gt;
Function below takes DataTable as input and generate XML string, As you see below I used StringWriter which use StringBuilder object, DataTable make use of StringWriter and write XML string in StringBuilder object.   &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public int Ins(DataTable pImportTable)
{
     int IsSuccess = -100;
     try
     {
          StringBuilder sbXMLString = new StringBuilder();
          System.IO.StringWriter sw = new System.IO.StringWriter
                                                  (sbXMLString);
          pImportTable.WriteXml(sw);

          DALXML dALManualCost = new DALXML();
          dALManualCost.Ins(sbXMLString.ToString());
          IsSuccess = dALManualCost.IsSuccess;
     }
     catch
     {
          throw;
     }
     return IsSuccess;
}
&lt;/pre&gt;&lt;b&gt;Note:&lt;/b&gt;Above method generate Element centric XML string.&lt;br /&gt;
&lt;br /&gt;
Now if you want to write out the Attribute centric xml file you just need to replace the line of datatable.WriteXml with the below code for loop also you dont require to use the StringWriter object.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;sbXMLString.Append("&lt;root&gt;");
          for (int i = 0; i &amp;lt; pImportTable.Rows.Count; i++)
          {
            sbXMLString.Append("&amp;lt;DATA ");
            sbXMLString.Append("Name='" + 
                         pImportTable.Rows[i][0].ToString().Trim() + "' ");
            sbXMLString.Append("Email='" + pImportTable.Rows
                         [i][1].ToString().Trim() + "' ");
            sbXMLString.Append("PhoneNo='" + 
                         pImportTable.Rows[i][2].ToString().Trim() + "' ");
            
            sbXMLString.Append(" /&amp;gt;");
 
          }
          sbXMLString.Append("&lt;/root&gt;");
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;DataLayer&lt;/b&gt;&amp;nbsp; &lt;br /&gt;
Now this layer call the stored procedure which pass the xmlstring of employee to database. Return parameter will tell that its successfull insert or not.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public void Ins(string pXMLString)
{
     try
     {
          Database db = CommonHelper.GetDataBaseInstance();
          DbCommand cmdXML = db.GetStoredProcCommand
                         (SP_INSERT_STAGINGMANUALCOSTMONTHLY);

          db.AddInParameter(cmdXML, "XmlString", DbType.String, 
                                                       pXMLString);
          db.AddParameter(cmdXML, "ret", DbType.Int32,                     
          ParameterDirection.ReturnValue, "", DataRowVersion.Current, 
                                                            IsSuccess);

          db.ExecuteNonQuery(cmdXML);
          IsSuccess = Convert.ToInt32(db.GetParameterValue(cmdXML, "ret"));
     }
     catch
     {
          IsSuccess = -100;
          throw;
     }
}
&lt;/pre&gt;&lt;br /&gt;
Note : This is the one technique I found useful to enter bulk amount of data in database in one transaction. There are also other available which might be more efficient than this.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-8155573331619160942?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/12/bulk-insertion-of-data-using-c.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-SFk3Lard1aA/Tuze99qvJHI/AAAAAAAACls/dEsx2fIiVFc/s72-c/execel.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5532399729696922323</guid><pubDate>Sun, 04 Dec 2011 13:16:00 +0000</pubDate><atom:updated>2011-12-04T05:16:58.872-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JAVA SCRIPT / JQUERY</category><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Month and Year Picker UserControl</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MLEMb_56oSJiSBSWgDvzs3lsSEM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MLEMb_56oSJiSBSWgDvzs3lsSEM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MLEMb_56oSJiSBSWgDvzs3lsSEM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MLEMb_56oSJiSBSWgDvzs3lsSEM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I am going to discuss about the pop-Up calender control created by me for selecting Month and Year. By this post you will get to know how to easily you can create pop-Up window using jQuery as well as little about how to use it as Asp.Net user control. Well that's not it you can also utilize this thing in you web project develop in any other language.&lt;br /&gt;
&lt;br /&gt;
Below is the picture of the control &lt;br /&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-hC5hXav3nS8/Tts47OPLmsI/AAAAAAAACkc/amjGbDySMEM/s1600/DateControl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="49" src="http://1.bp.blogspot.com/-hC5hXav3nS8/Tts47OPLmsI/AAAAAAAACkc/amjGbDySMEM/s400/DateControl.png" width="294" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-C7fJ4mBrGCA/Tts4_s77HAI/AAAAAAAACko/OMk5rh_y6JE/s1600/DateSelect.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="66" src="http://3.bp.blogspot.com/-C7fJ4mBrGCA/Tts4_s77HAI/AAAAAAAACko/OMk5rh_y6JE/s400/DateSelect.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now following is step by step Explanation of control created and how to use that control in your application. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1 : Control Design i.e ASCX file&lt;/b&gt; &lt;br /&gt;
To create user control you need to left click on the solution and click on Add New Item &amp;gt;&amp;gt; than in screen select WebUserControl as below &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-kIrf8qf6_p8/TttNk9KfnKI/AAAAAAAACk0/Ve3GaEo2-o0/s1600/control%2Bcreation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-kIrf8qf6_p8/TttNk9KfnKI/AAAAAAAACk0/Ve3GaEo2-o0/s400/control%2Bcreation.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
After you click on Add button one ASCX file is get created , than you can add the following line of code to get display as show in the fist image above  &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="DateBox.ascx.cs" Inherits="DateBox" %&amp;gt;

&lt;div id="labelContainer" runat="server" style="float: left;"&gt;&lt;asp:label id="lblText" runat="server"&gt;&lt;/asp:label&gt;
&lt;/div&gt;&lt;div&gt;&lt;asp:textbox id="txtDate" runat="server"&gt;&lt;/asp:textbox&gt;
  &lt;asp:button id="btnDate" runat="server" text="..."&gt;
&lt;/asp:button&gt;&lt;/div&gt;&lt;/pre&gt;lblText : - Label to hold the text to display with the text box.&lt;br /&gt;
txtDate : - TextBox to hold the text get selected by user from the pop-Up calender window shown in the second image above. &lt;br /&gt;
btnDate : - Button control, when get clicked it display the pop-Up calender window.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2 : Control Code-Behind i.e .CS file&lt;/b&gt;&lt;br /&gt;
Once you done with the control design you can paste the following code in the codebehind i.e. .cs file &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public partial class DateBox : System.Web.UI.UserControl
{
    public string LabelText
    {
        get
        {
            return lblText.Text;
        }
        set
        {
            lblText.Text = value;
        }
    }

    public string TextData
    {
        get
        {
            return txtDate.Text;
        }
        set
        {
            txtDate.Text = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (lblText.Text == string.Empty)
                labelContainer.Visible = false;

            this.btnDate.Attributes.Add("OnClick", "return buttonClick(this,'"+ txtDate.ClientID +"');");
        }
    }
}
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Property&lt;/b&gt;&lt;/i&gt; &lt;br /&gt;
LabelText : - Used to get/set the text for the label control.&lt;br /&gt;
TextData  : - Used to get/set the text of the textbox conrol which is going to display selected date.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Method&amp;nbsp;&lt;/b&gt;&lt;/i&gt; &lt;br /&gt;
Page_Load : - method get executed when page load check, if the label control don't have text make the container div set to visible off. Adding client script on button control and passing button control itself and textbox control client id which going to use by the jQuery/javascript to display selected date. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 3 : Code to create popUp Calender i.e. .JS file&lt;/b&gt;&lt;br /&gt;
After you done with Stpe 2, Add new javascript file to your solution and paste the following code in it &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;jQuery(document).ready(function ($) {

    var divContainer = $("&lt;div id="window" style="display: none;"&gt;&lt;/div&gt;");

    var divButtonHolder = $("&lt;div id="bholder" style="padding-top: 5px; text-align: center;"&gt;&lt;/div&gt;");
    var buttonOk = $("&lt;div style="float: left;"&gt;&lt;input id="buttonDone" onclick="buttonDoneClick()" type="button" value="Done" /&gt;&lt;/div&gt;");
    var buttonCancel = $("&lt;div style="float: right;"&gt;&lt;input id="buttonCancel" onclick="Close_Popup()" type="button" value="Cancel" /&gt;&lt;/div&gt;");

    var divSelectHolder = $("&lt;div id="holder"&gt;Select Month and Year :&amp;nbsp; &lt;/div&gt;");
    var ddlmonth = $("&lt;select cellspacing="0" id="ddlmonth"&gt; &lt;/select&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;");
    var ddlyear = $("&lt;select cellspacing="0" id="ddlyear"&gt; &lt;/select&gt;");
    var i = 0;
    var month = 1;

    for (i = 1985; i &amp;lt;= 2020; i++) {
        ddlyear.append('&lt;option value="' + i + '"&gt;' + i + '&lt;/option&gt;');
    }

    i = 0;
    for (i = 1; i &amp;lt;= 12; i++) {
        if (i &amp;lt; 10) {
            month = "0" + month;
        }
        ddlmonth.append('&lt;option value="' + month + '"&gt;' + month + '&lt;/option&gt;');
        month++;
    }

    divSelectHolder.append(ddlmonth);
    divSelectHolder.append(ddlyear);
    divContainer.append(divSelectHolder);

    divButtonHolder.append(buttonOk);
    divButtonHolder.append(buttonCancel);
    divContainer.append(divButtonHolder);
    $('body').append(divContainer);
});


var txtDate;
function buttonDoneClick() {
    var month = $("#ddlmonth").val();
    var year = $("#ddlyear").val();

    $(txtDate).val(month + year);
    Close_Popup() 
}

function buttonClick(obj,id) {

    txtDate = ('#' + id);
    var position = $(obj).position();

    $('#window').css({ top: position.top, left: position.left }).fadeIn('fast');
    return false;
}

function Close_Popup() {
    $('#window').fadeOut('fast');
}
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Variables&lt;/b&gt;&lt;/i&gt; &lt;br /&gt;
divContainer : - Main container which contains all controls of pop-Up.&lt;br /&gt;
divButtonHolder : - Hold button controls of the window i.e Done and Cancel.&lt;br /&gt;
buttonOk : - Hold reference of button control called Done.&lt;br /&gt;
buttonCancel : - Hold reference of button control called Cancel.&lt;br /&gt;
divSelectHolder : - Hold Select control i.e Month and Year combo.&lt;br /&gt;
ddlmonth : - Hold reference of select control called Month.&lt;br /&gt;
ddlmonth : - Hold reference of select control called Month.&lt;br /&gt;
ddlyear : - Hold reference of select control called Year.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;jQuery method &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
.append : - allows to append control to the control selected by filter.&lt;br /&gt;
.ready : - method contains the code for initialize the variable, add the option to select control and attach all created control to body of the page.&lt;br /&gt;
.position : - method to get the location of the control which selected by selector.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Method&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
buttonDoneClick : - Get the selected value of the Month and Year combo box and display text in the textbox attached with the calender control.&lt;br /&gt;
buttonClick : - Display calender popUp window , the method make use of position method of jquery to get the location of button and assign it to popUp window.&lt;br /&gt;
Close_Popup : - To close the popUp window called when the Cancel button of the popUp window clicked.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 4 : popUp window Style sheet i.e .Css file &lt;/b&gt;&lt;br /&gt;
Add following style shit to Css file which you can able to add from the solution.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;#window {
margin: 0 auto;
border: 1px solid #000000;
background: #ffffff;
position: absolute;
left: 25%;
width:250px;
height:50px;
padding:5px;
}
&lt;/pre&gt;Style is get attached with the the div which is having id called window i.e the popUp window.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 5 : How to use control in your project ASPX file &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Register  Src="~/DateBox.ascx" TagPrefix="UC" TagName="DateBox"   %&amp;gt;
&lt;script src="JavaScript/jquery.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="JavaScript/DateBox.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;uc:datebox id="DateBox" labeltext="Select period : " runat="server"&gt;
&lt;/uc:datebox&gt;&lt;/pre&gt;&lt;/div&gt;So to use control in your application you just need to register the user control, need to include jquery, created js and css file. And you can make use of Lable property to display text with control.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
So its quite easy to create popUp control and use it as User Control in your application. But if you are working on other than .net than just you need to use .Js and .Css file and need to create control on your page.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-5532399729696922323?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/12/month-and-year-picker-usercontrol.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-hC5hXav3nS8/Tts47OPLmsI/AAAAAAAACkc/amjGbDySMEM/s72-c/DateControl.png" height="72" width="72" /><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-1305973664066931130</guid><pubDate>Mon, 07 Nov 2011 16:44:00 +0000</pubDate><atom:updated>2011-11-07T08:44:23.779-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ajax</category><title>AJAX presentation</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S57T9_flkXIkaBRw0rgm3KbgM2Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S57T9_flkXIkaBRw0rgm3KbgM2Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S57T9_flkXIkaBRw0rgm3KbgM2Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S57T9_flkXIkaBRw0rgm3KbgM2Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="width:425px" id="__ss_10059120"&gt;&lt;strong style="display:block;margin:12px 0 4px"&gt;&lt;a href="http://www.slideshare.net/pranayamr/ajax-10059120" title="Ajax" target="_blank"&gt;Ajax&lt;/a&gt;&lt;/strong&gt; &lt;iframe src="http://www.slideshare.net/slideshow/embed_code/10059120" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"&gt;&lt;/iframe&gt; &lt;div style="padding:5px 0 12px"&gt;View more &lt;a href="http://www.slideshare.net/" target="_blank"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/pranayamr" target="_blank"&gt;Pranay Rana&lt;/a&gt; &lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-1305973664066931130?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/11/ajax-presentation.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5488091181953417623</guid><pubDate>Mon, 24 Oct 2011 19:17:00 +0000</pubDate><atom:updated>2011-10-24T12:19:17.628-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>DataLoadOptions  and How to use in Compiled Linq query</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uA7zp31_N4PhJz4ejaTNsM6wYpA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uA7zp31_N4PhJz4ejaTNsM6wYpA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uA7zp31_N4PhJz4ejaTNsM6wYpA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uA7zp31_N4PhJz4ejaTNsM6wYpA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;DataLoadOption in LINQ allows immediate loading and filtering of related data. The DataLoadOption allow to load related object so this remove need of the firing subquery every time you ask for the related object(s).&lt;br /&gt;
&lt;br /&gt;
Consider below case  &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-l4S4dkAiFTQ/TqWsVjl9pJI/AAAAAAAACj8/wXJosjQnUjc/s1600/relation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="226" src="http://3.bp.blogspot.com/-l4S4dkAiFTQ/TqWsVjl9pJI/AAAAAAAACj8/wXJosjQnUjc/s400/relation.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
If you do code like this &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var distlist = (from d in edb.Distributors select d).ToList();
            foreach(Distributor d in distlist)
            {
              var clientlist = d.Customers;
              foreach( Customer c in clientlist)
              {
                   //do the code 
              }
            }
&lt;/pre&gt;each time inner for loop fire query on database to get the customer related to distributor which in  turn decrease the performance. But if you know in advance that you are need to use the related list when you are loading main list i.e you need to load data of related entity eagerly make use of DataLoadOptions.&lt;br /&gt;
&lt;br /&gt;
Modified code is something like &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith&amp;lt;Distributorgt;(d =&amp;gt; d.Customers);
dataContext.LoadOptions = dlo;
&lt;/pre&gt;&lt;b&gt;Note&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Be careful when you use DataLoadOption because it may decrease the performance if you are not going to use related objects. Use only in situation when you want to load related object early and going to consume it all.   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;You an only attach DataLoadOption once with the instance of datacontext.&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
The above DataLoadOption runs perfectly when you use regular Linq Queries. But it does not work with compiled queries. When you run this code and the query hits the second time, it produces an exception:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;DataLoadOptions in Complied queries&lt;/b&gt;&lt;br /&gt;
First to get more info about Complied look this post : &lt;a href="http://pranayamr.blogspot.com/2011/10/increase-linq-query-perfromance-by.html"&gt;Increase Linq query performance by Compling it&lt;/a&gt;&lt;br /&gt;
Now when you attache DataLoadOption to complied query as we did above it give you an exception at run-time&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Compiled queries across DataContexts with different LoadOptions not supported&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
To avoid the exception you need to create the static DataLoadOption variable because as the compiled linq queries are the static one it not consume the DataLoadOption which is not static.&lt;br /&gt;
&lt;br /&gt;
So for that I have created below code where GetDataLoadOpt() static function returns DataLoadOptions object and I store it into static variable dlo and than attach this dlo1 with the compiled version of query.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static DataLoadOptions dlo1 = GetDataLoadOpt();

    public static Func&amp;lt;DataLoadTestDataContext, string, IQueryable&amp;lt;Product&amp;gt;&amp;gt;
        ProductByCategory =
        CompiledQuery.Compile((DataLoadTestDataContext db, string category) =&amp;gt;
        from p in db.Products where p.Category == category select p);

    public static DataLoadOptions GetDataLoadOpt()
    {
        DataLoadOptions dlo = new DataLoadOptions();
        dlo.LoadWith&amp;lt;Product&amp;gt;(p =&amp;gt; p.ProductWithCategory);
        return dlo;
    }

    public static void testfunction()
    {
        DataLoadTestDataContext context = new DataLoadTestDataContext();
        context.LoadOptions = dlo1;
        var productlist = ProductByCategory(context, "mobile");

        foreach (Product p in productlist)
        {
            Console.WriteLine(p.ProductWithCategory);
        }
    }
&lt;/pre&gt;&lt;/div&gt;If you want to get the above exception try code removing static from the function v and variable dlo1 than assign it to compiled version of query you will get the run-time exception.&lt;br /&gt;
&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-5488091181953417623?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/10/dataloadoptions-and-how-to-use-in.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-l4S4dkAiFTQ/TqWsVjl9pJI/AAAAAAAACj8/wXJosjQnUjc/s72-c/relation.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5951992368342345685</guid><pubDate>Mon, 17 Oct 2011 19:20:00 +0000</pubDate><atom:updated>2011-10-24T11:59:09.588-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Increase Linq query performance by Compling it</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XEbPYgwR0mkBCKB3TYzdCmGK5wA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XEbPYgwR0mkBCKB3TYzdCmGK5wA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XEbPYgwR0mkBCKB3TYzdCmGK5wA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XEbPYgwR0mkBCKB3TYzdCmGK5wA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Each time when we fire any Linq to SQL or to any other data-source using Entity Framework query run-time convert query to expression tree and than into t-SQL statement. So if the query get fired number of time in application it get converted in the expression tree to t-SQL statement by run-time this conversion increase execution time which in turn affect performance of the application. To avoid this cost Microsoft .net framework introduce concept of the complied queries which allows compilation and caching of queries for reuse.&lt;br /&gt;
&lt;br /&gt;
Now, there is shopping website which list of the product by the category basically it allows filtering of product by the category. So if I have 100 no of user who logged in to system and do the filter the product by category they basically fire &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;from p in db.Products where p.Category == category select p
&lt;/pre&gt;query to get the result they want. So this will increase the execution cost as this query get fire no of time and get converted in the expression tree and in turn get the result.&lt;br /&gt;
&lt;br /&gt;
With the help of &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.linq.compiledquery.aspx"&gt;CompiledQuery&lt;/a&gt; class of .net framework I can rewrite my code and it's like as below&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static Func&amp;lt;DataLoadTestDataContext, string, IQueryable&amp;lt;Product&amp;gt;&amp;gt;
  ProductByCategory =
    CompiledQuery.Compile((DataLoadTestDataContext db, string category) =&amp;gt;
     from p in db.Products where p.Category == category select p);
&lt;/pre&gt;&lt;b&gt;Static Variable&lt;/b&gt;&lt;br /&gt;
Static variable is used to store the so its not thread safe and global to all. Because of static variable compilation will only occur once per AppDomain and will remain cached through the rest of the application's lifetime. If you don't use the static variable query get complied each time which increase the cost and decrease the performance of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Constrain and Use&lt;/b&gt;&lt;br /&gt;
Cannot use to store the queries which returns Anonymous type, because the anonymous type doesn't have any type to assign generic argument of function.&lt;br /&gt;
&lt;br /&gt;
Useful when query is used heavily and you want to reuse the query, by using this way increase the performance of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Where to include the code ?&lt;/b&gt;&lt;br /&gt;
Better place to include above code is partial class, its extended partial class to the partial class generated by ORM tool.&lt;a href="http://pranayamr.blogspot.com/2011/10/extenend-linq-to-sql-generated-class.html"&gt;More:Extenend ORM generated class&lt;/a&gt;&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-5951992368342345685?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/10/increase-linq-query-perfromance-by.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-1777276809008006193</guid><pubDate>Tue, 11 Oct 2011 17:12:00 +0000</pubDate><atom:updated>2011-10-15T00:24:25.639-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Extenend ORM generated class</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qfeDbq-AeQA6mzz_5honi3IZ-kc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qfeDbq-AeQA6mzz_5honi3IZ-kc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qfeDbq-AeQA6mzz_5honi3IZ-kc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qfeDbq-AeQA6mzz_5honi3IZ-kc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to show how you can extend the class generated by the ORM tools. To demonstrate I am using Linq To Sql ORM.&lt;br /&gt;
&lt;br /&gt;
When you make use of ORM tool like Linq to Sql or Entity-Framework it generate the classes from the database structure given as input. For example consider below example&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-pUxrn_sem4c/TpRupuAWVfI/AAAAAAAACjs/nqZppCERfws/s1600/product.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="167" src="http://3.bp.blogspot.com/-pUxrn_sem4c/TpRupuAWVfI/AAAAAAAACjs/nqZppCERfws/s400/product.png" width="206" /&gt;&lt;/a&gt;&lt;/div&gt;Now I want to display the list of product in my grid but I have to display product name with &lt;i&gt;categoryname&lt;/i&gt; for example &lt;i&gt;productname(categoryname)&lt;/i&gt; or consider situation where I have ordertable and I have to display one more extra column in grid with display &lt;i&gt;total = quantity * price&lt;/i&gt;.   &lt;br /&gt;
&lt;br /&gt;
To achieve this make look to the class generated by ORM tools, when you see the class definition you see its decorated with the partial keyword. C#2.0 partial class allow us to create class which expands in two different file and at the time of compile both file get compile in one class. So by making use of same rule I have added one more class file and its partial as below.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public partial class Product
{
   public string ProductWithCategory
   {
      get
      {
         return this.ProductName + "(" + this.Category +")";
      }
   }
}
&lt;/pre&gt;Now to we can consume property in the presentation or businesslayer like as below.   &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var productlist = (from p in context.Products select p).ToList();
foreach (Product p in productlist)
{
   Console.WriteLine(p.ProductWithCategory);
}
&lt;/pre&gt;So by above way adding property to partial class we can easily achieve the task.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
By using partial class we can add the custom logic to the class created by the ORM tool(s).&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-1777276809008006193?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/10/extenend-linq-to-sql-generated-class.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-pUxrn_sem4c/TpRupuAWVfI/AAAAAAAACjs/nqZppCERfws/s72-c/product.png" height="72" width="72" /><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-260961976361769046</guid><pubDate>Mon, 03 Oct 2011 19:15:00 +0000</pubDate><atom:updated>2011-10-15T00:26:18.832-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Log your LINQ query</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/eofFkbYnU13_KxYN7glQzfwb_3A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eofFkbYnU13_KxYN7glQzfwb_3A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/eofFkbYnU13_KxYN7glQzfwb_3A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eofFkbYnU13_KxYN7glQzfwb_3A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
Most of the beginner developer who are using LINQ to SQL as there back-end to talk with the database (i.e to perform the database CRUD operation), don't have idea what the query get fire to database out of LINQ query.  &lt;br /&gt;
&lt;br /&gt;
Lastly I asked to log the query that fire to database out of my LINQ query. So as solution I found one make use of SQL Server Profiler to check fire query. But with the profiler I can not able to log the queries.&lt;br /&gt;
&lt;br /&gt;
I fond one solution is to make use of &lt;i&gt;Log&lt;/i&gt; property of DataContext object. &lt;i&gt;Log&lt;/i&gt; property allow me to log the queries in the file. Consider the below code  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//created temp file 
using 
(System.IO.StreamWriter sw = new System.IO.StreamWriter(@"e:\tempdatacontext.log"))
{
    EmployeeDataContext edb = new EmployeeDataContext();
    //assigned streamwriter to the log property of datacontext
    edb.Log = sw;
    var cust = from c in edb.Customers
              join d in edb.Distributors on
                new { CityID = c.CityId, StateID = c.StateId, 
                      CountryID = c.CountryId, Id = c.DistributorId }
                equals
                new { CityID = d.CityId, StateID = d.StateId, 
                      CountryID = d.CountryId, Id = d.DistributorId }
              select c;

    List&amp;lt;customer&amp;gt; custList = cust.ToList();
}
&lt;/pre&gt;&lt;br /&gt;
So once the code get executed it's time to check the temp file. As I opened up the file I found following query get fired on my database.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-U57n339w8TU/TohrdjZ4JWI/AAAAAAAACjI/gtydwHp8yLY/s1600/queryfile.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="168" src="http://3.bp.blogspot.com/-U57n339w8TU/TohrdjZ4JWI/AAAAAAAACjI/gtydwHp8yLY/s640/queryfile.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
It's fun to find the query get fire to database and you get to know if there is any problem in the LINQ query you wrote. &lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-260961976361769046?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/10/log-your-linq-query.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-U57n339w8TU/TohrdjZ4JWI/AAAAAAAACjI/gtydwHp8yLY/s72-c/queryfile.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6519227364031236490</guid><pubDate>Sat, 01 Oct 2011 21:12:00 +0000</pubDate><atom:updated>2011-10-01T14:27:39.370-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Linq Join on Mutiple columns using Anonymous type</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/X4g9xXF4rsuG7-pkqfFKMxjQqp0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/X4g9xXF4rsuG7-pkqfFKMxjQqp0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/X4g9xXF4rsuG7-pkqfFKMxjQqp0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/X4g9xXF4rsuG7-pkqfFKMxjQqp0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was working on the project using LINQ. I got the requirement to join the two entity on multiple column. &lt;br /&gt;
&lt;br /&gt;
For example consider the following image. There are two entity Distributor and Customer related to each other. &lt;br /&gt;
&lt;br /&gt;
Now I want to find out all customer who lives in same city where the distributor living.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-cK4RKSZCFbQ/TodvBfcOZaI/AAAAAAAACjE/zVBpczJRDj8/s1600/mutiple%2Bcolumns.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="219" src="http://1.bp.blogspot.com/-cK4RKSZCFbQ/TodvBfcOZaI/AAAAAAAACjE/zVBpczJRDj8/s400/mutiple%2Bcolumns.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;So to find out that I have to make join between Customer and Distributor. And to achieve this I need to join by using multiple columns City,State,Country,ID. (Note: I am using id in join because later on I want to get which distributor near to customer).&lt;br /&gt;
&lt;br /&gt;
Now with the LINQ you can join two entity on multiple columns by creating one anonymous type.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;EmployeeDataContext edb= new EmployeeDataContext();
var cust = from c in edb.Customers
           join d in edb.Distributors on
             new { CityID = c.CityId, StateID = c.StateId, CountryID = c.CountryId, 
                   Id = c.DistributorId }    
           equals
             new { CityID = d.CityId, StateID = d.StateId, CountryID = d.CountryId, 
                   Id = d.DistributorId }    
           select c;
&lt;/pre&gt;&lt;b&gt;Note : &lt;/b&gt;As anonymous types used to join entity on multiple column, so for that make sure that both are equal and they must have the same properties in same order. Otherwise it don't get complied and you get error.&lt;br /&gt;
&lt;br /&gt;
Once you are done run the code and you see the following query in your sql profiler or you can also use the visual studio feature to get the query. &lt;br /&gt;
&lt;pre class="brush: sql"&gt;SELECT [t0].[Id], [t0].[Name], [t0].[EmailId], [t0].[CityId], [t0].[StateId], 
[t0].[CountryId], [t0].[PinCode], [t0].[DistributorId]
FROM [dbo].[Customer] AS [t0]
INNER JOIN 
[dbo].[Distributor] AS [t1] ON 
([t0].[CityId] = [t1].[CityId]) 
    AND ([t0].[StateId] = [t1].[StateId]) 
    AND  ([t0].[CountryId] = [t1].[CountryId]) 
    AND ([t0].[DistributorId] =[t1].[DistributorId])
&lt;/pre&gt;&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6519227364031236490?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/10/linq-join-on-mutiple-columns-using.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-cK4RKSZCFbQ/TodvBfcOZaI/AAAAAAAACjE/zVBpczJRDj8/s72-c/mutiple%2Bcolumns.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3882241243998760449</guid><pubDate>Sat, 03 Sep 2011 07:45:00 +0000</pubDate><atom:updated>2011-09-03T00:48:07.946-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Certificate</category><title>My MVB Certificate</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0RQ6-Q71BNy6pM9sXTVsguy8yKU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0RQ6-Q71BNy6pM9sXTVsguy8yKU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0RQ6-Q71BNy6pM9sXTVsguy8yKU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0RQ6-Q71BNy6pM9sXTVsguy8yKU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-j06322H6Sh8/TmHazGMlIeI/AAAAAAAACds/xgdZaieCt80/s1600/MVB%2Bcertificate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="480" src="http://1.bp.blogspot.com/-j06322H6Sh8/TmHazGMlIeI/AAAAAAAACds/xgdZaieCt80/s640/MVB%2Bcertificate.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-3882241243998760449?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/09/my-mvb-certicate.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-j06322H6Sh8/TmHazGMlIeI/AAAAAAAACds/xgdZaieCt80/s72-c/MVB%2Bcertificate.jpg" height="72" width="72" /><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-116582366523705542</guid><pubDate>Thu, 11 Aug 2011 18:39:00 +0000</pubDate><atom:updated>2011-08-11T11:42:49.299-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SilverLight</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">Business Application</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Entity Framework</category><title>Build your silver light application</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cUnuDrCrMi_am_OAwH35fxPNLck/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cUnuDrCrMi_am_OAwH35fxPNLck/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cUnuDrCrMi_am_OAwH35fxPNLck/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cUnuDrCrMi_am_OAwH35fxPNLck/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="width:425px" id="__ss_8830044"&gt;&lt;strong style="display:block;margin:12px 0 4px"&gt;&lt;a href="http://www.slideshare.net/pranayamr/build-your-silver-light-application-8830044" title="Build your silver light application"&gt;Build your silver light application&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse8830044" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildyoursilverlightapplication-110811133204-phpapp01&amp;stripped_title=build-your-silver-light-application-8830044&amp;userName=pranayamr" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse8830044" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildyoursilverlightapplication-110811133204-phpapp01&amp;stripped_title=build-your-silver-light-application-8830044&amp;userName=pranayamr" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="padding:5px 0 12px"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/pranayamr"&gt;Pranay Rana&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-116582366523705542?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/08/build-your-silver-light-application.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>2</thr:total><enclosure url="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildyoursilverlightapplication-110811133204-phpapp01&amp;stripped_title=build-your-silver-light-application-8830044&amp;userName=pranayamr" length="99888" type="application/x-shockwave-flash" /><media:content url="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=buildyoursilverlightapplication-110811133204-phpapp01&amp;stripped_title=build-your-silver-light-application-8830044&amp;userName=pranayamr" fileSize="99888" type="application/x-shockwave-flash" /><itunes:explicit>no</itunes:explicit><itunes:subtitle>Build your silver light applicationView more presentations from Pranay Rana.</itunes:subtitle><itunes:author>Pranay Rana</itunes:author><itunes:summary>Build your silver light applicationView more presentations from Pranay Rana.</itunes:summary><itunes:keywords>net,wcf,linq,sql,jquery,javascript,c</itunes:keywords></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2672586525917946298</guid><pubDate>Thu, 11 Aug 2011 14:24:00 +0000</pubDate><atom:updated>2011-08-11T07:51:36.433-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Any Mehtod</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9ejWwRAkex-uWK_3nanPSC4L2BM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9ejWwRAkex-uWK_3nanPSC4L2BM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9ejWwRAkex-uWK_3nanPSC4L2BM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9ejWwRAkex-uWK_3nanPSC4L2BM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Here I am oging to discuss about Any method. One purpose of this method is to check either the collection has elemetn or not.&lt;br /&gt;
&lt;b&gt;Example &lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;List&amp;lt;string&amp;gt; members = 
         new List&amp;lt;string&amp;gt;() { "pranay", "Hemang" };
   bool ISCollectionEmpty = members.Any();             
&lt;/pre&gt;So by using method I get to know my collection has any element or not. &lt;br /&gt;
So when I run above coe I get true in my boolean variable if there is not element it return flase.  &lt;br /&gt;
&lt;br /&gt;
Now cosider the below Database Table and&amp;nbsp; LINQ to SQL dbml file&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Department table&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-q5qvKwrmKMs/TkO0x0X_w_I/AAAAAAAACdE/f2CQoyqKimo/s1600/database%2Btable%2B1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="150" src="http://4.bp.blogspot.com/-q5qvKwrmKMs/TkO0x0X_w_I/AAAAAAAACdE/f2CQoyqKimo/s400/database%2Btable%2B1.PNG" width="252" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;Employee table&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-snX52JutjvE/TkO01PDq2lI/AAAAAAAACdM/ETMqiXoywQk/s1600/database%2Btable%2B2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="84" src="http://4.bp.blogspot.com/-snX52JutjvE/TkO01PDq2lI/AAAAAAAACdM/ETMqiXoywQk/s640/database%2Btable%2B2.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-h9fCfjiTEBs/TkO0rI-Bf_I/AAAAAAAACc8/WbrrKe9Jycc/s1600/dbml.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="231" src="http://3.bp.blogspot.com/-h9fCfjiTEBs/TkO0rI-Bf_I/AAAAAAAACc8/WbrrKe9Jycc/s400/dbml.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
As you can see there is one to many relationship between Department and Employee.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem Statement&lt;/b&gt;&lt;br /&gt;
Now Here I want to list out only those department whihc has employee.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
Most of the people do the gorup by and make use of the join and then try to find out the department which has solution.&lt;br /&gt;
&lt;br /&gt;
But the better solution to this is make use of Any() method available in the System.Linq for the collection as below&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var deptList = from dept in dbcontext.Departments
                           where dept.Employees.Any()
                           select dept;

   foreach (var item in deptList)
   {
      Console.WriteLine(item.Name + " : " + item.Employees.Count());
   }
&lt;/pre&gt;Output:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-L7_2qm8yztA/TkO08MNzFGI/AAAAAAAACdU/dnxVkYbpqCw/s1600/image.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="83" src="http://1.bp.blogspot.com/-L7_2qm8yztA/TkO08MNzFGI/AAAAAAAACdU/dnxVkYbpqCw/s640/image.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
As you can see the above query fetch the those department only which has employee and remove the department those doesnt have any. &lt;br /&gt;
I can easily able to get the cout of the employees in department using count method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Sql query : &lt;/b&gt;&lt;br /&gt;
When you see the Sql profiler or get the query in visual studio by watching variable. &lt;br /&gt;
&lt;pre class="brush: sql"&gt;SELECT [t0].[Id], [t0].[Name]
FROM [dbo].[Department] AS [t0]
WHERE EXISTS(
  SELECT NULL AS [EMPTY]
  FROM [dbo].[Employee] AS [t1]
  WHERE [t1].[DeptId] = [t0].[Id]
)
&lt;/pre&gt;&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-2672586525917946298?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/08/any-mehtod.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://4.bp.blogspot.com/-q5qvKwrmKMs/TkO0x0X_w_I/AAAAAAAACdE/f2CQoyqKimo/s72-c/database%2Btable%2B1.PNG" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3709136642922210319</guid><pubDate>Sat, 06 Aug 2011 18:26:00 +0000</pubDate><atom:updated>2011-08-11T07:26:26.902-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>SqlMethod LIKE</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/myFs5dk_0APyipaGzByUs4vo1XM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/myFs5dk_0APyipaGzByUs4vo1XM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/myFs5dk_0APyipaGzByUs4vo1XM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/myFs5dk_0APyipaGzByUs4vo1XM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;In this post I am going to discuss about the special method available in .NET framework which allows to perform the like operation as we do in the t-sql to when searching data with string. &lt;br /&gt;
&lt;br /&gt;
In sql to search string data query is &lt;br /&gt;
&lt;pre class="brush: sql"&gt;--Searching string contains abc i.e prabcfg, abcpr
Select * from table name where columnname like '%abc%'
--Searching string starts with abc i.e abcpr, abcrana
Select * from table name where columnname like 'abc%'
--Searching string ends with abc i.e prabc, ranaabc
Select * from table name where columnname like '%abc'
--Searching string with wildcard char _ i.e abec,abfc
Select * from table name where columnname like 'ab_c'
&lt;/pre&gt;Now in LINQ to achieve same thing we have function like StartsWith, EndsWith and Contains. So LINQ query is &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//Searching string contains abc i.e prabcfg, abcpr
var user = form u in users where u.Name.Contains("abc");
//Searching string starts with abc i.e abcpr, abcrana
var user = form u in users where u.Name.StartsWith("abc");
//Searching string ends with abc i.e prabc, ranaabc
var user = form u in users where u.Name.EndsWith("abc");
&lt;/pre&gt;But with the LINQ I cannot able to achieve the last case(wildcard char _ ) and many more that I can do in like condition of the t-SQL. &lt;br /&gt;
&lt;br /&gt;
SqlMehtod class has static method Like which allows to perform the same function as the like keyword of t-sql. So the query with the LINQ is &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var emplist = from emp in dbcontext.Employees
where SqlMethods.Like(emp.FirstName, "pr_nay")
select emp;
&lt;/pre&gt;When you execute the statement you can see the the t-sql statement same as above i.e wildcard statement listed above, you can view the query in the sql profiler. &lt;br /&gt;
But the the Like method work when you do the query using LINQ TO SQL only.&lt;br /&gt;
&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-3709136642922210319?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/08/sqlmethod-like.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2745456511254433828</guid><pubDate>Fri, 05 Aug 2011 15:29:00 +0000</pubDate><atom:updated>2011-08-11T07:26:07.914-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>LINQ presentation</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6ecIOk63B5aTr7rkyzrlGWKQJF0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ecIOk63B5aTr7rkyzrlGWKQJF0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6ecIOk63B5aTr7rkyzrlGWKQJF0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6ecIOk63B5aTr7rkyzrlGWKQJF0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div id="__ss_8780659" style="width: 425px;"&gt;&lt;b style="display: block; margin: 12px 0 4px;"&gt;&lt;a href="http://www.slideshare.net/pranayamr/linq-8780659" target="_blank" title="Linq"&gt;Linq&lt;/a&gt;&lt;/b&gt; &lt;iframe frameborder="0" height="355" marginheight="0" marginwidth="0" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/8780659" width="425"&gt;&lt;/iframe&gt; &lt;br /&gt;
&lt;div style="padding: 5px 0 12px;"&gt;View more &lt;a href="http://www.slideshare.net/" target="_blank"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/pranayamr" target="_blank"&gt;pranayamr&lt;/a&gt; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-2745456511254433828?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/08/linq-presentation.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6296514498917689757</guid><pubDate>Sat, 30 Jul 2011 07:21:00 +0000</pubDate><atom:updated>2011-08-02T09:58:27.629-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Testing</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Generate thousand of request</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HI6APSw5lHsvRyZ11iroykgHPeM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HI6APSw5lHsvRyZ11iroykgHPeM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HI6APSw5lHsvRyZ11iroykgHPeM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HI6APSw5lHsvRyZ11iroykgHPeM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Lastly I was working on the project where I have to designed web page which is exposing some set of the functions and which is get consume by some external application like java and flex. It's worked fine and providing the output I want.&lt;br /&gt;
&lt;br /&gt;
But now I want to perform the load test, so for that I want to generate thousand of request which consume the page and show me how it works. But the problem is how to generate the request because I don't have that many people who can make request at given time. &lt;br /&gt;
&lt;br /&gt;
Solution for this problem I make use of the Thread class and loop it to the no. of request I have to generate as you see in below code. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;for (int i = 0; i &amp;lt; 100; i++)
{
    Thread thread1 = new Thread(new ThreadStart(WorkThreadFunction1));
    thread1.Start();
}
&lt;/pre&gt;Now the secondly I made use of &lt;i&gt;HttpWebRequest&lt;/i&gt; class which allow me to call the page and to get the response. You can get more information about &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx"&gt;HttpWebRequest&lt;/a&gt;. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public void WorkThreadFunction1()
{
   try
   {
     string param = string.Empty;
     HttpWebRequest oWebReq =     
      (HttpWebRequest)WebRequest.Create("http://mywebsite/WebForm1.aspx" + param);
     HttpWebResponse oWebResp = (HttpWebResponse)oWebReq.GetResponse();
     StreamReader oStream = new StreamReader(oWebResp.GetResponseStream(),     
                                                     System.Text.Encoding.ASCII);
     Console.WriteLine(oStream.ReadToEnd());
   }
   catch (Exception ex)
   {
      // log errors
   }
}
&lt;/pre&gt;As you can see in the above code I am making the call to the my page and writing the response to the console window.&lt;br /&gt;
Note:&lt;br /&gt;
Here WebForm1 is entry point based on the parameter passed to it , it calls the&amp;nbsp;different&amp;nbsp;function and may be the pages in your site.&lt;br /&gt;
Here I am making request to one single page but you can write you own script to call the different page and pass the parameter to it. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
So you can easily make no. of request without need of the no. of people. But this thing depends on the requirement in you case.    &lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6296514498917689757?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/generate-thousand-of-request.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5624767102323138989</guid><pubDate>Fri, 29 Jul 2011 12:55:00 +0000</pubDate><atom:updated>2011-07-30T06:34:23.962-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Intermediate</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Difference between Object, Dynamic and Var</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PiwOQz8-oxZ7hAnzpOajohQGkm4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PiwOQz8-oxZ7hAnzpOajohQGkm4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PiwOQz8-oxZ7hAnzpOajohQGkm4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PiwOQz8-oxZ7hAnzpOajohQGkm4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to write the points about the three type of the variable Object, Var and Dynamic. Most of the developer not able to get what is difference between this three kind of variable.&lt;br /&gt;
&lt;table border="1"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Dynamic&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Var&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Can able to store any kind of value, because object is the base class of all type in .net framework.&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Can able to store any type of the variable, similar to old VB language variable.&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Can able to store any type of value but it require to initialize at the time of declaration.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-f4R_nVJyN7Q/TjKtHKB0NNI/AAAAAAAACcE/vZmriKOlC5Y/s1600/var+inialize+error.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="49" src="http://2.bp.blogspot.com/-f4R_nVJyN7Q/TjKtHKB0NNI/AAAAAAAACcE/vZmriKOlC5Y/s200/var+inialize+error.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Compiler has little information about the type&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-O3j4Ud1rn9s/TjKtOoGsrbI/AAAAAAAACcI/Q1a9HF2Hbok/s1600/object.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="44" src="http://1.bp.blogspot.com/-O3j4Ud1rn9s/TjKtOoGsrbI/AAAAAAAACcI/Q1a9HF2Hbok/s200/object.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Compiler doesn't have any information about the this type of variable.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-9B9snB1pPFg/TjKtRr435OI/AAAAAAAACcM/FnUjqaGFYI0/s1600/dynamic.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="83" src="http://4.bp.blogspot.com/-9B9snB1pPFg/TjKtRr435OI/AAAAAAAACcM/FnUjqaGFYI0/s200/dynamic.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;It's compiler safe i.e compiler has all information about the stored value, so that it doesn't cause any issue at run-time.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-BXXEgzeJ8XE/TjKtWeI_JGI/AAAAAAAACcQ/iW6xh5sYPg4/s1600/var+compiler.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="56" src="http://4.bp.blogspot.com/-BXXEgzeJ8XE/TjKtWeI_JGI/AAAAAAAACcQ/iW6xh5sYPg4/s200/var+compiler.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Object type can be passed as function argument and function also can return object type&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Dynamic type can be passed as function argument and function also can return object type&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Var type can not be passed as function argument and function can not return object type. This type of variable can work in the scope where it defined.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dkV7VvttM34/TjKtbFDf0yI/AAAAAAAACcU/PnUFg5KIDcE/s1600/var+passing+argument.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="30" src="http://4.bp.blogspot.com/-dkV7VvttM34/TjKtbFDf0yI/AAAAAAAACcU/PnUFg5KIDcE/s200/var+passing+argument.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Require to cast object variable to original type before using it. So this assigning to object type and converting to original type called as Boxing and Un-Boxing for primitive data type and for the reference type its casting of types. It's actually increasing the overhead when we do this both operation.&lt;br /&gt;
&lt;br /&gt;
Allows to perform operation of given type once it get cast any user defined or primitive data type.&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Casting is not require but you need to know the property and methods related to stored type&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;No need to cast because compiler has all information to perform operation.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Cause the problem at run time if the stored value is not get converted to underlying data type.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-AcTarSXqc08/TjKtgMQ-jiI/AAAAAAAACcY/ldRUTGHpTO4/s1600/Object+error.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="68" src="http://2.bp.blogspot.com/-AcTarSXqc08/TjKtgMQ-jiI/AAAAAAAACcY/ldRUTGHpTO4/s200/Object+error.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Cause problem if the wrong method or property accessed because all the information about stored value is get resolve only at run time&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Gk8fm_tIc98/TjKtjhCgnPI/AAAAAAAACcc/BZshBUrwC90/s1600/dynamic+error.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="73" src="http://2.bp.blogspot.com/-Gk8fm_tIc98/TjKtjhCgnPI/AAAAAAAACcc/BZshBUrwC90/s200/dynamic+error.JPG" t$="true" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Doesn't cause problem because compiler has all info about stored value.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style="vertical-align: top;"&gt;Useful when doesn't have more information about the data type.&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Useful when coding using reflection or dynamic language support or with the COM objects, because we require to write less amount of code.&lt;/td&gt;&lt;td style="vertical-align: top;"&gt;Useful when getting result out of the linq queries. In 3.5 framework it introduce to support linq feature.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-5624767102323138989?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/object-dynamic-and-var.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://2.bp.blogspot.com/-f4R_nVJyN7Q/TjKtHKB0NNI/AAAAAAAACcE/vZmriKOlC5Y/s72-c/var+inialize+error.JPG" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3747817793666678596</guid><pubDate>Thu, 21 Jul 2011 17:13:00 +0000</pubDate><atom:updated>2011-07-24T09:28:11.476-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Exception</category><title>Handle Exception Carefully</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ck_xb6m-RAJ7zsqJXmdEOqdLRlg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ck_xb6m-RAJ7zsqJXmdEOqdLRlg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ck_xb6m-RAJ7zsqJXmdEOqdLRlg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ck_xb6m-RAJ7zsqJXmdEOqdLRlg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Handle Exception carefully means I am not going to discuss some rocket science about exception handling but I am going to discuss not to shadow the exception in your program. Not going to discuss more I am starting my example&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Program p = new Program();
                p.MethodA();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            Console.ReadLine();
        }

        public void MethodA()
        {
            try
            {
                MethodB();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void MethodB()
        {
            try
            {
                MethodC();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void MethodC()
        {
            int a = 10;
            int b = 0;
            int c = 0;
            try
            {
                c = a / b;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
&lt;/pre&gt;When execute the program you will get the following output as result. Yes you can able to handle the exception thrown by the method and displayed on the console.&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ScumUNrSkfw/TihWUuiEDhI/AAAAAAAACbM/rStUzFnFN7Q/s1600/Exception+output+1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="130" src="http://3.bp.blogspot.com/-ScumUNrSkfw/TihWUuiEDhI/AAAAAAAACbM/rStUzFnFN7Q/s640/Exception+output+1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;But the actual thing is you hiding the stack trace and each time you throw the exception by writing &lt;i&gt;throw ex&lt;/i&gt; you are creating new stack trace. So you are not able to get the actual  path from where the exception get thrown.&lt;br /&gt;
&lt;br /&gt;
Now to understand the thing properly, write the program again and now replace &lt;i&gt;throw ex&lt;/i&gt; by the &lt;i&gt;throw&lt;/i&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Program p = new Program();
                p.MethodA();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            Console.ReadLine();
        }

        public void MethodA()
        {
            try
            {
                MethodB();
            }
            catch
            {
                throw;
            }
        }

        public void MethodB()
        {
            try
            {
                MethodC();
            }
            catch
            {
                throw;
            }
        }

        public void MethodC()
        {
            int a = 10;
            int b = 0;
            int c = 0;
            try
            {
                c = a / b;
            }
            catch
            {
                throw;
            }
        }
    }
&lt;/pre&gt;When execute the program get the following output &lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-caivic8u-8A/TihWyBTyncI/AAAAAAAACbQ/buRvfp1_DvI/s1600/Exception+output+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="172" src="http://3.bp.blogspot.com/-caivic8u-8A/TihWyBTyncI/AAAAAAAACbQ/buRvfp1_DvI/s640/Exception+output+2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;Now as you see when you replace the line there is no new stacktrace get created and you get actual path from where exception get thrown.   &lt;/div&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
So make use of the &lt;i&gt;throw&lt;/i&gt; to get the actual path of the exception rather than using &lt;i&gt;throw ex&lt;/i&gt;.&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-3747817793666678596?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/handle-exception-carefully.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-ScumUNrSkfw/TihWUuiEDhI/AAAAAAAACbM/rStUzFnFN7Q/s72-c/Exception+output+1.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6301589448544906660</guid><pubDate>Sun, 17 Jul 2011 10:12:00 +0000</pubDate><atom:updated>2011-07-24T09:28:35.691-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">split</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">string</category><title>String Split Utility</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kepWxcqGJrN1or-Iu-CpO4BJXKk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kepWxcqGJrN1or-Iu-CpO4BJXKk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kepWxcqGJrN1or-Iu-CpO4BJXKk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kepWxcqGJrN1or-Iu-CpO4BJXKk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;Note: Split function has more no of overload method but the below two I found useful. You may found other overloads helpful in your code.&lt;br /&gt;
&lt;br /&gt;
In this post I am going to discuss about two important thing about Split function of String class. Split function of the string class split the string in array of string. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Split function to split string in array &lt;/b&gt;&lt;br /&gt;
&lt;i&gt;String.Split( char[])&lt;/i&gt;&lt;br /&gt;
For example &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string words = "stringa,stringb, ,stringc,stringd stringe.";
string [] split = words.Split(new Char [] {' ', ','}); 
&lt;/pre&gt;Above code create a string array which has &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//output
split[0]=stringa
split[1]=stringb
split[2]=
split[3]=stringc
split[4]=stringd
split[5]=stringe
&lt;/pre&gt;but What If I want to remove empty string from the array when I split string.&lt;br /&gt;
Solution to this problem is to make use of second overload method of the the string Split where you can specify the option to remove string. So above code is rewritten as &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Overload method with option&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;String.Split(Char[], StringSplitOptions)&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string words = "stringa,stringb, ,stringc,stringd stringe.";
string [] split = words.Split(new Char [] {' ', ','},StringSplitOptions.RemoveEmptyEntries); 
&lt;/pre&gt;Created string array is&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//output 
split[0]=stringa
split[1]=stringb
split[2]=stringc
split[3]=stringd
split[4]=stringe
&lt;/pre&gt;&lt;br /&gt;
Now consider case where I have to limit no of return string. Consider for example &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string a = "key:mykey, Value : test1,test2";  
&lt;/pre&gt;Now I have to get the key:mykey in string 1 and  Value : test1,test2 in string 2.&lt;br /&gt;
&lt;b&gt;Overload function to split string in limited no. of string&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;Split(Char[], Int32)&lt;/i&gt;&lt;br /&gt;
So the code for this is &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string a = "key:mykey, Value : test1,test2";
string [] split = words.Split(new Char [] {','},2);   
&lt;/pre&gt;Now the split array have&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//output
split[0]= "key:mykey";
split[1]= "Value : test1,test2";
&lt;/pre&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
There are also other variable of Split method which you can refer form the msdn link :&lt;a href="http://msdn.microsoft.com/en-us/library/system.string.split.aspx"&gt;String.Split&lt;/a&gt;. But I fond above two more useful than others.&lt;br /&gt;
&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6301589448544906660?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/string-split.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-985130866402255145</guid><pubDate>Tue, 12 Jul 2011 17:32:00 +0000</pubDate><atom:updated>2011-07-24T09:28:53.664-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">collection</category><category domain="http://www.blogger.com/atom/ns#">foreach</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>ForEach Method for the collections</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bOUAnOFAUOHKW5uWyCnV2sf57gQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bOUAnOFAUOHKW5uWyCnV2sf57gQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bOUAnOFAUOHKW5uWyCnV2sf57gQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bOUAnOFAUOHKW5uWyCnV2sf57gQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;In this small post I am going to discuss about the new method introduce in the .net framework &lt;i&gt;ForEach&lt;/i&gt; which allow to perform the action on the each set of element.&lt;br /&gt;
&lt;br /&gt;
Syntax &lt;br /&gt;
&lt;i&gt;public void ForEach(Action&amp;lt;t&amp;gt; action)&lt;br /&gt;
Action&amp;lt;t&amp;gt; is delegate or function to perform on each element of the List&lt;t&gt;.&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
To get in more detail how it works check check the following code.&lt;br /&gt;
Below is Employee class which has property related to employee of the company. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class Employee
{
        public string Name { get; set; }
        public int Salary { get; set; }
        public string Address { get; set; }
        public int Id { get; set; }
}
&lt;/pre&gt;and now in following line of code I am initializing list of employees &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;class Program
    {
        static void Main(string[] args)
        {
          List&amp;lt;employee&amp;gt; emplst = new List&amp;lt;employee&amp;gt; { 
          new Employee() { Name="pranay", Address = "Ahmedabad", Id=1, Salary=1234},
          new Employee() { Name="Hemang", Address = "Ahmedabad", Id=2, Salary=2348},
          new Employee() { Name="kurnal", Address = "Himmatnagar", Id=3, Salary=8999},
          new Employee() { Name="Hanika", Address = "Ahmedabad", Id=4, Salary=7888}
        };
&lt;/pre&gt;Now I want to increase salary of each employee by 10%, so with the the help of new ForEach construct I can easily achieve it by using following line of code.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;emplst.ForEach(new Program().incSalary);
     }

  private void incSalary(Employee emp)
  {
     emp.Salary += (emp.Salary * 10)/100; 
  }
}
&lt;/pre&gt;As you can see in above code I have written &lt;i&gt;new Program().incSalary&lt;/i&gt; as action, in the &lt;i&gt;incsalary&lt;/i&gt; method as you see I increase the salary of each employee 10%.&lt;br /&gt;
This thing can easily also done by making use of the &lt;i&gt;foreach&lt;/i&gt; loop available but if you see the the &lt;i&gt;ForEach&lt;/i&gt; in reflector it does the same thing. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-DS1XfRPskhM/Thxi2VNF7gI/AAAAAAAACaw/_pm2uXuHbVQ/s1600/foreach.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-DS1XfRPskhM/Thxi2VNF7gI/AAAAAAAACaw/_pm2uXuHbVQ/s640/foreach.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;ForEach method make code more simple and easy to understand.&lt;br /&gt;
&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-985130866402255145?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/foreach-method-for-collections.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-DS1XfRPskhM/Thxi2VNF7gI/AAAAAAAACaw/_pm2uXuHbVQ/s72-c/foreach.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2366282108274014351</guid><pubDate>Fri, 08 Jul 2011 23:12:00 +0000</pubDate><atom:updated>2011-07-09T02:12:33.468-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JAVA SCRIPT / JQUERY</category><category domain="http://www.blogger.com/atom/ns#">Ajax</category><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><title>Jquery Ajax Calling functions</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZuwKsXHIbcRD6wdlgx7boR8GJiY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZuwKsXHIbcRD6wdlgx7boR8GJiY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZuwKsXHIbcRD6wdlgx7boR8GJiY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZuwKsXHIbcRD6wdlgx7boR8GJiY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;a href="https://rapidshare.com/files/1206103032/AJAXCALLS.rar"&gt;Download Code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Recently I am working on Website with the asp.net and jQuery. While working with jquery library I found that there are 5 diffrent function that used to make ajax call to page and to fetch data. I am going to discuss about that five function one by one.&lt;br /&gt;
&lt;br /&gt;
Following is list of that five function availale in jquery libaray to make ajax call.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Load&lt;/li&gt;
&lt;li&gt;getJson&lt;/li&gt;
&lt;li&gt;GET&lt;/li&gt;
&lt;li&gt;POST&lt;/li&gt;
&lt;li&gt;Ajax&lt;/li&gt;
&lt;/ol&gt;&lt;b&gt;Load &lt;/b&gt;&lt;br /&gt;
Method allow to make ajax call to the page and allows to send using both Get and Post methods.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var loadUrl = "TestPage.htm";
$(document).ready(function () {
   $("#load_basic").click(function () {
     $("#result").html(ajax_load).load(loadUrl, function (response, status, xhr) {
                    if (status == "error") {
                        var msg = "Sorry but there was an error: ";
                        $("#dvError").html(msg + xhr.status + " " + xhr.statusText);
                    }
                }
                );
                return false;
});
&lt;/pre&gt;As you can see in above code you can easily make call to any page by passing it Url. The call back function provide more control and allows to handle the error if any by making use of the Status value.&lt;br /&gt;
One of the important thing about the load method is its allow to load part of page rather than whole page. So get only part of the page call remains same but the url is&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var loadUrl = "TestPage.htm #dvContainer";   
&lt;/pre&gt;So by the passing above url to load method it just load content of the div having id=dvContainer. Check the demo code for detail.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-jPDHgH9OOvo/TheLakK-W5I/AAAAAAAACZQ/HH-dt5XEcXI/s1600/load.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="368" src="http://2.bp.blogspot.com/-jPDHgH9OOvo/TheLakK-W5I/AAAAAAAACZQ/HH-dt5XEcXI/s640/load.jpg" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Firebug shows the repose get return by when we call the page by Load method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important Feature&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Allow make call with both Get and Post request&lt;/li&gt;
&lt;li&gt;Allow to load part of the page.&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;getJson&lt;/b&gt;&lt;br /&gt;
Method allow get json data by making ajax call to page. This method allows only to pass the parameter by get method posting parameter is not allowed. One more thing this method treat the respose as Json.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var jsonUrl = "Json.htm";
            $("#btnJson").click(function () {
                $("#dvJson").html(ajax_load);

                $.getJSON(jsonUrl, function (json) {
                    var result = json.name;
                    $("#dvJson").html(result);
                }
                );
                return false;
            });
&lt;/pre&gt;Above code make use of getJSON function and displays json data fetch from the page.&lt;br /&gt;
Following is json data return by the Json.htm file.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;{
"name": "Hemang Vyas",
"age" : "32",
"sex": "Male"
}
&lt;/pre&gt;&lt;br /&gt;
Following image displays the json Data return as respose.&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;&lt;a href="http://3.bp.blogspot.com/-wOOE9z4bgLU/TheLaBxBVAI/AAAAAAAACZM/c-6e8UVXueM/s1600/getjson.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="184" src="http://3.bp.blogspot.com/-wOOE9z4bgLU/TheLaBxBVAI/AAAAAAAACZM/c-6e8UVXueM/s640/getjson.jpg" style="cursor: move;" width="640" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;Important Feature&lt;/b&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Only send data using get method, post is not&amp;nbsp;allowed.&lt;/li&gt;
&lt;li&gt;Treat the response data as Json only&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;get&lt;/b&gt;&lt;br /&gt;
Allow to make ajax request with the get method.  It handles the response of many formats including xml, html, text, script, json, and jonsp. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var getUrl = "GETAndPostRequest.aspx";
            $("#btnGet").click(function () {
                $("#dvGet").html(ajax_load);

                $.get(getUrl, { Name: "Pranay" }, function (result) {
                    $("#dvGet").html(result);
                }
                );
                return false;
            });
&lt;/pre&gt;As in code I am passing Name parameter to the page using get request. &lt;br /&gt;
On server side you can get the value of the Name parameter in request object querycollection.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;if (Request.QueryString["Name"]!=null)
{
    txtName.Text = Request.QueryString["Name"].ToString();
} 
&lt;/pre&gt;&lt;br /&gt;
The firebug shows the parameter passe by me as Get request &amp;nbsp;and &amp;nbsp;value of the parameter is pranay&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-PX09ohLgzjI/TheLZiEbo7I/AAAAAAAACZI/XFTkdVYRykw/s1600/get.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="144" src="http://2.bp.blogspot.com/-PX09ohLgzjI/TheLZiEbo7I/AAAAAAAACZI/XFTkdVYRykw/s640/get.jpg" style="cursor: move;" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;Important Feature&lt;/b&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Can handle any type of the response data.&lt;/li&gt;
&lt;li&gt;Send data using get method only.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;post&lt;/b&gt;&lt;br /&gt;
Allow to make ajax request with the post method. It handles the response of many formats including xml, html, text, script, json, and jonsp. post does same as get but just send data using post method. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var postUrl = "GETAndPostRequest.aspx";
            $("#btnPost").click(function () {
                $("#dvPost").html(ajax_load);

                $.post(postUrl, { Name: "Hanika" }, function (result) {
                    $("#dvPost").html(result);
                }
                );
                return false;
            });
&lt;/pre&gt;As in code I am passing Name parameter to the page using post request. &lt;br /&gt;
On server side you can get the value of the Name parameter in request object formcollection.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;if (Request.Form["Name"] != null)
{
    txtName.Text = Request.Form["Name"].ToString();
}
&lt;/pre&gt;&lt;br /&gt;
The firebug shows the parameter passe by me as Get request &amp;nbsp;and &amp;nbsp;value of the parameter is Hanika&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/-XBNv-EgrNQA/TheLZAOLzKI/AAAAAAAACZE/Jzw57kKkBMY/s1600/post.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="152" src="http://3.bp.blogspot.com/-XBNv-EgrNQA/TheLZAOLzKI/AAAAAAAACZE/Jzw57kKkBMY/s640/post.jpg" style="cursor: move;" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;Important Feature&lt;/b&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Can handle any type of the response data.&lt;/li&gt;
&lt;li&gt;Send data using post method only.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;ajax&lt;/b&gt;&lt;br /&gt;
Allow to make the ajax call. This method provide more control than all other methods we seen. you can figure out the difference by checking the list of parameter.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var ajaxUrl = "Json.htm";
            $("#btnAjax").click(function () {
                $("#dvAjax").html(ajax_load);


                $.ajax({
                    type: "GET", //GET or POST or PUT or DELETE verb
                    url: ajaxUrl, // Location of the service
                    data: "", //Data sent to server
                    contentType: "", // content type sent to server
                    dataType: "json", //Expected data format from server
                    processdata: true, //True or False
                    success: function (json) {//On Successfull service call
                        var result = json.name;
                        $("#dvAjax").html(result);
                    },
                    error: ServiceFailed// When Service call fails
                });


                return false;
            });&lt;/pre&gt;In above code you can see the all the parameter and comment related to each parameter describe the purpose of each one.&lt;br /&gt;
&lt;br /&gt;
Fire bug shows the called page return json data and Ajax function treat the respose as Json because in code datatype = json&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-TytvBlUVRi4/TheLWTQNnlI/AAAAAAAACZA/Gex7ub88joM/s1600/ajax.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="196" src="http://1.bp.blogspot.com/-TytvBlUVRi4/TheLWTQNnlI/AAAAAAAACZA/Gex7ub88joM/s640/ajax.png" style="cursor: move;" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;Important Feature&lt;/b&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Provide more control on the data sending and on response data.&lt;/li&gt;
&lt;li&gt;Allow to handle error occur during call.&lt;/li&gt;
&lt;li&gt;Allow to handle data if the call to ajax page is successfull.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
So each method of jQuery ajax is different and can use for the difference purpose.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-2366282108274014351?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/jquery-ajax-calling-functions.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://2.bp.blogspot.com/-jPDHgH9OOvo/TheLakK-W5I/AAAAAAAACZQ/HH-dt5XEcXI/s72-c/load.jpg" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6986548044141910004</guid><pubDate>Tue, 05 Jul 2011 14:01:00 +0000</pubDate><atom:updated>2011-07-24T09:29:14.867-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Debugging</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Get time of Code Execution Using StopWatch</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WId9flhBeIYG34omeIiVovSUBm0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WId9flhBeIYG34omeIiVovSUBm0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WId9flhBeIYG34omeIiVovSUBm0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WId9flhBeIYG34omeIiVovSUBm0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;During Development of the application/product or after deployment of the application/product there might be a situation where you want to find out the the how much time is taken by you code to execute ? Is it too much slow ?&lt;br /&gt;
&lt;br /&gt;
Answer to this problem is make use of &lt;b&gt; StopWatch&lt;/b&gt; class of System.Diagnostics namespace which is usefull to find out the time taken to execute given line of code. The class is helpfull to find out how efficient code develop by measuring the time of execution.&lt;br /&gt;
&lt;br /&gt;
To understand how to use it consider the below demo&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
//instead of this there is line of code that you are going to execute
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine(elapsedTime);
Console.ReadLine();
&lt;/pre&gt;Stopwatch class has method Start() and Stop(), So the as name suggest call start when you want to start your watch and call Stop when you want to stop the watch. Once you stop the watch i.e called stop method of the StopWatch class you can get the value of time of execution by using Elapsed property of the class which return TimeSpan object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://dailydotnettips.com/wp-content/uploads/2011/07/Output1.jpg"&gt;&lt;img alt="" class="alignnone size-medium wp-image-1288" height="37" src="http://dailydotnettips.com/wp-content/uploads/2011/07/Output1-300x37.jpg" title="Output" width="300" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There are also other important methods which are very usefull you can get the more infomation about those on the MSDN documentation over here : &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx"&gt;StopWatch Class&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Methods&lt;/b&gt;&lt;br /&gt;
StartNew -  Initializes a new Stopwatch instance, sets the elapsed time property to zero, and starts measuring elapsed time.&lt;br /&gt;
Restart     -  Stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.&lt;br /&gt;
Reset      -   Stops time interval measurement and resets the elapsed time to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Properties&lt;/b&gt;&lt;br /&gt;
ElapsedMilliseconds - Gets the total elapsed time measured by the current instance, in milliseconds.&lt;br /&gt;
ElapsedTicks           -  Gets the total elapsed time measured by the current instance, in timer ticks.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Advantage&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Easy and Simple to use.&lt;/li&gt;
&lt;li&gt;Useful when want to find out the time take by the line of code to execute.&lt;/li&gt;
&lt;li&gt;By using the class there is no need of any third party tool because it part of the .net framework.&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-6986548044141910004?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/during-development-of.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3364553795550900798</guid><pubDate>Mon, 04 Jul 2011 19:43:00 +0000</pubDate><atom:updated>2011-07-24T09:29:38.534-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Lazy initialization</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Lazy initialization of object in C# with Lazy&lt;T&gt; class</title><description>
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bEu5m7V3DVwWgJ0lYXM9J6AJoMw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bEu5m7V3DVwWgJ0lYXM9J6AJoMw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bEu5m7V3DVwWgJ0lYXM9J6AJoMw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bEu5m7V3DVwWgJ0lYXM9J6AJoMw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Lazy&amp;lt;T&amp;gt; is class introduced in the .Net framework 4.0 to initialize the object later on i.e allow to initialize object when we are going to utilize or assigning value to the object.&lt;br /&gt;
&lt;br /&gt;
To understand Lazy initialization consider below class. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class Employee
    {
        public string Name { get; set; }
        public int Salary { get; set; }
        public string Address { get; set; }
        public int Id { get; set; }
    }
&lt;/pre&gt;In the following code I am using the Employee class. As you can see I have initialize the class to null   &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Employee emp1=null;
     Console.WriteLine(emp1);
     ///Code do perform other task
     if(Condition)
     {
      if (emp1 == null)
        emp1 = new Employee();
     }
&lt;/pre&gt;In above code I am initializing class when I need it rather than initializing before using it same way we can do in the Singleton design pattern, by this way we are lazing initializing the object and consume memory when need it rather than initializing it in the first line of the method.  &lt;br /&gt;
&lt;br /&gt;
But now .net 4.0 framework provide the new class to do this thing easily. The class is Lazy&amp;lt;T&amp;gt;. So the above code is something like as below  &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Lazy&amp;lt;employee&amp;gt; emp = new Lazy&amp;lt;employee&amp;gt;();
     Console.WriteLine(emp);

     emp.Value.Id = 1;
     emp.Value.Name = "pranay";
     emp.Value.Salary = 123;
     emp.Value.Address = "Ahmedabad";
     Console.WriteLine(emp);
&lt;/pre&gt;Output of the program&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-qms4tLI20a4/ThH9NV_G2PI/AAAAAAAACYI/HQh30S9PL-M/s1600/Lazy.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="89" src="http://3.bp.blogspot.com/-qms4tLI20a4/ThH9NV_G2PI/AAAAAAAACYI/HQh30S9PL-M/s640/Lazy.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;As you can see in output window it display no value is defined.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important Properties&lt;/b&gt;&lt;br /&gt;
Object is get created when we access property &lt;i&gt;Value&lt;/i&gt; and assign value to it. To find out the detail I used reflector and which shows that the object get created when I access property. &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-1xCvputAmHs/ThIKXig6oGI/AAAAAAAACYQ/YSrGInLv6sc/s1600/value%2Bproperty.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://1.bp.blogspot.com/-1xCvputAmHs/ThIKXig6oGI/AAAAAAAACYQ/YSrGInLv6sc/s640/value%2Bproperty.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Another the important property is &lt;i&gt;IsValueCreated&lt;/i&gt;-Gets a value that indicates whether a value has been created for this Lazy&lt;t&gt; instance.&lt;br /&gt;
&lt;/div&gt;&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1194836729866470946-3364553795550900798?l=pranayamr.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2011/07/lazy-inialization.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-qms4tLI20a4/ThH9NV_G2PI/AAAAAAAACYI/HQh30S9PL-M/s72-c/Lazy.jpg" height="72" width="72" /><thr:total>1</thr:total></item><language>en-us</language><copyright>Pranay Rana @2010 Gmind Solution</copyright><media:credit role="author">Pranay Rana</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Gmind Solution</media:description></channel></rss>

