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

<channel>
	<title>.toString() &#187; ASP.NET</title>
	<atom:link href="http://www.dottostring.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dottostring.com</link>
	<description>Programming is our passion</description>
	<lastBuildDate>Sun, 04 Oct 2009 15:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding support for .NET datatypes to ExtJs Grid (DateTime, Boolean and Currency)</title>
		<link>http://www.dottostring.com/2009/04/adding-support-for-net-datatypes-to-extjs-grid-datetime-boolean-and-currency/</link>
		<comments>http://www.dottostring.com/2009/04/adding-support-for-net-datatypes-to-extjs-grid-datetime-boolean-and-currency/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 21:10:56 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ExtJs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[renderer]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=356</guid>
		<description><![CDATA[In our previous examples we had been using plain Strings in ExtJs grid.
Have a quick look at them:

On-Demand Paging using ExtJS Grid with Client-Centric ASP.NET AJAX (WebMethods)
Adding server side sorting to ExtJS Grid using WebMethods in ASP.NET

Today, we are going to deal with other Data types like DateTime, Boolean, Currency et cetera. For this purpose, [...]]]></description>
			<content:encoded><![CDATA[<p>In our previous examples we had been using plain Strings in ExtJs grid.<br />
Have a quick look at them:</p>
<ul>
<li><a href="/2008/12/on-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods/" target="_blank">On-Demand Paging using ExtJS Grid with Client-Centric ASP.NET AJAX (WebMethods)</a></li>
<li><a href="/2009/03/adding-server-side-sorting-to-extjs-grid-using-webmethods-in-aspnet/" target="_blank">Adding server side sorting to ExtJS Grid using WebMethods in ASP.NET</a></li>
</ul>
<p>Today, we are going to deal with other Data types like DateTime, Boolean, Currency et cetera. For this purpose, ExtJs ColumnModel provides and excellent config option <code><a href="http://extjs.com/deploy/ext/docs/output/Ext.grid.ColumnModel.html#config-renderer" target="_blank">renderer</a></code></p>
<p>Lets start with builtin format options of ExtJs. </p>
<pre name="code" class="js">
// create the grid
        var grid = new Ext.grid.EditorGridPanel({
            el:'grid-employees',
            width:650,
            height:300,
            title:'Sample Employees',
            store: store,
            stripeRows: true,
            loadMask: true,
            enableHdMenu: false,

            // grid columns
            columns:[{
                id: 'EmployeeID',
                dataIndex: 'EmployeeID',
                hidden:true
            },{
                header: "Login ID",
                dataIndex: 'LoginID',
                width: 150,
                sortable:true

            },{
                header: "Title",
                dataIndex: 'Title',
                width: 200,
                sortable:true
            },{
                header: "Birth Date",
                dataIndex: 'BirthDate',
                width: 100,
                sortable:true
            },{
                header: "Gender",
                dataIndex: 'Gender',
                width: 70,
                sortable:true
            },{
                header: "Salary",
                dataIndex: 'Salary',
                width: 70,
                renderer: 'usMoney',
                sortable:true
            },{
                header: "Salaried",
                dataIndex: 'SalariedFlag',
                width: 50,
                sortable:true
            }],
            // put paging bar on the bottom
            bbar: pagingBar
        });
</pre>
<p>Notice that for the dataIndex Salary, we have renderer option equal to <code><a href="http://extjs.com/deploy/ext/docs/output/Ext.util.Format.html#usMoney" target="_blank">usMony</a></code>. This will render all values in this column as usMoney. </p>
<p>Now lets play with some custom renderers. I have written two custom rederers. One is for DateTime object of .NET and the other is for Boolean object.</p>
<pre name="code" class="js">
        // Our own date renderer function
        function formatDate(value){
            return value ? value.dateFormat('F d, Y') : '';
        };

        // Our own boolean renderer
        function formatTrueFalse(value) {
            return value ? '&amp;#10003;': '&amp;#9747;';
        }
</pre>
<p>These functions are quite simple. They just return the formatted strings to be used in ColumnModel. Now we will use these renderers in our ColumnModel.</p>
<pre name="code" class="js">
        // create the grid
        var grid = new Ext.grid.EditorGridPanel({
            el:'grid-employees',
            width:650,
            height:300,
            title:'Sample Employees',
            store: store,
            stripeRows: true,
            loadMask: true,
            enableHdMenu: false,

            // grid columns
            columns:[{
        	    id: 'EmployeeID',
                dataIndex: 'EmployeeID',
                hidden:true
            },{
                header: "Login ID",
                dataIndex: 'LoginID',
                width: 150,
                sortable:true

            },{
                header: "Title",
                dataIndex: 'Title',
                width: 200,
                sortable:true
            },{
                header: "Birth Date",
                dataIndex: 'BirthDate',
                width: 100,
                renderer: formatDate,
                sortable:true
            },{
                header: "Gender",
                dataIndex: 'Gender',
                width: 70,
                sortable:true
            },{
                header: "Salary",
                dataIndex: 'Salary',
                width: 70,
                renderer: 'usMoney',
                sortable:true
            },{
                header: "Salaried",
                dataIndex: 'SalariedFlag',
                width: 50,
                renderer: formatTrueFalse,
                sortable:true
            }],
            // put paging bar on the bottom
            bbar: pagingBar
        });
</pre>
<p>And that&#8217;s all <img src='http://www.dottostring.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now you will have a beautifully rendered grid. </p>
<p><img src="http://www.dottostring.com/wp-content/uploads/2009/04/custom-renderer-extjs-grid.png" alt="custom-renderer-extjs-grid" title="custom-renderer-extjs-grid" width="652" height="302" class="aligncenter size-full wp-image-358" /></p>
<p>You can also add images in grid in this way. Try replacing Gender in this example with appropriate icons. I leave this as an exercise for you.</p>
<p><a href='http://www.dottostring.com/wp-content/uploads/2009/04/dottostring-extjs-grid-fields.zip'>Download the example code</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F04%2Fadding-support-for-net-datatypes-to-extjs-grid-datetime-boolean-and-currency%2F';
  addthis_title  = 'Adding+support+for+.NET+datatypes+to+ExtJs+Grid+%28DateTime%2C+Boolean+and+Currency%29';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/04/adding-support-for-net-datatypes-to-extjs-grid-datetime-boolean-and-currency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery Communicating with Web Service to check for duplicate emails</title>
		<link>http://www.dottostring.com/2009/04/jquery-communicating-with-web-service-to-check-for-duplicate-emails/</link>
		<comments>http://www.dottostring.com/2009/04/jquery-communicating-with-web-service-to-check-for-duplicate-emails/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 15:36:34 +0000</pubDate>
		<dc:creator>ahsan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[WebService]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=331</guid>
		<description><![CDATA[Few days ago I had a task that on user registration I had to check the email address of the user. When the user enters the email address the application should check the database that if the email exists in the database user will not be able to add it again and the whole task [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I had a task that on user registration I had to check the email address of the user. When the user enters the email address the application should check the database that if the email exists in the database user will not be able to add it again and the whole task should be done in a way that user enters the email in a textbox and then starts filling the other form and system in the meanwhile automatically checks the existence of email in the database. I used <strong>Jquery</strong> for this task, the selection of jquery can be debatable but its not the issue at hand. I made a web service which communicates with my database. In the web service I have a method  named CheckEmail which checks the existence of email in the particular table. The web service looks like this:</p>
<pre name="code" class="vb">Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.Data.OleDb

&lt;WebService(Namespace:="http://tempuri.org/")&gt; _
&lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _
&lt;ScriptService()&gt; _
&lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _
Public Class Service
Inherits System.Web.Services.WebService

&lt;WebMethod()&gt; _
Public Function CheckEmail(ByVal email As String) As String
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionStringManual").ToString()
Dim connection As OleDbConnection = New OleDbConnection(connectionString)
connection.Open()
Dim sqlString As String = "Select count(*) from Customers where CustomerEmail =?"
Dim command As OleDbCommand = New OleDbCommand(sqlString, connection)
command.Parameters.AddWithValue("CustomerEmail", email)
Return command.ExecuteScalar()

End Function
End Class</pre>
<p>This web service returns an integer based on the count of rows after running the query.</p>
<p>I have an aspx page which looks like the code below:</p>
<pre name="code" class="html">&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
Email:
&lt;/td&gt;
&lt;td&gt;
&lt;asp:TextBox ID="txtEmail" runat="server" &gt;&lt;/asp:TextBox&gt;&lt;span id="spErrorMessage"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Password:
&lt;/td&gt;
&lt;td&gt;
&lt;asp:TextBox ID="txtPassword" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;/div&gt;

&lt;/form&gt;
&lt;/body&gt;</pre>
<p>And finally the last but the most important section of  Jquery in the head section of the page.</p>
<pre name="code" class="js">&lt;head runat="server"&gt;
&lt;script src="jquery-1.3.2.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

$(function()
{
$("#&lt;%= txtEmail.ClientID %&gt;").change(DuplicateEmailCheck);
}
);

function DuplicateEmailCheck()
{
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{email: '" + $('#&lt;%= txtEmail.ClientID %&gt;').val() + "'}",
dataType: "json",
url: "http://localhost:1561/TestWebService/Service.asmx/CheckEmail",
success: function(response)
{
$("#spErrorMessage").empty();
if (response.d != "0")
{
$("#spErrorMessage").html('Email address already exists.');
}
}
});

}
&lt;/script&gt;</pre>
<p>The first script section contains the reference to the latest jquery library till date. You can download it from internet very easily. The second script section does the real magic but its very easy. The first function just hooks the txtEmail textbox with the DuplicateEmailCheck function. The DuplicateEmailCheck function makes an ajax call to the web service which we created above. Now based on the result the span belonging to the textbox will be populated if email already exists.</p>
<p>Thats all folks, don&#8217;t forget to leave feedback/suggestions.</p>
<p>Cheers.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F04%2Fjquery-communicating-with-web-service-to-check-for-duplicate-emails%2F';
  addthis_title  = 'JQuery+Communicating+with+Web+Service+to+check+for+duplicate+emails';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/04/jquery-communicating-with-web-service-to-check-for-duplicate-emails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding server side sorting to ExtJS Grid using WebMethods in ASP.NET</title>
		<link>http://www.dottostring.com/2009/03/adding-server-side-sorting-to-extjs-grid-using-webmethods-in-aspnet/</link>
		<comments>http://www.dottostring.com/2009/03/adding-server-side-sorting-to-extjs-grid-using-webmethods-in-aspnet/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 08:03:01 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ExtJs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[serverside]]></category>
		<category><![CDATA[Sorting]]></category>
		<category><![CDATA[WebMethod]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=312</guid>
		<description><![CDATA[We will continue with the example in previous post:
On-Demand Paging using ExtJS Grid with Client-Centric ASP.NET AJAX (WebMethods)

First of all we will add config option sortable:true to all columns we want to be sortable
So, the grid code will look like this:

        // create the grid
    [...]]]></description>
			<content:encoded><![CDATA[<p>We will continue with the example in previous post:</p>
<p><a href="http://www.dottostring.com/2008/12/on-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods/">On-Demand Paging using ExtJS Grid with Client-Centric ASP.NET AJAX (WebMethods)</a></p>
<p><img class="aligncenter size-full wp-image-315" title="ExtJS Serverside Sorting Example" src="http://www.dottostring.com/wp-content/uploads/2009/03/extjs-serverside-sorting.jpg" alt="ExtJS Serverside Sorting Example" width="406" height="302" /></p>
<p>First of all we will add config option <code>sortable:true</code> to all columns we want to be sortable</p>
<p>So, the grid code will look like this:</p>
<pre name="code" class="js">
        // create the grid
        var grid = new Ext.grid.GridPanel({
            el:'grid-products',
            width:405,
            height:300,
            title:'Adventure Works Products',
            store: store,
            stripeRows: true,
            loadMask: true,
            enableHdMenu: false,

            // grid columns
            columns:[{
        	    header: "id",
        	    id: 'ProductID',
                dataIndex: 'ProductID',
                hidden:true
            },{
                header: "Product Name",
                dataIndex: 'Name',
                width: 200,
                sortable:true
            },{
                header: "Product Number",
                dataIndex: 'ProductNumber',
                width: 100,
                sortable:true
            },{
                header: "Safety Stock Level",
                dataIndex: 'SafetyStockLevel',
                width: 100
            }],
            // put paging bar on the bottom
            bbar: pagingBar
        });</pre>
<p>Now, you can sort the grid on client side. But this is sorting within a page only. We want to sort the grid for all products which can be achieved by server side sorting only.</p>
<p>Lets make it request the server for sorting. We have to add <code>remoteSort:true</code> to our JsonStore. So the JsonStore code will look like this:</p>
<pre name="code" class="js">// create the Data Store
        var store = new Ext.data.JsonStore({
            root: 'lstProducts',
            totalProperty: 'RowCount',
            idProperty: 'ProductID',
		    fields: [
                'Name','ProductID', 'ProductNumber', 'ReorderPoint','SafetyStockLevel'
            ],
            remoteSort:true,
            proxy:pmProxy
        });</pre>
<p>Now, all of sorting information will go with params to PageMethodProxy as:</p>
<ul>
<li><code>sort</code> having the id of the column</li>
<li><code>dir</code> for direction of sorting (it can have values <code>ASC</code> or <code>DESC</code>)</li>
</ul>
<p>We have to change the PageMethodProxy a little bit to forward this sorting information to WebMethod. After this our PageMethodProxy code will look like this:</p>
<pre name="code" class="js">Ext.data.PageMethodProxy = function(config){
	Ext.data.PageMethodProxy.superclass.constructor.call(this);
	Ext.apply(this, config);
};

Ext.data.PageMethodProxy.TRANS_ID = 1000;
Ext.data.PageMethodProxy.arr_trans = Array();

Ext.extend(Ext.data.PageMethodProxy, Ext.data.DataProxy, {
    load : function(params, reader, callback, scope, arg) {
        if(this.fireEvent("beforeload", this, params) !== false){
            var p = Ext.apply(params, this.extraParams);
            var transId = ++Ext.data.PageMethodProxy.TRANS_ID;
            var trans = {
                id : transId,
                params : params,
                arg : arg,
                callback : callback,
                scope : scope,
                reader : reader
            };
            if(typeof p.sort == "undefined")
                p.sort = "";
            if(typeof p.dir == "undefined")
                p.dir = "";

            eval("PageMethods." + this.pageMethod + "(p.start,p.limit,p.sort,p.dir,this.handleResponse)");

            Ext.data.PageMethodProxy.arr_trans[Ext.data.PageMethodProxy.TRANS_ID] = trans;
        }
        else{
            callback.call(scope||this, null, arg, false);
        }

    },	

    isLoading : function(){
        return this.trans ? true : false;
    },

    abort : function(){
        if(this.isLoading()){
            this.destroyTrans(this.trans);
        }
    },

    handleResponse : function(o){
        var trans = Ext.data.PageMethodProxy.arr_trans[Ext.data.PageMethodProxy.TRANS_ID];
        var result;
        try {
            result = trans.reader.readRecords(o);
        }catch(e){
            this.fireEvent("loadexception", this, o, trans.arg, e);
            trans.callback.call(trans.scope||window, null, trans.arg, false);
            return;
        }
        this.trans = false;
        trans.callback.call(trans.scope||window, result, trans.arg, true);
    }
});</pre>
<p>Notice that we have added check for undefined sorting parameters. This is the case when no sorting is applied. We have to handle this on client side.</p>
<p>Now finally add the sorting code to the WebMethod which will handle the sorting parameters. The Web Method code will look like this now</p>
<pre name="code" class="c#">
    [System.Web.Services.WebMethod]
    public static ProductList GetProducts(int PageNumber,int MaximumRows,string SortColumnName, string SortDirection)
    {
        //calculating the start row index
        int Start = PageNumber + 1;
        //calculating the end row index
        int End = PageNumber + MaximumRows;

        ProductList productList = new ProductList();
        //setting up sql connection to execute the query
        SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
        sqlConnection.Open();
        //setting up the command object with a parameterized query and sql connection
        using (SqlCommand command = new SqlCommand(GetQuery(SortColumnName,SortDirection), sqlConnection))
        {
            //Creating Sql Start Paramter
            SqlParameter StartParameter = new SqlParameter();
            StartParameter.DbType = DbType.Int32;
            StartParameter.ParameterName = "startRowIndex";
            StartParameter.Value = Start;
            //Creating Sql End Parameter
            SqlParameter EndParameter = new SqlParameter();
            EndParameter.DbType = DbType.Int32;
            EndParameter.ParameterName = "endRowIndex";
            EndParameter.Value = End;
            //Adding Start Parameter to the command object
            command.Parameters.Add(StartParameter);
            //Adding End Parameter to the command object
            command.Parameters.Add(EndParameter);
            //Executing Reader
            using (IDataReader reader = command.ExecuteReader())
            {
                //Creating a list of objects from the fetched rows
                while (reader.Read())
                {
                    productList.lstProducts.Add(ConstructProduct(reader));
                }
            }
        }
        //closing the connection
        sqlConnection.Close();
        //Assigning total row count for the given query so that it can
        //be used by the grid to set up total number of pages
        productList.RowCount = GetRowCount();
        return productList;
    }

    private static String GetQuery(String ColumnName,String SortDirection)
    {

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.Append(" SELECT * FROM ( ");
        if(!ColumnName.Trim().Equals(String.Empty) &#038;&#038; !SortDirection.Trim().Equals(String.Empty))
            stringBuilder.Append(" SELECT	ROW_NUMBER() OVER (ORDER BY "+ColumnName.Trim().ToUpper()+" "+ SortDirection.Trim().ToUpper()+") AS row_num,ProductID,[Name],ProductNumber,SafetyStockLevel,ReorderPoint ");
        else
            stringBuilder.Append(" SELECT	ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row_num,ProductID,[Name],ProductNumber,SafetyStockLevel,ReorderPoint ");
        stringBuilder.Append(" FROM	Product ");
        stringBuilder.Append(" ) AS TempTable WHERE row_num>=@startRowIndex AND row_num<=@endRowIndex ");
        return stringBuilder.ToString();
    }
</pre>
<p>And thats all. We have successfully added Server side sorting to our existing code. This will work with paging too.</p>
<p>You can download the complete project here:<a href='http://www.dottostring.com/wp-content/uploads/2009/03/dottostringextjs_grid_sorting.zip'>.toString() - ExtJS Serverside Grid Sorting</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F03%2Fadding-server-side-sorting-to-extjs-grid-using-webmethods-in-aspnet%2F';
  addthis_title  = 'Adding+server+side+sorting+to+ExtJS+Grid+using+WebMethods+in+ASP.NET';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/03/adding-server-side-sorting-to-extjs-grid-using-webmethods-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III</title>
		<link>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/</link>
		<comments>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 23:15:18 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET Controls]]></category>
		<category><![CDATA[AssociatedControlID]]></category>
		<category><![CDATA[BackColor]]></category>
		<category><![CDATA[BorderColor]]></category>
		<category><![CDATA[BorderStyle]]></category>
		<category><![CDATA[BorderWidth]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[CssClass]]></category>
		<category><![CDATA[Encode]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[ForeColor]]></category>
		<category><![CDATA[Label]]></category>
		<category><![CDATA[Literal Control]]></category>
		<category><![CDATA[Microsofto Visual Studio 2008]]></category>
		<category><![CDATA[Mode]]></category>
		<category><![CDATA[PassThrough]]></category>
		<category><![CDATA[runat]]></category>
		<category><![CDATA[runat="server"]]></category>
		<category><![CDATA[Standard Control]]></category>
		<category><![CDATA[Style]]></category>
		<category><![CDATA[ToolTip]]></category>
		<category><![CDATA[Transform]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=250</guid>
		<description><![CDATA[In this Part we are working with some of the Standard Controls in Details.
Standard Controls
Standard controls contain controls which help the developers to perform useful operations for example displaying information, taking user input in a textbox, displaying a drop down box, ListBox and many more. we will take look at some of them in detail.
Label [...]]]></description>
			<content:encoded><![CDATA[<p>In this Part we are working with some of the Standard Controls in Details.</p>
<h3>Standard Controls</h3>
<p>Standard controls contain controls which help the developers to perform useful operations for example displaying information, taking user input in a textbox, displaying a drop down box, ListBox and many more. we will take look at some of them in detail.</p>
<h4><span style="color: #000080;">Label Control</span></h4>
<p>label control is used when you need to dynamically display/change data on the webpage. we already saw a sample code in the last part (part 03) which changed text of the label dynamically on button&#8217;s click and TextBox&#8217;s TextChanged Event. There are plenty of Properties with which we play around with.</p>
<div id="attachment_251" class="wp-caption aligncenter" style="width: 204px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-property-panel.jpg"><img class="size-medium wp-image-251" title="ASP.NET Standard Controls - Label - Property Panel" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-property-panel-194x300.jpg" alt="ASP.NET Standard Controls - Label - Property Panel" width="194" height="300" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Property Panel</p></div>
<p>following are some of the most used properties witha  brief description</p>
<ul>
<li><strong>BackColor &#8211; </strong>sets the color of the background of the label control</li>
<li><strong>BorderColor &#8211; </strong>sets the color of the border of the label control</li>
<li><strong>BorderStyle &#8211; </strong>lets you set the style of the border e.g. <strong>NotSet, None, Dotted, Dashed, Solid, Double, Groove, Ridge, Inset, and Outset.</strong></li>
<li><strong>BorderWidth &#8211; </strong>lets you set the width of the border</li>
<li><strong>CssClass -</strong>lets you set CSS class for label.</li>
<li><strong>Font &#8211; </strong>lets you configure various font properties e.g <strong>Bold, Italic, Name, Names</strong>, <strong>Overline, Size, Strikeout, Underline</strong></li>
<li><strong>ForeColor &#8211; </strong>lets you<strong> </strong>set the color of the content of the label.</li>
<li><strong>ToolTip &#8211; </strong>lets you set the tool tip for the label control.</li>
<li><strong>Style &#8211; </strong>lets you set inline style attribute for the label control.</li>
</ul>
<p>now lets have a look at a sample which illustrates the use of these properties.</p>
<pre name="code" class="html">&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;[.toString()] Standard Controls - http://dottostring.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:Label ID="Label1"
            runat="server"
            Text="label text goes here"
            BackColor="#FF9966"
            BorderColor="Black"
            BorderStyle="Double"
            BorderWidth="2px"
            Font-Bold="True"
            Font-Italic="True"&gt;
            &lt;/asp:Label&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<ul>
<li>Run (F5) your website and this is what you will get:</li>
</ul>
<div id="attachment_258" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration.jpg"><img class="size-medium wp-image-258" title="ASP.NET Standard Controls - Label - Properties Demonstration" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-300x225.jpg" alt="ASP.NET Standard Controls - Label - Properties Demonstration" width="300" height="225" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Properties Demonstration</p></div>
<p>Labels are frequently used as the labels next to textbox fields in order to identify the information to be entered in those fields.  In order to associate a Label to a TextBox, Label has a property <strong>AssociatedControlID</strong>, setting this property doesn&#8217;t change anything as far as the display is concerned however when the label is clicked by the user it automatically takes the focus to the associated control.</p>
<p>Here is another sample which illustrates the use of <strong>AssociatedControlID </strong>and <strong>CssClass </strong>attributes.</p>
<pre name="code" class="html">&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;[.toString()] Standard Controls - http://www.dottostring.com&lt;/title&gt;
    &lt;style type="text/css"&gt;
        .LabelStyle {
            font-family: "Trebuchet MS";
            font-size: medium;
            font-weight: bold;
            color: #800000;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div &gt;
        &lt;asp:Label ID="Label1"
            runat="server"
            Text="label text goes here"
            BackColor="#FF9966"
            BorderColor="Black"
            BorderStyle="Double"
            BorderWidth="2px"
            Font-Bold="True"
            Font-Italic="True"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Label
            ID="lblProductName"
            runat="server"
            AssociatedControlID="txtProductName"
            Text="Product Name"
            CssClass="LabelStyle"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;asp:TextBox
            ID="txtProductName"
            runat="server"&gt;
            &lt;/asp:TextBox&gt;
        &lt;br /&gt;
        &lt;asp:Label
            ID="lblProductCode"
            runat="server"
            AssociatedControlID="txtProductCode"
            Text="Product Code"
            CssClass="LabelStyle"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;asp:TextBox
            ID="txtProductCode"
            runat="server"&gt;
            &lt;/asp:TextBox&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<ul>
<li>Run(F5) the website and see the results.</li>
</ul>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-ii.jpg"><img class="size-medium wp-image-259" title="ASP.NET Standard Controls - Label - Properties Demonstration II" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-ii-300x225.jpg" alt="ASP.NET Standard Controls - Label - Properties Demonstration II" width="300" height="225" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Properties Demonstration II</p></div>
<h4><span style="color: #000080;">Literal Control</span></h4>
<p>Literal Control is almost the same as the Label Control except for the fact that Literal Control does not render its content inside the Span Tag, you can use it to display text or HTML content. it simply outputs contents assigned to it. Like for example lets say we need to dynamically update the title of the page, this can be done either by  placing a <strong>runat=&#8221;server&#8221; </strong> and  <strong>ID </strong>attributes to the Title Tag and then modify it from the server side or we can simply place a <strong>Literal Control </strong>in the Title Tag and then assign the desired title text to the literal control from the server.</p>
<p>Literal Control possess a useful property called <strong>Mode, </strong>which can be set to one of the following properties.</p>
<ul>
<li><strong>PassThrough &#8211; </strong>Everything assigned to the Text Property is rendered as it is to the browser. for example <em>&#8220;&lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt;&#8221; </em> will print <em><strong>dottostring </strong></em>(in bold and italic)</li>
<li><strong>Transform &#8211; </strong>This will remove all the content from the Text Property of the Literal Control which is not supported by the browser/device it is rendering to. In case of HTML Browser this acts just like <strong>PassThrough</strong></li>
<li><strong>Encode &#8211; </strong>This will encode the all the tag so that they are displayed as it is to the viewer. for example <em>&#8220;&lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt;&#8221; </em> will print &lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt; to the user interface.</li>
</ul>
<p>as we dont have any span tag in the literal control rendered output, therefore we cannot apply any sort of formatting.</p>
<p>now lets look at some samples</p>
<ul>
<li>Add Two Literal Controls, one in the Title Tag and the other inside the body and name them <strong>lTitle </strong>and <strong>lContent </strong>respectively.</li>
<li>in the <strong>Page_Load </strong>Method add the following code.</li>
</ul>
<pre name="code" class="c#">protected void Page_Load(object sender, EventArgs e)
    {
        lTitle.Text = "[.toString()] Standard Controls - http://www.dottostring.com";
        lContent.Text = "&lt;b&gt;&lt;i&gt;dottostring&lt;/i&gt;&lt;/b&gt;";
    }</pre>
<ul>
<li>Run(F5) the application and notice the following results</li>
</ul>
<p> </p>
<div id="attachment_293" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-293" title="ASP.NET Standard Controls - Literal Control Demonstration" src="http://www.dottostring.com/wp-content/uploads/2009/02/aspnet-standard-controls-literal-control-demonstration-300x281.jpg" alt="ASP.NET Standard Controls - Literal Control Demonstration" width="300" height="281" /><p class="wp-caption-text">ASP.NET Standard Controls - Literal Control Demonstration</p></div>
<p>The Title of the page is what we set from the Page_Load Method dynamically and also we can see the other Literal Control which is rendered to display <strong>dottostring </strong> in below the two textboxes. also it is important to note that by Default the Mode Property for Literal Control is set to <strong>Transform</strong>, and since results are being redered to an HTML Browser, Transform and PassThrough will generate the same results, however when we change the <strong>IContent</strong>&#8217;s Mode Property to <strong>Encode </strong>it will also display the markup language on the user interface. effectively converting &#8220;&lt;&#8221; to &#8220;&amp;lt&#8221; and &#8220;&gt;&#8221; to &#8220;&amp;gt;&#8221;.</p>
<p> </p>
<div id="attachment_294" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-294" title="ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode" src="http://www.dottostring.com/wp-content/uploads/2009/02/aspnet-standard-controls-literal-control-demonstration-modeencode-300x281.jpg" alt="ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode" width="300" height="281" /><p class="wp-caption-text">ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode</p></div>
<p>we can clearly see the mark up language now. so Literal Control can be a very handy control in generating HTML content dynamically.</p>
<p>Thats it for this Part04, in this part we learned how to use some Standard Controls and what their important set of properties do. In the next part we will look at other Standard Controls which will enable us to make our interface much more user interactive.</p>
<ul>
<li>Thanks for visiting and waiting patiently for this part, I will be posting more regulary now, so keep in touch and don&#8217;t forget to leave comments/feedback</li>
<li><a rel="attachment wp-att-295" href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/dottostring-aspnet-tutorialspart04/">Download Source Code for Part04</a></li>
<li>Cheers !</li>
</ul>
<p>Previous Parts:</p>
<ul>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/" target="_self">ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5<br />
</a></li>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/" target="_self">ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I<br />
</a></li>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/" target="_self">ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II<br />
</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F02%2Faspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+04%5D+ASP.NET+3.5+Controls+and+Event+Handlers+III';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using extjs calendar control (DateField) in ASP.NET</title>
		<link>http://www.dottostring.com/2009/01/using-extjs-calendar-control-datefield-in-aspnet/</link>
		<comments>http://www.dottostring.com/2009/01/using-extjs-calendar-control-datefield-in-aspnet/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 21:36:49 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[ExtJs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Calendar Control]]></category>
		<category><![CDATA[DateField]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=268</guid>
		<description><![CDATA[There are lots of scenarios where you want to use a nice calendar control, without changing server side logic. This short tutorial will enable you to use extjs DateField in ASP.NET as a calendar control and get the value of user input as DateTime object on server side. With extjs DateField you can apply validations, [...]]]></description>
			<content:encoded><![CDATA[<p>There are lots of scenarios where you want to use a nice calendar control, without changing server side logic. This short tutorial will enable you to use extjs DateField in ASP.NET as a calendar control and get the value of user input as DateTime object on server side. With extjs DateField you can apply validations, restrict certain dates, set default date or change it in any way you want.</p>
<p><img class="aligncenter size-full wp-image-269" title="extjs calendar control in ASP.NET" src="http://www.dottostring.com/wp-content/uploads/2009/01/extjs-calendar-aspnet.png" alt="extjs calendar control in ASP.NET" width="207" height="232" /></p>
<p>We start with adding a textbox and a button (We will be converting this textbox to calendar control):</p>
<pre name="code" class="html">
<div id="calendarContainer">
    <asp:TextBox ID="txtCalendar" runat="server" rel="calendar"></asp:TextBox>
</div>

<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</pre>
<p>Notice that we are using <code>rel="calendar"</code> here. We do not want to use name or id attribute here because using a master page, we cannot predict client side id or name of the control. Using rel we can safely select multiple controls on client side.</p>
<p>Now we write our javascript. First of all, select all TextBoxes having <code>rel="calendar"</code> using <code>DomQuery</code>:</p>
<pre name="code" class="js">
        Ext.onReady(function(){
            var textBoxes = Ext.DomQuery.select("input[rel=calendar]");
        });
</pre>
<p>Now loop through each TextBox and convert them to extjs DateField</p>
<pre name="code" class="js">
        Ext.onReady(function(){
            var textBoxes = Ext.DomQuery.select("input[rel=calendar]");
            Ext.each(textBoxes, function(item, id, all){
                var cl = new Ext.form.DateField({
                    allowBlank : false,
                    applyTo: item
                });
            });
        });
</pre>
<p>And thats all <img src='http://www.dottostring.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now you can get the value of selected date on server side like this:</p>
<pre name="code" class="csharp">
DateTime.Parse(txtCalendar.Text);
</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F01%2Fusing-extjs-calendar-control-datefield-in-aspnet%2F';
  addthis_title  = 'Using+extjs+calendar+control+%28DateField%29+in+ASP.NET';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/01/using-extjs-calendar-control-datefield-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II</title>
		<link>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/</link>
		<comments>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 15:06:27 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET Controls]]></category>
		<category><![CDATA[Creating New Website]]></category>
		<category><![CDATA[Event Handlers]]></category>
		<category><![CDATA[Microsofto Visual Studio 2008]]></category>
		<category><![CDATA[On Click]]></category>
		<category><![CDATA[runat]]></category>
		<category><![CDATA[runat="server"]]></category>
		<category><![CDATA[Text Changed Event]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=225</guid>
		<description><![CDATA[In the last part (part 02) I gave you an overview of ASP.NET 3.5 Controls and their Event Handlers, in this part I will put forward some samples codes.
Creating an ASP.NET Website

Open Microsoft Visual Studio 2008
Create a new ASP.NET website (File &#8211; &#62; New &#8211; &#62; Website)



Provide the location and name for your website.
From the [...]]]></description>
			<content:encoded><![CDATA[<p>In the last part (part 02) I gave you an overview of ASP.NET 3.5 Controls and their Event Handlers, in this part I will put forward some samples codes.</p>
<h3>Creating an ASP.NET Website</h3>
<ul>
<li>Open Microsoft Visual Studio 2008</li>
<li>Create a new ASP.NET website (File &#8211; &gt; New &#8211; &gt; Website)</li>
</ul>
<p style="text-align: center;">
<div id="attachment_226" class="wp-caption aligncenter" style="width: 488px"><img class="size-full wp-image-226" title="My First Website - Create New Website" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-create-new-website.jpg" alt="My First Website - Create New Website" width="478" height="316" /><p class="wp-caption-text">My First Website - Create New Website</p></div>
<ul>
<li>Provide the location and name for your website.</li>
<li>From the Language drop down you can select the language of your choice (I will be using C# throughout all my articles).</li>
<li>Pressing OK, will create a website project for you and by default it already has a Default.aspx page added to it.</li>
</ul>
<p>Switch to Split View of the Default Page and drag and drop a Label, TextBox and Button Control on the interface such that it looks something like this.</p>
<div id="attachment_227" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-sample-default-page.jpg"><img class="size-medium wp-image-227" title="My First Website - Sample Default Page" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-sample-default-page-300x194.jpg" alt="My First Website - Sample Default Page" width="300" height="194" /></a><p class="wp-caption-text">My First Website - Sample Default Page</p></div>
<p>lets look at the declaration of these controls.</p>
<p>&lt;asp:Label ID=&#8221;lblmyLabel&#8221; runat=&#8221;server&#8221;&gt;&lt;/asp:Label&gt;<br />
&lt;asp:TextBox ID=&#8221;txtmyTextBox&#8221; runat=&#8221;server&#8221;&gt;&lt;/asp:TextBox&gt;<br />
&lt;asp:Button ID=&#8221;btnmyButton&#8221; runat=&#8221;server&#8221; Text=&#8221;Click&#8221; /&gt;</p>
<p>all of the ASP.NET Controls have the following characteristics</p>
<ul>
<li> Tag Element starting with <strong>asp:</strong> <em>( with the exception of HTML Controls )</em></li>
<li>Each tag (ASP.NET Control tag) has an attribute <strong>runat=&#8221;server&#8221;</strong> which indicates to the framework that this control needs to be rendered at the server side.<em> (HTML Controls can have this attribute only if you need to access it in the server side code)</em></li>
<li><strong>ID </strong>attribute in the declaration of the ASP.NET Control identifies it, once defined, these controls can be accessed on the server side with these IDs.(I have already given controls appropriate IDs)</li>
</ul>
<p>Now lets add a click event to the button we have on the page, to do that select the button and the look for <strong>Properties Panel</strong> on the right bottom of the VS Interface ( if you cannot see the properties panel, <strong>Press F4</strong>). everything you see in this panel are the properties of the control you have selected and you can modify them here. For now we are interested in adding a Click Event, Select  Events Tab in the properties panel.</p>
<div id="attachment_228" class="wp-caption aligncenter" style="width: 382px"><img class="size-full wp-image-228" title="My First Website - Properties Panel - Button Events" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-button-events.jpg" alt="My First Website - Properties Panel - Button Events" width="372" height="332" /><p class="wp-caption-text">My First Website - Properties Panel - Button Events</p></div>
<p>you can see there are number of Button events available, but by default no events is placed. To add an event, lets say Click Event, we need to double click the space in front of the Click Label, this will add a Button Click Event handler in the Code File of the Default.aspx. This is how your code-behind file for this page would look like with a Button Click Event Handler.</p>
<pre name="code" class="c#">using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnmyButton_Click(object sender, EventArgs e)
    {

    }
}</pre>
<p><strong>btnmyButton_Click </strong>Event will occur everytime when <strong>btnmyButton</strong> is clicked. now lets Append <strong>&#8220;Hello&#8221; </strong>to the Label (lblmyLabel) Text everytime this button is clicked.</p>
<pre name="code" class="c#">    protected void btnmyButton_Click(object sender, EventArgs e)
    {
        lblmyLabel.Text += "Hello ";
    }</pre>
<ul>
<li>Run (F5) the website and click on the Button more than one time and see what happens. (Note: for the very first time  a Message Box will appear once you Run (F5) your website asking whether to enable debugging or not, Press Yes/Ok)</li>
</ul>
<div id="attachment_233" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-button-click-event-handler-demonstration.jpg"><img class="size-medium wp-image-233" title="My First Website - Button Click Event Handler Demonstration" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-button-click-event-handler-demonstration-300x225.jpg" alt="My First Website - Button Click Event Handler Demonstration" width="300" height="225" /></a><p class="wp-caption-text">My First Website - Button Click Event Handler Demonstration</p></div>
<p>now this is how we can perform different kind of operations, for example manipulating certain information from a form to the database. similarly we have <strong>TextChanged </strong>Event available for the TextBox control, lets say we require that, whatever is written in the textbox is appended to the label whenever textbox loses focus, All we need to do is select mytxtTextBox control we dropped earlier on the page and add its TextChanged Event Handler like the way we added Button&#8217;s Click Event.</p>
<pre name="code" class="c#">using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnmyButton_Click(object sender, EventArgs e)
    {
        lblmyLabel.Text += "Hello ";
    }
    protected void txtmyTextBox_TextChanged(object sender, EventArgs e)
    {
        lblmyLabel.Text += txtmyTextBox.Text;
    }
}</pre>
<p>just the way on the click of the button there was a post back to the server so that text could be appended to the label, TextBoxes by default are set not to post back on any event, we have to explicitly enable post back by enabling <strong>AutoPostBack</strong> property of the<strong> txtmyTextBox.</strong></p>
<div id="attachment_236" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-autopostback-property.jpg"><img class="size-medium wp-image-236" title="My First Website - Properties Panel - AutoPostBack Property" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-autopostback-property-300x245.jpg" alt="My First Website - Properties Panel - AutoPostBack Property" width="300" height="245" /></a><p class="wp-caption-text">My First Website - Properties Panel - AutoPostBack Property</p></div>
<p>this will make the TextBox postback to the server on <strong>TextChanged </strong>Event.</p>
<ul>
<li>Now Run(F5) the website again</li>
<li>Enter some text in the textbox and click out side the textbox, this will make the textbox lose focus and subsequently will post back to the server and call the TextChanged Event Handler and our text will appended in the label above.</li>
</ul>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-textboxs-textchanged-event-handler-demonstration.jpg"><img class="size-medium wp-image-238" title="My First Website - TextBox's TextChanged Event Handler Demonstration" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-textboxs-textchanged-event-handler-demonstration-300x225.jpg" alt="My First Website - TextBox's TextChanged Event Handler Demonstration" width="300" height="225" /></a><p class="wp-caption-text">My First Website - TextBox&#39;s TextChanged Event Handler Demonstration</p></div>
<p>this brings us to the end of Part 03. In this part we learned How ASP.NET Controls and Event Handlers are used in ASP.NET Websites, in the upcoming parts we shall look into Controls in each Category in detail, discovering various properties and events associated with them.</p>
<ul>
<li>Thanks for Visiting, don&#8217;t forget to let us know how did this article helped you.</li>
<li><a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostring-aspnet-tutorialspart03.zip">Download Source Code  for Part 03</a></li>
<li>Cheers!</li>
</ul>
<p>Proceed to:</p>
<ul>
<li><a href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/" target="_self">ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III<br />
	</a>
	</li>
</ul>
<p>Previous Parts:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/" target="_self">ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5</a></li>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/" target="_self">ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Faspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+03%5D+ASP.NET+3.5+Controls+and+Event+Handlers+II';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I</title>
		<link>http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/</link>
		<comments>http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 17:18:48 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET Controls]]></category>
		<category><![CDATA[.NET Framework 3.5]]></category>
		<category><![CDATA[AJAX Extensions]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET 3.5 Controls]]></category>
		<category><![CDATA[ASP.NET Event Handlers]]></category>
		<category><![CDATA[Data Controls]]></category>
		<category><![CDATA[Event Handlers]]></category>
		<category><![CDATA[Login Controls]]></category>
		<category><![CDATA[Navigation Controls]]></category>
		<category><![CDATA[Standard Controls]]></category>
		<category><![CDATA[Validation Controls]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WebParts Controls]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=211</guid>
		<description><![CDATA[In part 1 we talked about ASP.NET and .NET Framework 3.5 in general and got accross some of the very basic concepts of .net technology. now we move on to ASP.NET Controls often termed as the heart of the .NET Framework.
There are around 70+ Controls in ASP.NET Framework and are categorized as follows.

Standard Controls
Data Controls
Validation [...]]]></description>
			<content:encoded><![CDATA[<p>In part 1 we talked about ASP.NET and .NET Framework 3.5 in general and got accross some of the very basic concepts of .net technology. now we move on to <strong>ASP.NET Controls</strong> often termed as the heart of the .NET Framework.</p>
<p>There are around <strong>70+ Controls in ASP.NET Framework</strong> and are categorized as follows.</p>
<ul>
<li>Standard Controls</li>
<li>Data Controls</li>
<li>Validation Controls</li>
<li>Navigation Controls</li>
<li>Login Controls</li>
<li>WebParts Controls</li>
<li>HTML Controls</li>
<li>AJAX Extentions</li>
</ul>
<p><strong>Standard Controls &#8211; </strong>as the name suggests this category contains all the basic controls in order to fullfil the web interface related requirements such as text boxes, hyperlinks, buttons, tables and many more.</p>
<p><strong>Data Controls &#8211; </strong>A number of useful data controls are available for the developer to easily communicate with database and efficiently display them to the end user. GridView, ObjectDataSource, Repeater are few of the most popular data controls.</p>
<p><strong>Validation Controls</strong> -  these controls come in very handy when we need to apply any sort of validations on the standard controls such as Required field validation on Textbox, Data Type validation, Regular Expression Match and many others.</p>
<p><strong>Navigation Controls &#8211; </strong>navigation controls make things very comfortable when it comes to manage navigation of your website for example generating SiteMaps, Menus and TreeView.</p>
<p><strong>Login Controls &#8211; </strong>these controls are there to be used whenever you need to implement security to your website, they enable you to display login, change password and registration forms.</p>
<p><strong>WebParts Controls &#8211; </strong> these controls enable end users to modify the content, appearance, and behavior of Web pages in the web browser itself.</p>
<p><strong>HTML Controls -</strong> these are standard HTML controls such as textboxes, anchor, checkboxes and any other HTML control you would know. it also gives the ability to convert any HTML tag into a server control.</p>
<p><strong>AJAX Extensions &#8211; </strong>this category contains some very helpful AJAX related controls which enables AJAX on  your pages magically ( well seems like magic ), for example if you want to change text of some label on the web page by a button&#8217;s click event using AJAX (without posting the entire page back) all you need to do is put that label and button in a UpdatePanel and that&#8217;s just about it!</p>
<p>we will learn about each of them in the detail in the later parts.</p>
<h3>Event Handlers</h3>
<p>Almost all of the ASP.NET controls provides one or more Events to support the idea of event driven web application. for example if you want that on a certain click of a button a text should change on the web page would require a Click Event of the Button to be raised when clicked and subsequently changing the text of the label placed somewhere on the page.</p>
<p>the code below demonstrates this example</p>
<pre name="code" class="html">&lt;%@ Page Language="C#" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;script runat="server"&gt;

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "Button has been Clicked";
    }
&lt;/script&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;DotToString - My First Website&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:Label ID="lblMessage" runat="server" Text="Click on the Button Below" &gt;&lt;/asp:Label&gt;&lt;br /&gt;
        &lt;asp:Button ID="btnSubmit" runat="server" Text="Click"
            onclick="btnSubmit_Click" /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>In this example Two ASP.NET controls are used,  Label and Button. I have placed an onclick event which is handled by btnSubmit_Click Event Handler to change the text of the Label control.</p>
<p>In the part 3 I will demonstrate some samples codes (using Microsoft Visual Studio 2008) which will further elaborate the use of ASP.NET Controls and their Event Handlers.</p>
<p>keep visiting and don&#8217;t forget to leave feedback.</p>
<p>Cheers!</p>
<p>Proceed to:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/" target="_self">ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II</a></li>
<li>
	<a href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/" target="_self">ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III<br />
	</a>
	</li>
</ul>
<p>Previous Parts:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/" target="_self">ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Faspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+02%5D+ASP.NET+3.5+Controls+and+Event+Handlers+I';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5</title>
		<link>http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/</link>
		<comments>http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 21:17:31 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET Framework 3.5]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Assemblies]]></category>
		<category><![CDATA[Common Runtime Language (CLR)]]></category>
		<category><![CDATA[Namespaces]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=199</guid>
		<description><![CDATA[ASP.NET is increasingly becoming the reference point of development around the globe and alot of credit goes to Microsoft&#8217;s aggresive strategy to make things very simple for the developer subsequently supporting Rapid Application Development (RAD). To achieve all of this Microsoft puts in quite a lot of energy in improving Microsoft Visual Studio.
Microsoft Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET is increasingly becoming the reference point of development around the globe and alot of credit goes to Microsoft&#8217;s aggresive strategy to make things very simple for the developer subsequently supporting Rapid Application Development (RAD). To achieve all of this Microsoft puts in quite a lot of energy in improving Microsoft Visual Studio.</p>
<p>Microsoft Visual Studio 2008 is a developer&#8217;s heaven, it strives hard to take care of all the dirty work which otherwise a developer would have to waste time on and encourages him to concentrate on the Business Details. following are some of the handy features VS 2008 has to offer.</p>
<ul>
<li><strong>LINQ Support and Designer</strong></li>
<li><strong>Windows Presentation Foundation</strong></li>
<li><strong>VS 2008 Support for different .NET Framework Versions</strong></li>
<li><strong>AJAX support for ASP.NET</strong></li>
<li><strong>JavaScript Debugging</strong></li>
<li><strong>Nested Master Page</strong></li>
<li><strong>Built In Silverlight Library</strong></li>
</ul>
<p>before we dive into writing code for our first ASP.NET Sample Page, lets look at some of basic terms which you will come across frequently as we move ahead.</p>
<h4>Namespaces</h4>
<p>There are around <strong>13,000 Classes in .NET Framework</strong>, which is an overwhelming number and for obvious reasons needs some sort of management, just like we can have different closets for clothes that belong to summer and winter seasons so that we have everything organized. Similarly .NET Framework has Namespaces which is used to group all the relevant classes under a single Namespace which leads to better organization classes.</p>
<p>for example all the classes relevant to File Operations is categorized under the namespace <strong>System.IO </strong>and Mail Related Classes in <strong>System.Net.Mail</strong>.</p>
<p>you have to import Namespaces before you use any of the classes available in that particular Namespace (or provide a complete reference to the class including Namespace), however following is the a list of Namespaces which are already included in an ASP.NET Project and you dont have to reference them explicitly.</p>
<ul>
<li>System</li>
<li>System.Collections</li>
<li>System.Collections.Specialized</li>
<li>System.Configuration</li>
<li>System.Text</li>
<li>System.Text.RegularExpressions</li>
<li>System.Web</li>
<li>System.Web.Caching</li>
<li>System.Web.SessionState</li>
<li>System.Web.Security</li>
<li>System.Web.Profile</li>
<li>System.Web.UI</li>
<li>System.Web.UI.WebControls</li>
<li>System.Web.UI.WebControls.WebParts</li>
<li>System.Web.UI.HTMLControls</li>
</ul>
<p>you might be wondering how? the global web configuration file has the reference to all of these in the Framework directory.</p>
<h4>Assemblies</h4>
<p>Assembly is a compiled form of a particular set of .NET code/classes. its extension is .dll. There are two forms of Assemblies, Shared and Private. As the names would suggest Shared Assemblies are there to be used by every .NET application and resides in Global Assembly Cache (GAC) and Private Assemblies are used by .NET Applications which explicitly adds them to their development/production environtment.</p>
<h4>ASP.NET 3.5</h4>
<p>ASP.NET 3.5 broadly speaking is a technology used to build interactive data driven Web Applications. Apart from conventional HTML Elements used in any other scripting language, ASP.NET Server Control are the heart of ASP.NET 3.5, it contains text boxes, buttons, images, and data grids and numerous other server side controls which when used in combination with C#.NET/VB.NET is rendered by the .NET Framework to generate equivalent HTML for the client browser.</p>
<h4>.NET Framework 3.5</h4>
<p>.NET Framework 3.5 can be looked as layers of code which work in a modular fashion between underlying Operating System and your program. <strong>Common Runtine Language (CLR)</strong> is a huge and essential component of .NET Framework and responsible for the execution of your application code.</p>
<h4>Common Runtime Language (CLR)</h4>
<p>Common Runtime Language (CLR) is solely responsible for the execution of your program.All of your application code be it in C# or VB is converted to a special language called <strong>Microsoft Intermediate Language (MSIL).</strong> MSIL is a low-level and platform independent language and is not CPU Specific.</p>
<p>MSIL is then further compiled into machine code by <strong>JITTER (The Just-In-Time Compiler)</strong> and is then executed. .NET Framework only understands MSIL and includes compilers for supported languages like C#.NET and VB.NET. So practically speaking you can write program code in any language as long as it can compile into MSIL.</p>
<p>This brings us to the end of the part 1. we will be turning our attention to ASP.NET Controls and their Event Handlers in the next part.</p>
<p>keep visiting and don&#8217;t forget to leave feedback</p>
<p>Cheers!</p>
<p>Proceed to:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/" target="_self">ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I</a></li>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/" target="_self">ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II</a></li>
<li>
	<a href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/" target="_self">ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III<br />
	</a>
	</li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Faspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+01%5D+A+peek+into+ASP.NET+and+.NET+Framework+3.5';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>On-Demand Paging using ExtJS Grid with Client-Centric ASP.NET AJAX (WebMethods)</title>
		<link>http://www.dottostring.com/2008/12/on-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods/</link>
		<comments>http://www.dottostring.com/2008/12/on-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 00:51:03 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ExtJs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Client Centric]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[javscript]]></category>
		<category><![CDATA[On Demand Paging]]></category>
		<category><![CDATA[Web Method]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=181</guid>
		<description><![CDATA[We have a scenario where we want to use on demand paging for ExtJS grid using some smart AJAX techniques. One method could be to use default functionality of ExtJS grid with ExtJS PagingToolbar in its bottom bar; and ExtJS store associated with this grid is using httpProxy to fetch data. This httpProxy requires a url of [...]]]></description>
			<content:encoded><![CDATA[<p>We have a scenario where we want to use on demand paging for ExtJS grid using some smart AJAX techniques. One method could be to use default functionality of ExtJS grid with ExtJS PagingToolbar in its bottom bar; and ExtJS store associated with this grid is using httpProxy to fetch data. This httpProxy requires a url of aspx page only and it will fetch data from this page. This seems quite easy but there are some issues with this technique. We dont want the Page_Load method to be called every time creating a complete page on server side. Other way is to use WebMethods which are quite efficient. But ExtJS has no proxy for Page Methods. In this tutorial we will be creating a PageMethodProxy extended from DataProxy of ExtJS and will use it with JsonStore of ExtJS. Lets start:</p>
<div id="attachment_190" class="wp-caption aligncenter" style="width: 417px"><img class="size-full wp-image-190" title="EXTJS-ASP-NET-ON-DEMAND-PAGING" src="http://www.dottostring.com/wp-content/uploads/2008/12/extjs-asp-net-paging.jpg" alt="An Illustration of On-Demand Paging Using EXTJS Grid and ASP.NET" width="407" height="304" /><p class="wp-caption-text">An Illustration of On-Demand Paging Using EXTJS Grid and ASP.NET</p></div>
<p>Lets start by creating a PageMethod which takes page index and number of required results on a page as parameter and returns an object of ProductList type.</p>
<pre name="code" class="c#">using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// &lt;summary&gt;
    /// This method will be called from the client side using PageMethods
    /// and its primary responsibility is to fetch records from the database
    /// using that startRowIndex and MaximumRows allowed
    /// &lt;/summary&gt;
    /// &lt;param name="PageNumber"&gt;Page Number of the grid&lt;/param&gt;
    /// &lt;param name="MaximumRows"&gt;Page Size&lt;/param&gt;
    /// &lt;returns&gt;Rows in the form of a list&lt;/returns&gt;
    [System.Web.Services.WebMethod]
    public static ProductList GetProducts(int PageNumber,int MaximumRows)
    {
        //calculating the start row index
        int Start = PageNumber + 1;
        //calculating the end row index
        int End = PageNumber + MaximumRows;
        ProductList productList = new ProductList();
        //setting up sql connection to execute the query
        SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
        sqlConnection.Open();
        //setting up the command object with a parameterized query and sql connection
        using (SqlCommand command = new SqlCommand(GetQuery(), sqlConnection))
        {
            //Creating Sql Start Paramter
            SqlParameter StartParameter = new SqlParameter();
            StartParameter.DbType = DbType.Int32;
            StartParameter.ParameterName = "startRowIndex";
            StartParameter.Value = Start;
            //Creating Sql End Parameter
            SqlParameter EndParameter = new SqlParameter();
            EndParameter.DbType = DbType.Int32;
            EndParameter.ParameterName = "endRowIndex";
            EndParameter.Value = End;
            //Adding Start Parameter to the command object
            command.Parameters.Add(StartParameter);
            //Adding End Parameter to the command object
            command.Parameters.Add(EndParameter);
            //Executing Reader
            using (IDataReader reader = command.ExecuteReader())
            {
                //Creating a list of objects from the fetched rows
                while (reader.Read())
                {
                    productList.lstProducts.Add(ConstructProduct(reader));
                }
            }
        }
        //closing the connection
        sqlConnection.Close();
        //Assigning total row count for the given query so that it can
        //be used by the grid to set up total number of pages
        productList.RowCount = GetRowCount();
        return productList;
    }
    /// &lt;summary&gt;
    /// Builds the Actual Parameterized Query which handles On-Demand Paging using
    /// ROW_NUMBER() feature given by SQL Server 2005
    /// &lt;/summary&gt;
    /// &lt;returns&gt;Parameterized Query&lt;/returns&gt;
    private static String GetQuery()
    {

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.Append(" SELECT * FROM ( ");
        stringBuilder.Append(" SELECT	ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row_num,ProductID,[Name],ProductNumber,SafetyStockLevel,ReorderPoint ");
        stringBuilder.Append(" FROM	Product ");
        stringBuilder.Append(" ) AS TempTable WHERE row_num&gt;=@startRowIndex AND row_num&lt;=@endRowIndex ");
        return stringBuilder.ToString();
    }
    /// &lt;summary&gt;
    /// Builds the Query such that it return the count of the
    /// total number of account the query will select without
    /// paging
    /// &lt;/summary&gt;
    /// &lt;returns&gt;Query to return total number of records&lt;/returns&gt;
    private static String GetRowCountQuery()
    {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.Append(" SELECT COUNT(*) FROM ( ");
        stringBuilder.Append(" SELECT	ProductID,[Name],ProductNumber,SafetyStockLevel,ReorderPoint ");
        stringBuilder.Append(" FROM	Product ");
        stringBuilder.Append(" ) AS TempTable");
        return stringBuilder.ToString();
    }
    /// &lt;summary&gt;
    /// Executes the Actual Query without paging in order to
    /// fetch total number of records
    /// &lt;/summary&gt;
    /// &lt;returns&gt;Total Number of records&lt;/returns&gt;
    private static int GetRowCount()
    {
        int rowCount;
        SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
        sqlConnection.Open();
        using (SqlCommand command = new SqlCommand(GetRowCountQuery(), sqlConnection))
        {
            rowCount = Convert.ToInt32(command.ExecuteScalar());
        }
        sqlConnection.Close();
        return rowCount;

    }
    /// &lt;summary&gt;
    /// Constructs Product Entity from the IDataReaer
    /// &lt;/summary&gt;
    /// &lt;param name="reader"&gt;Reader (Already Executed)&lt;/param&gt;
    /// &lt;returns&gt;Product Entity&lt;/returns&gt;
    private static Product ConstructProduct(IDataReader reader)
    {
        Product product = new Product();

        int i = reader.GetOrdinal("ProductID");
        if (!reader.IsDBNull(i))
            product.ProductID = reader.GetInt32(i);
        i = reader.GetOrdinal("Name");
        if (!reader.IsDBNull(i))
            product.Name = reader.GetString(i);
        i = reader.GetOrdinal("ProductNumber");
        if (!reader.IsDBNull(i))
            product.ProductNumber = reader.GetString(i);
        i = reader.GetOrdinal("SafetyStockLevel");
        if (!reader.IsDBNull(i))
            product.SafetyStockLevel = Convert.ToInt32(i);
        i = reader.GetOrdinal("ReorderPoint");
        if (!reader.IsDBNull(i))
            product.ReorderPoint = Convert.ToInt32(i);

        return product;
    }
}</pre>
<p>Now we include our magical PageMethodProxy on our page.</p>
<pre name="code" class="js">Ext.data.PageMethodProxy = function(config){
	Ext.data.PageMethodProxy.superclass.constructor.call(this);
	Ext.apply(this, config);
};

Ext.data.PageMethodProxy.TRANS_ID = 1000;
Ext.data.PageMethodProxy.arr_trans = Array();

Ext.extend(Ext.data.PageMethodProxy, Ext.data.DataProxy, {
    load : function(params, reader, callback, scope, arg) {
        if(this.fireEvent("beforeload", this, params) !== false){

            var p = Ext.apply(params, this.extraParams);

            var transId = ++Ext.data.PageMethodProxy.TRANS_ID;
            var trans = {
                id : transId,
                params : params,
                arg : arg,
                callback : callback,
                scope : scope,
                reader : reader
            };

            eval("PageMethods." + this.pageMethod + "(p.start,p.limit,this.handleResponse)");

            Ext.data.PageMethodProxy.arr_trans[Ext.data.PageMethodProxy.TRANS_ID] = trans;
        }
        else{
            callback.call(scope||this, null, arg, false);
        }

    },	

    isLoading : function(){
        return this.trans ? true : false;
    },

    abort : function(){
        if(this.isLoading()){
            this.destroyTrans(this.trans);
        }
    },

    handleResponse : function(o){
        var trans = Ext.data.PageMethodProxy.arr_trans[Ext.data.PageMethodProxy.TRANS_ID];
        var result;
        try {
            result = trans.reader.readRecords(o);
        }catch(e){
            this.fireEvent("loadexception", this, o, trans.arg, e);
            trans.callback.call(trans.scope||window, null, trans.arg, false);
            return;
        }
        this.trans = false;
        trans.callback.call(trans.scope||window, result, trans.arg, true);
    }
});</pre>
<p>You should have following three Javascripts on your page.</p>
<pre name="code" class="html">&lt;script type="text/javascript" src="extjs/adapter/ext/ext-base.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="extjs/ext-all-debug.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="extjs/pagemethods-proxy.js"&gt;&lt;/script&gt;</pre>
<p>We start by making an object of our PageMethodProxy in Ext.onReady</p>
<pre name="code" class="js">Ext.onReady(function(){
    // lets make an object of pagemethod proxy first
    var pmProxy = new Ext.data.PageMethodProxy({
	    pageMethod: 'GetProducts'
    });
});</pre>
<p>Now we make a JsonStore which uses the object of this proxy and specifies properties of Json.</p>
<pre name="code" class="js">Ext.onReady(function(){
    // lets make an object of pagemethod proxy first
    var pmProxy = new Ext.data.PageMethodProxy({
	    pageMethod: 'GetProducts'
    });

    // create the Data Store
    var store = new Ext.data.JsonStore({
        root: 'lstProducts',
        totalProperty: 'RowCount',
        idProperty: 'ProductID',
	    fields: [
            'Name','ProductID', 'ProductNumber', 'ReorderPoint','SafetyStockLevel'
        ],
        proxy:pmProxy
    });
});</pre>
<p>Make a PagingToolbar object to be used in grid.</p>
<pre name="code" class="js">Ext.onReady(function(){
    // lets make an object of pagemethod proxy first
    var pmProxy = new Ext.data.PageMethodProxy({
	    pageMethod: 'GetProducts'
    });

    // create the Data Store
    var store = new Ext.data.JsonStore({
        root: 'lstProducts',
        totalProperty: 'RowCount',
        idProperty: 'ProductID',
	    fields: [
            'Name','ProductID', 'ProductNumber', 'ReorderPoint','SafetyStockLevel'
        ],
        proxy:pmProxy
    });

    // create paging bar
    var pagingBar = new Ext.PagingToolbar({
        pageSize: 10,
        store: store,
        emptyMsg: "No topics to display"
    });
});</pre>
<p>At the end create a grid placeholder div and create the grid object.</p>
<pre name="code" class="js">Ext.onReady(function(){
    // lets make an object of pagemethod proxy first
    var pmProxy = new Ext.data.PageMethodProxy({
	    pageMethod: 'GetProducts'
    });

    // create the Data Store
    var store = new Ext.data.JsonStore({
        root: 'lstProducts',
        totalProperty: 'RowCount',
        idProperty: 'ProductID',
	    fields: [
            'Name','ProductID', 'ProductNumber', 'ReorderPoint','SafetyStockLevel'
        ],
        proxy:pmProxy
    });

    // create paging bar
    var pagingBar = new Ext.PagingToolbar({
        pageSize: 10,
        store: store,
        emptyMsg: "No topics to display"
    });

    // create the grid
    var grid = new Ext.grid.GridPanel({
        el:'grid-products',
        width:405,
        height:300,
        title:'Adventure Works Products',
        store: store,
        stripeRows: true,
        loadMask: true,
        enableHdMenu: false,

        // grid columns
        columns:[{
    	    header: "id",
    	    id: 'ProductID',
            dataIndex: 'ProductID',
            hidden:true
        },{
            header: "Product Name",
            dataIndex: 'Name',
            width: 200
        },{
            header: "Product Number",
            dataIndex: 'ProductNumber',
            width: 100
        },{
            header: "Safety Stock Level",
            dataIndex: 'SafetyStockLevel',
            width: 100
        }],
        // put paging bar on the bottom
        bbar: pagingBar
    });

    grid.render();

    // set parameters for initial loading
    store.load({
	    params:{
		    start:0,
		    limit:10
	    }
    });
});</pre>
<ul>
<li>And thats all <img src='http://www.dottostring.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Cheers, don&#8217;t forget to leave comments/feedback</li>
<li>Download Source Code <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringon-demand-paging-ext-js-asp-net.zip" target="_blank">Here</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Fon-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods%2F';
  addthis_title  = 'On-Demand+Paging+using+ExtJS+Grid+with+Client-Centric+ASP.NET+AJAX+%28WebMethods%29';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/on-demand-paging-using-extjs-grid-with-client-centric-asp-dot-net-ajax-webmethods/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET &#8211; How to Stop/Start the Ticker on Mouse Hover/Leave</title>
		<link>http://www.dottostring.com/2008/12/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-c-sharp-net-how-to-stopstart-the-ticker-on-mouse-hoverleave/</link>
		<comments>http://www.dottostring.com/2008/12/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-c-sharp-net-how-to-stopstart-the-ticker-on-mouse-hoverleave/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 08:29:05 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[ManualResetEvent]]></category>
		<category><![CDATA[Message Smooth Scrolling]]></category>
		<category><![CDATA[Message Ticker]]></category>
		<category><![CDATA[Mouse Hover Leave Events]]></category>
		<category><![CDATA[Notification Bar]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=166</guid>
		<description><![CDATA[With reference to my article How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET , I have been getting inquiries on how to handle certain mouse events. so in this post I will explain how you can make the scroller stop/start on mouse hover/leave events respectively.
before we [...]]]></description>
			<content:encoded><![CDATA[<p>With reference to my article <a href="http://www.dottostring.com/2008/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/" target="_blank">How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET</a> , I have been getting inquiries on how to handle certain mouse events. so in this post I will explain how you can make the scroller stop/start on mouse hover/leave events respectively.</p>
<p>before we go ahead, I feel its important for you as reader to know that this is the third article in the chain.following are reference to the previous articles ( for those who are interested )</p>
<ol>
<li><a href="http://www.dottostring.com/2008/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/" target="_blank">How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET</a> | <a href="http://www.dottostring.com/wp-content/uploads/2008/11/dottostringnotificationbarticker.zip">Download Source Code</a></li>
<li><a href="http://www.dottostring.com/2008/12/how-to-create-make-a-windows-form-act-like-a-docking-window-without-a-container-in-c-sharp-net/" target="_blank">How to create (make a Windows Form act like) a Docking Window without a container in C#.NET</a> | <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringdockingwindow.zip">Download Source Code</a></li>
</ol>
<p> </p>
<p>moving on.</p>
<p>we have two labels which are working as a smooth vertically scrolling set of messages, this scroll effect is given by a Thread we created with the name <strong>BeginScroll, </strong>so in order to make the labels stop we have to some how make the infinite loop in the BeginScroll thread to stop and vice versa in case of start it again. for that to happen we are going to use a a concept straight out of the operating system textbook i.e. Semaphore/Mutex.</p>
<p>we have to develope a machanism that would allow us to use Signal/Wait strategy. For that .NET Framework has a handy feature called <strong>ManualResetEvent</strong>(<em>details of this is out of the scope of this article, so I would prefer you to look <a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx" target="_blank">here </a>for further information ) </em></p>
<p>(You can use any of the source code mentioned in the above two articles,I will be using source code from the second article mentioned above in this example)</p>
<ul>
<li>Add the following two global declarations to the code (NotificationTiker.cs)</li>
</ul>
<pre name="code" class="c#">        public ManualResetEvent signalThread = new ManualResetEvent(false);
        private bool keepScrolling;
 </pre>
<ul>
<li>now add the MouseHover and MouseLeave events for the both the labels such that they should match the following code.</li>
</ul>
<pre name="code" class="c#">private void lblMessageOne_MouseHover(object sender, EventArgs e)
        {
            //Set KeepSrcolling variable to false so that the loop
            //in the thread terminates
            keepScrolling = false;
            //Reset Event of the ManualResetEvent will make WaitOne
            //Event in the BeginScroll Thread to block and effectively
            //stopping the scroll effect
            signalThread.Reset();
        }

        private void lblMessageOne_MouseLeave(object sender, EventArgs e)
        {
            //Set Event of the ManualResetEvent will release the blocked
            //Thread (blocked by the WaitOne Method)
            signalThread.Set();
        }

        private void lblMessageTwo_MouseHover(object sender, EventArgs e)
        {
            //Set KeepSrcolling variable to false so that the loop
            //in the thread terminates
            keepScrolling = false;
            //Reset Event of the ManualResetEvent will make WaitOne
            //Event in the BeginScroll Thread to block and effectively
            //stopping the scroll effect
            signalThread.Reset();
        }

        private void lblMessageTwo_MouseLeave(object sender, EventArgs e)
        {
            //Set Event of the ManualResetEvent will release the blocked
            //Thread (blocked by the WaitOne Method)
            signalThread.Set();
        }</pre>
<p>now after making some changes to the scroll function, it should contain the following code</p>
<pre name="code" class="c#">        private void BeginScroll()
        {
            //This variable will take label out of view
            int LabelHeight = -lblMessageOne.Height;
            //This variable will be used to assign out of view variable to bottom of the panel, to re-enter
            int PanelBottom = panel1.Height;
            bool firstEntry = true;
            while (true)
            {
                if (!firstEntry)
                    signalThread.WaitOne();
                keepScrolling = true;
                while (keepScrolling)
                {
                    firstEntry = false;
                    if (lblMessageOne.Location.Y == LabelHeight)
                    {
                        //when label one goes out of view, it is configured to re enter again
                        lblMessageOne.Location = new Point(lblMessageOne.Location.X, PanelBottom);
                    }
                    else
                    {
                        //Scrolling label by decrementing it y-axis location
                        int MessageOneY = lblMessageOne.Location.Y - 1;
                        lblMessageOne.Location = new Point(lblMessageOne.Location.X, MessageOneY);
                    }
                    if (lblMessageTwo.Location.Y == LabelHeight)
                    {
                        //when label one goes out of view, it is configured to re enter again
                        lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, PanelBottom);
                    }
                    else
                    {
                        //Scrolling label by decrementing it y-axis location
                        int MessageTwoY = lblMessageTwo.Location.Y - 1;
                        lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, MessageTwoY);
                    }
                    this.Refresh();
                    Thread.Sleep(50);
                }
            }
        }</pre>
<p> </p>
<ul>
<li>this is it, now Run(F5) the application and test the mouse over and leave events.</li>
<li>Cheers, dont forget to leave comments/feedback.</li>
<li>Download Source Code <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringnotificationbarticker-mouseevents.zip">Here</a>.</li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Fhow-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-c-sharp-net-how-to-stopstart-the-ticker-on-mouse-hoverleave%2F';
  addthis_title  = 'How+to+make+pop-up+%2F+Notification+bar+with+Message+Ticker+%28smooth+message+scroller%29+over+the+Task+Bar+in+C%23.NET+%26%238211%3B+How+to+Stop%2FStart+the+Ticker+on+Mouse+Hover%2FLeave';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-c-sharp-net-how-to-stopstart-the-ticker-on-mouse-hoverleave/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
