<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Jwalin Khatri &#187; Asp.Net</title>
	<atom:link href="http://jwalin.wordpress.com/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://jwalin.wordpress.com</link>
	<description>Don't limit yourself</description>
	<lastBuildDate>Wed, 14 Oct 2009 18:29:15 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='jwalin.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/499eff1ef6b26c8546dbe7bd01c0ac6c?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Jwalin Khatri &#187; Asp.Net</title>
		<link>http://jwalin.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jwalin.wordpress.com/osd.xml" title="Jwalin Khatri" />
		<item>
		<title>Get Started with the Enterprise Library Data Access Application Block</title>
		<link>http://jwalin.wordpress.com/2009/02/11/get-started-with-the-enterprise-library-data-access-application-block/</link>
		<comments>http://jwalin.wordpress.com/2009/02/11/get-started-with-the-enterprise-library-data-access-application-block/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 20:12:14 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[ADO.Net]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[DAAB]]></category>
		<category><![CDATA[DAAB Example]]></category>
		<category><![CDATA[Data Access Applicatin Block Example]]></category>
		<category><![CDATA[Data Access Application Block]]></category>
		<category><![CDATA[Enterprise Library Data Access Application Block]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=109</guid>
		<description><![CDATA[Microsoft has redesigned version 2.0 of the Data Access Block to take advantage of new ADO.NET 2.0 features. You can download the Enterprise Library Data Access Application Block from MSDN.
1] Using Application Data Block (Change in Web.Config)
 To use the Data Access Block successfully, you will need to go through the steps listed below:
Add a reference [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=109&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Microsoft has redesigned version 2.0 of the Data Access Block to take advantage of new ADO.NET 2.0 features. You can download the <a href="http://msdn.microsoft.com/en-us/library/cc309504.aspx">Enterprise Library Data Access Application Block</a> from MSDN.</p>
<p><strong>1] Using Application Data Block (Change in Web.Config)<br />
</strong> To use the Data Access Block successfully, you will need to go through the steps listed below:</p>
<p>Add a reference to the Microsoft.Practices.EnterpriseLibrary.Common.dll and Microsoft.Practices.EnterpriseLibrary.Data.dll assemblies from your solution. You can do this by using the &#8220;Add Reference&#8221; option and navigating to the &lt;Drive Name&gt;:\Program Files\Microsoft Enterprise Library\bin folder.<br />
Add the necessary configuration entries to the web.config or app.config file or a custom configuration file. To this end, you add the below &lt;configSections&gt; element under the root &lt;configuration&gt; element.<br />
   <br />
         &lt;configSections&gt;<br />
            &lt;section   <br />
              name=&#8221;dataConfiguration&#8221;            <br />
              type=&#8221;Microsoft.Practices.          <br />
              EnterpriseLibrary.Data.<br />
              Configuration.<br />
              DatabaseSettings, <br />
              Microsoft.Practices.<br />
              EnterpriseLibrary.Data&#8221; /&gt;<br />
          &lt;/configSections&gt;</p>
<p>Then you also add the &lt;dataConfiguration&gt;&lt;configuration&gt; element as shown below:</p>
<p>         &lt;dataConfiguration         <br />
            defaultDatabase=<br />
            &#8220;AdventureWorksDB&#8221;/&gt;</p>
<p>In this example, I have marked AdventureWorks as the default database, declared separately under the &lt;connectionStrings&gt; element.<br />
          &lt;connectionStrings&gt;<br />
            &lt;add<br />
             name=&#8221;AdventureWorksDB&#8221;<br />
              providerName=<br />
              &#8220;System.Data.SqlClient&#8221;  <br />
              connectionString=<br />
              &#8220;server=localhost;<br />
              database=AdventureWorks;<br />
              UID=user;PWD=word;&#8221; /&gt;<br />
          &lt;/connectionStrings&gt;</p>
<p><strong>2]. Retriving value from the ExecuteDataReader</strong></p>
<p>      Database db = DatabaseFactory.CreateDatabase();<br />
       string sqlCommand = @&#8221;Select EmployeeID,<br />
  NationalIDNumber, LoginID, Title from  Employee &#8220;;<br />
       DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);<br />
       using (IDataReader reader = db.ExecuteReader(dbCommand))<br />
       {<br />
         //Bind with DataGrid<br />
       }               <br />
     }</p>
<p><strong>Retriving single row</strong></p>
<p> Here is the store procedure<br />
 Create Procedure GetEmployeeDetails<br />
 (<br />
      @EmployeeID int,<br />
      @NationalIDNumber nvarchar(15)<br />
        OUTPUT,<br />
      @LoginID nvarchar(256) OUTPUT,<br />
      @Title nvarchar(50) OUTPUT<br />
 )<br />
 AS<br />
      Select @NationalIDNumber =<br />
        NationalIDNumber,<br />
        @LoginID = LoginID,<br />
        @Title = Title from<br />
        Employee<br />
      Where EmployeeID = @EmployeeID<br />
 GO</p>
<p>Here is the code for it.</p>
<p>Database db = DatabaseFactory.CreateDatabase();<br />
string sqlCommand =&#8221;GetEmployeeDetails&#8221;;<br />
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);<br />
//DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);<br />
//dbCommand.CommandType = CommandType.StoredProcedure;<br />
db.AddInParameter(dbCommand, &#8220;EmployeeID&#8221;, DbType.Int32, 1);<br />
db.AddOutParameter(dbCommand, &#8220;NationalIDNumber&#8221;, DbType.String, 15);<br />
db.AddOutParameter(dbCommand, &#8220;LoginID&#8221;, DbType.String, 256);<br />
db.AddOutParameter(dbCommand, &#8220;Title&#8221;, DbType.String, 50);<br />
db.ExecuteNonQuery(dbCommand);<br />
Response.Write(&#8220;NationalID : &#8221; + db.GetParameterValue(dbCommand, &#8220;NationalIDNumber&#8221;) + &#8220;&lt;br&gt;&#8221;);<br />
<strong>3]. Retriving DataSet/DataTable</strong></p>
<p>       string   sqlCommand = @&#8221;Select EmployeeID,<br />
          NationalIDNumber, LoginID, Title from Employee &#8220;;<br />
       DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);<br />
       DataSet dst = db.ExecuteDataSet(dbCommand);</p>
<p> //Bind with Datagrid</p>
<p><strong>4]. Insert the records with Return Value<br />
</strong><br />
 CREATE PROCEDURE InsertRecordIntoCustomer<br />
 (<br />
    @CustomerID NCHAR(5),<br />
    @CompanyName VARCHAR(50)<br />
 )<br />
 AS<br />
 <strong>DECLARE @Result int<br />
</strong> IF EXISTS<br />
 (<br />
    SELECT<br />
       NULL<br />
   FROM<br />
       [Customers]<br />
   WHERE<br />
       [CustomerID] LIKE @CustomerID<br />
 )<br />
    BEGIN<br />
       SELECT @Result = -1<br />
       END<br />
 ELSE<br />
    BEGIN<br />
       INSERT INTO [Customers]<br />
   (<br />
   [CustomerID],<br />
   [CompanyName]<br />
   )<br />
   VALUES<br />
   (<br />
   @CustomerID,<br />
   @CompanyName<br />
   )<br />
       SELECT @Result = @@ERROR<br />
       END<br />
 <strong>RETURN @Result</strong><br />
 GO<br />
The C# code used to execute the above stored procedure is as follows:<br />
 try<br />
 {<br />
    // Create DataBase Instance<br />
    Database db = DatabaseFactory.CreateDatabase();<br />
    // Initialize the Stored Procedure<br />
    DBCommand dbCommand = db.GetStoredProcCommand(&#8220;InsertRecordIntoCustomer&#8221;);<br />
    // If There are output parameters, use ExecuteNonQuery only, better performance<br />
    dbCommand.AddInParameter(&#8220;@CustomerID&#8221;, DbType.String, &#8220;JohnY&#8221;);<br />
    dbCommand.AddInParameter(&#8220;@CompanyName&#8221;, DbType.String, &#8220;Microsoft&#8221;);<br />
    object Internalvalue = new object();<br />
    dbCommand.AddParameter(&#8220;@Result&#8221;, DbType.Int32, ParameterDirection.ReturnValue, &#8220;@Result&#8221;, DataRowVersion.Default,Internalvalue);<br />
    // Get output<br />
    int GetResult = 0;<br />
    // Execute Stored Procedure<br />
    db.ExecuteNonQuery(dbCommand);<br />
    GetResult = (int)dbCommand.GetParameterValue(&#8220;@Result&#8221;);<br />
    switch ( GetResult )<br />
    {<br />
       case 0:<br />
           Response.Write(&#8220;Record Inserted.&#8221;);<br />
           break;<br />
       case -1:<br />
           Response.Write(&#8220;Record Already Found.&#8221;);<br />
           break;<br />
       default:<br />
          Response.Write(&#8220;Record Not Inserted.&#8221;);<br />
          break;<br />
    }<br />
 }<br />
 catch (Exception ex)<br />
 {<br />
    Response.Write(ex.ToString());<br />
 }<br />
<strong>5]. Example with Tansactions</strong></p>
<p>   Database db = DatabaseFactory.CreateDatabase();<br />
  <br />
   //Two operations, one to add the order and another to add order details<br />
   string sqlCommand = &#8220;InsertOrder&#8221;;<br />
   DbCommand orderCommand = db.GetStoredProcCommand(sqlCommand);<br />
   //Add InsertOrder parameters<br />
  <br />
   sqlCommand = &#8220;InsertOrderDetails&#8221;;<br />
   DbCommand orderDetailsCommand = db.GetStoredProcCommand(sqlCommand);<br />
   //Add InsertOrderDetails parameters</p>
<p>   using (DbConnection connection = db.CreateConnection())<br />
   {<br />
     connection.Open();<br />
     DbTransaction transaction = connection.BeginTransaction();<br />
     try<br />
     {<br />
       //Execute the InsertOrder<br />
       db.ExecuteNonQuery(orderCommand, transaction);<br />
       //Execute the InsertOrderDetails   <br />
       db.ExecuteNonQuery( orderDetailsCommand, transaction);<br />
       //Commit the transaction<br />
       transaction.Commit();                   <br />
     }<br />
     catch<br />
     {<br />
       //Roll back the transaction.<br />
       transaction.Rollback();<br />
     }<br />
   } </p>
<p><strong>6]. Retrieve a Single Field<br />
</strong> <br />
 CREATE PROCEDURE [dbo].[GetCustomerSingleColumn]<br />
 (<br />
    @CustomerID NCHAR(5)<br />
 )<br />
 AS<br />
 SET NOCOUNT ON<br />
    SELECT<br />
       [CompanyName]<br />
    FROM<br />
       [Customers]<br />
    WHERE<br />
       [CustomerID] LIKE @CustomerID<br />
 GO<br />
The C# code used to execute the above stored procedure is as follows:<br />
 try<br />
 {<br />
    // Create DataBase Instance<br />
    Database db = DatabaseFactory.CreateDatabase();<br />
    // Initialize the Stored Procedure<br />
    DBCommand dbCommand = db.GetStoredProcCommand(&#8220;GetCustomerSingleColumn&#8221;);<br />
    dbCommand.AddInParameter(&#8220;@CustomerID&#8221;, DbType.String, &#8220;ALFKI&#8221;);<br />
    //Execute the stored procedure<br />
    string GetCompanyName = (string) db.ExecuteScalar(dbCommandWrapper);<br />
    //Display results of the query<br />
    string results = string.Format(&#8220;Company Name : {0}&#8221;,GetCompanyName);<br />
    Response.Write(results);<br />
 }<br />
 catch (Exception ex)<br />
 {<br />
    Response.Write(ex.ToString());<br />
 }</p>
<p>Search following text in Google you can find lots of articles about it <br />
&#8221; how to get the return value from store procedure in application data block dbcommand &#8220;</p>
<p>Happy Programming !!!!</p>
Posted in ADO.Net, Asp.Net Tagged: ADO.Net, Asp.Net, DAAB, DAAB Example, Data Access Applicatin Block Example, Data Access Application Block, Enterprise Library Data Access Application Block <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=109&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2009/02/11/get-started-with-the-enterprise-library-data-access-application-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Customize calander control</title>
		<link>http://jwalin.wordpress.com/2008/12/02/customize-calander-control/</link>
		<comments>http://jwalin.wordpress.com/2008/12/02/customize-calander-control/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 19:35:31 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=44</guid>
		<description><![CDATA[http://microsoft.apress.com/asptodayarchive/72141/using-the-calendar-control
Posted in Asp.Net Tagged: Asp.Net      <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=44&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://microsoft.apress.com/asptodayarchive/72141/using-the-calendar-control">http://microsoft.apress.com/asptodayarchive/72141/using-the-calendar-control</a></p>
Posted in Asp.Net Tagged: Asp.Net <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=44&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/12/02/customize-calander-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Executing async tasks in Asp.net</title>
		<link>http://jwalin.wordpress.com/2008/12/02/executing-async-tasks-in-aspnet/</link>
		<comments>http://jwalin.wordpress.com/2008/12/02/executing-async-tasks-in-aspnet/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 16:32:48 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Asyncronus program]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=39</guid>
		<description><![CDATA[Thank you for andreacol.net/blog
In this article I want to show 3 different ways to deal with long running tasks in Asp.net.
If such a task must be initiated from an Asp.net web page, the thread that is serving the page request is bound to the task until it completes or a timeout occurs. Asp.net and .net framework [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=39&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Thank you for andreacol.net/blog</p>
<p>In this article I want to show 3 different ways to deal with long running tasks in Asp.net.<br />
If such a task must be initiated from an Asp.net web page, the thread that is serving the page request is bound to the task until it completes or a timeout occurs. Asp.net and .net framework offer different ways to address this issue, in the project used for this article, a sample page attempts to star a long running task in three different ways:</p>
<p>1. Synchronously simply starting the task and waiting for its completion<br />
2. Asynchronously, using Page.RegisterAsyncTask and other features<br />
3. Asynchronously, using asynchronous delegates</p>
<p>Each of these options have pro and cons, and fit in different scenarios, but also these options don&#8217;t require to include the <strong>Async=&#8221;true&#8221;</strong> attribute in the page&#8217;s @ Page directive.</p>
<p>The first option entails to keep busy the thread that is serving the request, until the task completes. This could be a bottleneck, especially if multiple users start multiple tasks. This condition will probably end up to a <strong>503 &#8220;Server Unavailable&#8221; error</strong>.</p>
<p><a href="http://jwalin.files.wordpress.com/2008/12/demopage.jpg"><img class="alignleft size-thumbnail wp-image-40" title="demopage" src="http://jwalin.files.wordpress.com/2008/12/demopage.jpg?w=128&#038;h=59" alt="demopage" width="128" height="59" /></a></p>
<p> </p>
<p> </p>
<p> </p>
<p>It&#8217;s advisable to start a new thread that will perform the task, allowing the first thread to return in the thread pool and stand-by to serve a new incoming request.<br />
To reach our goal, no modifications are required to the actual codebase that is in charge to execute the task. In the second option we are going to use a Page&#8217;s method that first registers an async task, passing three different event handlers: one to begin/launch the task, one to manage its completion and the last one used to recover from a timeout that may occur during the task execution.<br />
This option also uses <strong>IAsyncResult</strong> interface described <a href="http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx" target="_blank">here</a>, but no extra coding is needed to use it, take a look to the code sample.<br />
The SimpleWorker class, exposes one method that simulates a long running operation but it only writes a text lines into a log file and waits one second per each line. Imagine an orders fulfillment procedure that creates packing lists and send an email to customers indicating that their orders are &#8220;approved&#8221;.</p>
<p> </p>
<pre><span>   1:</span> PageAsyncTask task = <span>new</span> PageAsyncTask(OnBegin, OnEnd, OnTimeout, <span>null</span>);
<span>   2:</span> Page.RegisterAsyncTask(task);
<span>   3:</span> 
<span>   4:</span> TraceStatusInfo(<span>"TEST CASE #2: Start a long running task asynchronously using PageAsyncTask."</span>);
<span>   5:</span> 
<span>   6:</span> <span>//Setting up a 5 secs timeout</span>
<span>   7:</span> Page.AsyncTimeout = <span>new</span> TimeSpan(0, 0, 5);
<span>   8:</span> 
<span>   9:</span> TraceStatusInfo(<span>"Starting task"</span>);
<span>  10:</span> 
<span>  11:</span> Page.ExecuteRegisteredAsyncTasks();</pre>
<p>Whether such a procedure could be started from an Asp.net page, is a good practice to maintain an activity registry or log, because the web application could be suddenly stopped without any warning and the worker process may be recycled due to an excessive, unexpected resource consumption.</p>
<p>The third option is the simplest one, it just uses an <a href="http://msdn.microsoft.com/en-us/library/22t547yb(VS.80).aspx" target="_blank">asynchronous delegate</a> to start the task before sending the response to the client. When the client browser renders the page after the postback, the task is still running into another thread on the server and the original thread, that initially served the request, is now free and returned in the thread pool. You could look at the ThreadID into the SimpleWorker&#8217;s log file and compare the server time when logging entries were added.</p>
<p><span style="font-family:'Courier New';line-height:18px;white-space:pre;"><span> 1:</span> TraceStatusInfo(<span>&#8220;TEST CASE #3: Start a long running task asynchronously using an asynchronous delegate.&#8221;</span>);<br />
<span> 2:</span> SimpleWorker w=<span>new</span> SimpleWorker();<br />
<span> 3:</span> atd2 = <span>new</span> AsyncTaskDelegate(w.DoWork);<br />
<span> 4:</span> <br />
<span> 5:</span> TraceStatusInfo(<span>&#8220;Starting task&#8221;</span>);<br />
<span> 6:</span> <br />
<span> 7:</span> atd2.BeginInvoke(<span>int</span>.Parse(txtUnits.Text), <span>null</span>, <span>null</span>);<br />
<span> 8:</span> <br />
<span> 9:</span> litStatus.Text = <span>&#8220;Test #3 completed.&#8221;</span>;</span></p>
<p> </p>
<p>The difference between the two last approaches, is on the fact that the former can get the task result as it completes and inform the user, the latter must poll the server to see what had happened, this should not be an issue for some scenarios, however an Ajax script could periodically hit the server querying an activity registry, like a table or a file, until the task is successfully completed. The second option could also benefit of the timeout handler, the third option instead is best suited for <em>fire and forget</em> tasks.</p>
<p>Here is a snapshot of the log file in which you can see that TreadID changes when an async task is executed in tests cases #2 and 3#.</p>
<p><a href="http://jwalin.files.wordpress.com/2008/12/simpleworkerlog1.jpg"><img class="alignleft size-medium wp-image-42" title="simpleworkerlog1" src="http://jwalin.files.wordpress.com/2008/12/simpleworkerlog1.jpg?w=300&#038;h=217" alt="simpleworkerlog1" width="300" height="217" /></a></p>
<p> </p>
<p><span style="font-family:'Courier New';line-height:18px;white-space:pre;"><br />
</span></p>
Posted in Asp.Net Tagged: Asp.Net, Asyncronus program <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=39&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/12/02/executing-async-tasks-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>

		<media:content url="http://jwalin.files.wordpress.com/2008/12/demopage.jpg?w=128" medium="image">
			<media:title type="html">demopage</media:title>
		</media:content>

		<media:content url="http://jwalin.files.wordpress.com/2008/12/simpleworkerlog1.jpg?w=300" medium="image">
			<media:title type="html">simpleworkerlog1</media:title>
		</media:content>
	</item>
		<item>
		<title>Building ASP.NET Web Server Controls using XML and XSLT</title>
		<link>http://jwalin.wordpress.com/2008/09/19/building-aspnet-web-server-controls-using-xml-and-xslt/</link>
		<comments>http://jwalin.wordpress.com/2008/09/19/building-aspnet-web-server-controls-using-xml-and-xslt/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 17:44:41 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=31</guid>
		<description><![CDATA[http://aspalliance.com/1680_Building_ASPNET_Web_Server_Controls_using_XML_and_XSLT.all
Posted in Asp.Net Tagged: Asp.Net, XML, XSLT      <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=31&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://aspalliance.com/1680_Building_ASPNET_Web_Server_Controls_using_XML_and_XSLT.all">http://aspalliance.com/1680_Building_ASPNET_Web_Server_Controls_using_XML_and_XSLT.all</a></p>
Posted in Asp.Net Tagged: Asp.Net, XML, XSLT <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=31&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/09/19/building-aspnet-web-server-controls-using-xml-and-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Create SubDomain and FormAuthentication</title>
		<link>http://jwalin.wordpress.com/2008/07/21/create-subdomain-and-formauthentication/</link>
		<comments>http://jwalin.wordpress.com/2008/07/21/create-subdomain-and-formauthentication/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 20:48:47 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[FormAunthentication]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=28</guid>
		<description><![CDATA[ 
http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx
http://mgrzyb.blogspot.com/search?updated-min=2007-01-01T00%3A00%3A00%2B01%3A00&#38;updated-max=2008-01-01T00%3A00%3A00%2B01%3A00&#38;max-results=1
http://davestechshop.net/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames2.aspx
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=28&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p> </p>
<p><a href="http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx">http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx</a></p>
<p><a href="http://mgrzyb.blogspot.com/search?updated-min=2007-01-01T00%3A00%3A00%2B01%3A00&amp;updated-max=2008-01-01T00%3A00%3A00%2B01%3A00&amp;max-results=1">http://mgrzyb.blogspot.com/search?updated-min=2007-01-01T00%3A00%3A00%2B01%3A00&amp;updated-max=2008-01-01T00%3A00%3A00%2B01%3A00&amp;max-results=1</a></p>
<p><a href="http://davestechshop.net/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames2.aspx">http://davestechshop.net/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames2.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=28&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/07/21/create-subdomain-and-formauthentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Are you making these 3 common ASP.NET AJAX mistakes?</title>
		<link>http://jwalin.wordpress.com/2008/07/08/are-you-making-these-3-common-aspnet-ajax-mistakes/</link>
		<comments>http://jwalin.wordpress.com/2008/07/08/are-you-making-these-3-common-aspnet-ajax-mistakes/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 17:35:04 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[UPDATE PANEL]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=26</guid>
		<description><![CDATA[http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=26&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/">http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=26&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/07/08/are-you-making-these-3-common-aspnet-ajax-mistakes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Pager control in GridView and DataList</title>
		<link>http://jwalin.wordpress.com/2008/05/23/pager-control-in-gridview-and-datalist/</link>
		<comments>http://jwalin.wordpress.com/2008/05/23/pager-control-in-gridview-and-datalist/#comments</comments>
		<pubDate>Fri, 23 May 2008 14:54:44 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[DataList]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[Pager Cotrol]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=23</guid>
		<description><![CDATA[http://www.sqlnetframework.com/Articles/GoogleDataPager.aspx
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=23&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.sqlnetframework.com/Articles/GoogleDataPager.aspx">http://www.sqlnetframework.com/Articles/GoogleDataPager.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=23&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/05/23/pager-control-in-gridview-and-datalist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Once button click, button should be disable and text change to Please wait</title>
		<link>http://jwalin.wordpress.com/2008/04/07/once-button-click-button-should-be-disable-and-text-change-to-please-wait/</link>
		<comments>http://jwalin.wordpress.com/2008/04/07/once-button-click-button-should-be-disable-and-text-change-to-please-wait/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 16:08:36 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Controls Disable]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=15</guid>
		<description><![CDATA[protected
 
void Button1_PreRender(object sender, EventArgs e)
{
string doubleSubmitScript = String.Format(@&#8221;if (typeof(Page_ClientValidate) == &#8216;function&#8217;) {{
if (!Page_ClientValidate()) {{ return false; }}
}}
this.value = &#8216;Please wait&#8230;&#8217;;
this.disabled = true;
{0};&#8221;

, ClientScript.GetPostBackEventReference(BeginButton, String.Empty));
Button1.OnClientClick = doubleSubmitScript;
}
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=15&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="color:#0000ff;"><font color="#0000ff">protected</p>
<p></font></span> </p>
<p><span style="color:#0000ff;">void</span> Button1_PreRender(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</p>
<p>{</p>
<p><span style="color:#0000ff;">string</span> doubleSubmitScript = <span style="color:#2b91af;">String</span>.Format(<span style="color:#a31515;">@&#8221;if (typeof(Page_ClientValidate) == &#8216;function&#8217;) {{</p>
<p>if (!Page_ClientValidate()) {{ return false; }}</p>
<p>}}</p>
<p>this.value = &#8216;Please wait&#8230;&#8217;;</p>
<p>this.disabled = true;</p>
<p><font color="#a31515">{0};&#8221;</p>
<p></font></span></p>
<p>, ClientScript.GetPostBackEventReference(BeginButton, <span style="color:#2b91af;">String</span>.Empty));</p>
<p>Button1.OnClientClick = doubleSubmitScript;</p>
<p>}</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=15&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/04/07/once-button-click-button-should-be-disable-and-text-change-to-please-wait/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Optimize your page for UpdatePanel</title>
		<link>http://jwalin.wordpress.com/2008/03/26/optimize-your-page-for-updatepanel/</link>
		<comments>http://jwalin.wordpress.com/2008/03/26/optimize-your-page-for-updatepanel/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 16:34:58 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[UPDATE PANEL]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=13</guid>
		<description><![CDATA[Than&#8217;s to Miron 
The Update Panel response contain the new html for the specific location that needs to be update and the complete new ViewState for the whole page. So, one more thing we can to optimize the UpdatePanel is to compress the ViewState before it been sent to the client. We don&#8217;t need to do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=13&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Than&#8217;s to Miron </p>
<p>The Update Panel response contain the new html for the specific location that needs to be update and the complete new ViewState for the whole page. So, one more thing we can to optimize the UpdatePanel is to <strong>compress the ViewState </strong>before it been sent to the client. We don&#8217;t need to do it in normal response because we use (or should use) a compression module that compress all the page response and that includes the ViewState. Compress the ViewState can save you some more KB from the async response. Another option is to save the ViewState in the server (file os session), and not send it at all. To compress the ViewState we needs to override the &#8216;LoadPageStateFromPersistenceMedium&#8217; and the &#8216;SavePageStateToPersistenceMedium&#8217; methods that load and save the view state.</p>
<p>Here is the code how to compress the ViewState for the UpdatePanel response only, just copy it to your base page:</p>
<div class="code"> <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">object</span> LoadPageStateFromPersistenceMedium()<br />
{<br />
    <span class="kwrd">string</span> viewState = Request.Form["__COMPRESSEDVS"];<br />
    <span class="kwrd">if</span> (viewState != <span class="kwrd">null</span>)<br />
    {<br />
         <span class="kwrd">byte</span>[] data = Convert.FromBase64String(viewState);<br />
         data = Utils.Decompress(data);<br />
         LosFormatter lf = <span class="kwrd">new</span> LosFormatter();<br />
         <span class="kwrd">return</span> lf.Deserialize(Convert.ToBase64String(data));<br />
    }<br />
    <span class="kwrd">else</span><br />
    {<br />
         <span class="kwrd">return</span> <span class="kwrd">base</span>.LoadPageStateFromPersistenceMedium();<br />
    }<br />
}<span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> SavePageStateToPersistenceMedium(<span class="kwrd">object</span> viewState)<br />
{<br />
    <span class="kwrd">if</span> (Utils.IsMsAjaxCallback(Request))<br />
    {<br />
         LosFormatter lf = <span class="kwrd">new</span> LosFormatter();<br />
         <span class="kwrd">using</span> (StringWriter writer = <span class="kwrd">new</span> StringWriter())<br />
         {<br />
             lf.Serialize(writer, viewState);<br />
             <span class="kwrd">string</span> viewStateString = writer.ToString();<br />
             <span class="kwrd">byte</span>[] data = Convert.FromBase64String(viewStateString);<br />
             data = Utils.Compress(data);<br />
             ScriptManager.RegisterHiddenField(<span class="kwrd">this</span>, &#8220;__COMPRESSEDVS&#8221;, Convert.ToBase64String(data));<br />
         }<br />
    }<br />
    <span class="kwrd">else</span><br />
    {<br />
         <span class="kwrd">base</span>.SavePageStateToPersistenceMedium(viewState);<br />
    }<br />
}</div>
<div class="code"></div>
<div class="code"></div>
<div class="code"></div>
<div class="code">=================</div>
<div class="code">HERE IS THE Utils.cs CLASS</div>
<div class="code">=================</div>
<div class="code">using System;<br />
using System.Web;<br />
using System.IO;<br />
using System.IO.Compression;</div>
<div class="code">public class Utils<br />
{<br />
    public static bool IsMsAjaxCallback(HttpRequest request)<br />
    {<br />
        return (request != null &amp;&amp; request.Headers["X-MicrosoftAjax"] != null);<br />
    }</div>
<div class="code">
    public static byte[] Compress(byte[] data)<br />
    {<br />
        using (MemoryStream ms = new MemoryStream())<br />
        {<br />
            using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))<br />
            {<br />
                zip.Write(data, 0, data.Length);<br />
                zip.Dispose();<br />
                return ms.ToArray();<br />
            }<br />
        }<br />
    }</div>
<div class="code">    public static byte[] Decompress(byte[] data)<br />
    {<br />
        using (MemoryStream ms = new MemoryStream())<br />
        {<br />
            int dataLength = BitConverter.ToInt32(data, 0);<br />
            ms.Write(data, 0, data.Length);</div>
<div class="code">            byte[] buffer = new byte[dataLength];</div>
<div class="code">            ms.Position = 0;<br />
            using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))<br />
            {<br />
                zip.Read(buffer, 0, buffer.Length);<br />
            }<br />
            return buffer;<br />
        }<br />
    }<br />
}<br />
 </div>
<div class="code"></div>
<div class="code"></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=13&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/03/26/optimize-your-page-for-updatepanel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
		<item>
		<title>Don’t run production ASP.NET Applications with debug=”true” enabled</title>
		<link>http://jwalin.wordpress.com/2008/03/19/don%e2%80%99t-run-production-aspnet-applications-with-debug%e2%80%9dtrue%e2%80%9d-enabled/</link>
		<comments>http://jwalin.wordpress.com/2008/03/19/don%e2%80%99t-run-production-aspnet-applications-with-debug%e2%80%9dtrue%e2%80%9d-enabled/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 20:02:08 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Web.Config]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=12</guid>
		<description><![CDATA[Don’t run production ASP.NET Applications with debug=”true” enabled

One of the things you want to avoid when deploying an ASP.NET application into production is to accidentally (or deliberately) leave the &#60;compilation debug=”true”/&#62; switch on within the application’s web.config file.

Doing so causes a number of non-optimal things to happen including:
1) The compilation of ASP.NET pages takes longer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=12&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin:0;" class="MsoPlainText"><font face="Consolas">Don’t run production ASP.NET Applications with debug=”true” enabled<br />
</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">One of the things you want to avoid when deploying an ASP.NET application into production is to accidentally (or deliberately) leave the &lt;compilation debug=”true”/&gt; switch on within the application’s web.config file.<br />
</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">Doing so causes a number of non-optimal things to happen including:</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">1) The compilation of ASP.NET pages takes longer (since some batch optimizations are disabled)</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">2) Code can execute slower (since some additional debug paths are enabled)</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">3) Much more memory is used within the application at runtime</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">4) Scripts and images downloaded from the WebResources.axd handler are not cached<br />
</font></p>
<p style="margin:0;" class="MsoPlainText"><font face="Consolas">You can see the full article by clicking following links</font></p>
<p style="margin:0;" class="MsoPlainText"><a href="http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx"><u><font color="#800080" face="Consolas">http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx</font></u></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jwalin.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jwalin.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=12&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2008/03/19/don%e2%80%99t-run-production-aspnet-applications-with-debug%e2%80%9dtrue%e2%80%9d-enabled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
	</channel>
</rss>