<?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>.Net Extremo</title>
	<atom:link href="http://acollado.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://acollado.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sun, 06 Feb 2011 19:22:47 +0000</lastBuildDate>
	<language>es</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='acollado.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>.Net Extremo</title>
		<link>http://acollado.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://acollado.wordpress.com/osd.xml" title=".Net Extremo" />
	<atom:link rel='hub' href='http://acollado.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Precarga en ASP.NET con AJAX (2)</title>
		<link>http://acollado.wordpress.com/2009/09/07/precarga-en-asp-net-con-ajax-2/</link>
		<comments>http://acollado.wordpress.com/2009/09/07/precarga-en-asp-net-con-ajax-2/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 19:52:34 +0000</pubDate>
		<dc:creator>acollado</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://acollado.wordpress.com/2009/10/12/precarga-en-asp-net-con-ajax-2/</guid>
		<description><![CDATA[En el artículo anterior vimos cómo realizar una precarga con el control UpdatePanel, en esta ocasión vamos a ver cómo implementar nuestro sistema de precarga en una página independiente y redirigir al usuario a la página donde se mostrarán los datos. Primero el usuario seleccionaría la información de un producto, una vez seleccionado, redirigimos la [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=52&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Arial;">En el <a href="http://acollado.wordpress.com/2008/05/02/precarga-en-aspnet-con-ajax-1">artículo anterior</a> vimos cómo realizar una precarga con el control UpdatePanel, en esta ocasión vamos a ver cómo implementar nuestro sistema de precarga en una página independiente y redirigir al usuario a la página donde se mostrarán los datos.<br />
</span></p>
<p><span style="font-family:Arial;">Primero el usuario seleccionaría la información de un producto, una vez seleccionado, redirigimos la petición a otra página donde se cargaría de forma asíncrona mientras muestra una animación (para que el usuario no desespere), obtenida la información del producto en cuestión, la guardamos   en el estado de la sesión y le redirigimos a la página donde se mostrará la información del producto que obtendremos de la variable de sesión.<br />
</span></p>
<p><span style="font-family:Arial;">Una vez vistos los preliminares, empezamos con el código.<br />
</span></p>
<p><span style="font-family:Arial;">La primera página es la que mostrará el formulario de búsqueda de producto:<br />
</span></p>
<p><span style="color:black;font-family:Arial;"><strong>viewproduct.aspx<br />
</strong></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;%@</span><br />
<span style="color:maroon;">Page</span><br />
<span style="color:red;">Language</span><span style="color:blue;">=&#8221;C#&#8221;</span><br />
<span style="color:red;">AutoEventWireup</span><span style="color:blue;">=&#8221;true&#8221;</span> %&gt;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;!</span><span style="color:maroon;">DOCTYPE</span><br />
<span style="color:red;">html</span><br />
<span style="color:red;">PUBLIC</span><br />
<span style="color:blue;">&#8220;-//W3C//DTD XHTML 1.1//EN&#8221;</span><br />
<span style="color:blue;">&#8220;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">script</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">protected</span><br />
<span style="color:blue;">void</span> DropDownList1_SelectedIndexChanged(<span style="color:blue;">object</span> sender, <span style="color:teal;">EventArgs</span> e)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">if</span>(DropDownList1.SelectedIndex&gt;0)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> Response.Redirect(<span style="color:maroon;">&#8220;loadproduct.aspx?id=&#8221;</span> + DropDownList1.SelectedValue);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">script</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">html</span><br />
<span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">head</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;</span>Untitled Page<span style="color:blue;">&lt;/</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">head</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">body</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">form</span><br />
<span style="color:red;">id</span><span style="color:blue;">=&#8221;form1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"> Seleccione una categoría para ver sus productos:<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">DropDownList</span><br />
<span style="color:red;">ID</span><span style="color:blue;">=&#8221;DropDownList1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span><br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:red;">onselectedindexchanged</span><span style="color:blue;">=&#8221;DropDownList1_SelectedIndexChanged&#8221;</span><br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:red;">AutoPostBack</span><span style="color:blue;">=&#8221;True&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><span style="color:blue;">&gt;</span>&#8211; Productos &#8211;<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><br />
<span style="color:red;">Value</span><span style="color:blue;">=&#8221;1&#8243;&gt;</span>Carnes<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><br />
<span style="color:red;">Value</span><span style="color:blue;">=&#8221;2&#8243;&gt;</span>Verduras<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><br />
<span style="color:red;">Value</span><span style="color:blue;">=&#8221;3&#8243;&gt;</span>Pescados<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ListItem</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">DropDownList</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">form</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">body</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">html</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="color:black;font-family:Arial;font-size:12pt;">La segunda es la más importante, es donde cargaremos el producto asincronamente y se lo asignaremos a una variable de sesión:<br />
</span></p>
<p><span style="color:black;font-family:Arial;font-size:10pt;"><strong>loadproduct.aspx<br />
</strong></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:black;">&lt;%</span><span style="color:blue;">@</span><br />
<span style="color:maroon;">Page</span><br />
<span style="color:red;">Language</span><span style="color:blue;">=&#8221;C#&#8221;</span> %&gt;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;">&lt;%<span style="color:blue;">@</span><br />
<span style="color:maroon;">Import</span><br />
<span style="color:red;">Namespace</span><span style="color:blue;">=&#8221;System.Collections.Generic&#8221;</span> %&gt;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;">&lt;%<span style="color:blue;">@</span><br />
<span style="color:maroon;">Import</span><br />
<span style="color:red;">Namespace</span><span style="color:blue;">=&#8221;System.Web.Services&#8221;</span> %&gt;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;!</span><span style="color:maroon;">DOCTYPE</span><br />
<span style="color:red;">html</span><br />
<span style="color:red;">PUBLIC</span><br />
<span style="color:blue;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span><br />
<span style="color:blue;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">script</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">protected</span><br />
<span style="color:blue;">void</span> Page_Load(<span style="color:blue;">object</span> sender, <span style="color:teal;">EventArgs</span> e)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">if</span> (Request.QueryString[<span style="color:maroon;">"id"</span>] == <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> Response.Redirect(<span style="color:maroon;">&#8220;viewproduct.aspx&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> [<span style="color:teal;">WebMethod</span>()]<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">public</span><br />
<span style="color:blue;">static</span><br />
<span style="color:blue;">void</span> LoadProduct(<span style="color:blue;">int</span> id)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:green;">//Aqui se cargaría el producto<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"> System.Threading.<span style="color:teal;">Thread</span>.Sleep(2000);<span style="color:green;">//Esto es sólo para hacer más real el e.0tjemplo (no hacer esto en aplicaciones reales)<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:teal;">HttpContext</span> context = <span style="color:teal;">HttpContext</span>.Current;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:teal;">List</span>&lt;<span style="color:teal;">Product</span>&gt; Productos=<span style="color:blue;">new</span><br />
<span style="color:teal;">List</span>&lt;<span style="color:teal;">Product</span>&gt;();<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:teal;">Random</span> precioAleatorio=<span style="color:blue;">new</span><br />
<span style="color:teal;">Random</span>();<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:green;">//Para hacer más sencillo el ejemplo rellenamos una lista ficticia de productos. En un entorno<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:green;">//real usaríamos el id pasado cómo parametro para recuperarla de un orígen de datos.<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">for</span>(<span style="color:blue;">int</span> i=0;i&lt;=20;i++)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:teal;">Product</span> p=<span style="color:blue;">new</span><br />
<span style="color:teal;">Product</span>();<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.Nombre=<span style="color:maroon;">&#8220;Producto_&#8221;</span>+i;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.Precio=(<span style="color:blue;">decimal</span>)precioAleatorio.Next(2,25);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">if</span> (i &gt; 0 &amp;&amp; i &lt; 5)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.IdCat = 1;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.Categoria = <span style="color:maroon;">&#8220;Carnes&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">else</span><br />
<span style="color:blue;">if</span> (i &gt; 5 &amp;&amp; i &lt; 12)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.IdCat = 2;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.Categoria = <span style="color:maroon;">&#8220;Verduras&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">else<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.IdCat = 3;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> p.Categoria = <span style="color:maroon;">&#8220;Pescados&#8221;</span>;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">if</span>(p.IdCat==id)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> Productos.Add(p);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:green;">//Asignamos la lista de productos a una variable de sesión para recuperarla desde otra página<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"> context.Session[<span style="color:maroon;">"ProductosActuales"</span>] = Productos;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">script</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">html</span><br />
<span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">head</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;</span>Cargando&#8230;<span style="color:blue;">&lt;/</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">script</span><br />
<span style="color:red;">language</span><span style="color:blue;">=&#8221;javascript&#8221;</span><br />
<span style="color:red;">type</span><span style="color:blue;">=&#8221;text/javascript&#8221;&gt;<br />
</span></span></p>
<p><span style="color:green;font-family:Arial;font-size:10pt;">// &lt;!CDATA[<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">function</span> load(id) {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> PageMethods.LoadProduct(id, onOk, onError);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">function</span> onOk() {document.location = <span style="color:maroon;">'productinfo.aspx'</span>;}<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">function</span> onError() { document.location.href = <span style="color:maroon;">'error.aspx'</span>; }<br />
</span></p>
<p><span style="color:green;font-family:Arial;font-size:10pt;">// ]]&gt;<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">script</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">head</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">body</span><br />
<span style="color:red;">onload</span><span style="color:blue;">=&#8221;load(</span>&lt;%=Request.QueryString["id"]%&gt;<span style="color:blue;">)&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">form</span><br />
<span style="color:red;">id</span><span style="color:blue;">=&#8221;form1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ScriptManager</span><br />
<span style="color:red;">ID</span><span style="color:blue;">=&#8221;ScriptManager1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span><br />
<span style="color:red;">EnablePageMethods</span><span style="color:blue;">=&#8221;True&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">ScriptManager</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">br</span><br />
<span style="color:blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">br</span><br />
<span style="color:blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">img</span><br />
<span style="color:red;">src</span><span style="color:blue;">=&#8221;loading.gif&#8221;</span><br />
<span style="color:blue;">/&gt;</span><span style="color:red;">&amp;nbsp;</span> Cargando&#8230;<span style="color:blue;">&lt;/</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">form</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">body</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">html</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="color:black;font-family:Arial;">En la tercera página mostramos los datos de la variable de sesión:<br />
</span></p>
<p><span style="color:black;font-family:Arial;"><strong>productinfo.aspx<br />
</strong></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><strong><span style="color:black;">&lt;%</span><span style="color:blue;">@</span><br />
<span style="color:maroon;">Page</span><br />
<span style="color:red;">Language</span><span style="color:blue;">=&#8221;C#&#8221;</span> %&gt;<br />
</strong></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;!</span><span style="color:maroon;">DOCTYPE</span><br />
<span style="color:red;">html</span><br />
<span style="color:red;">PUBLIC</span><br />
<span style="color:blue;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span><br />
<span style="color:blue;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">script</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">protected</span><br />
<span style="color:blue;">void</span> Page_Load(<span style="color:blue;">object</span> sender, <span style="color:teal;">EventArgs</span> e)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> {<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">if</span>(Session[<span style="color:maroon;">"ProductosActuales"</span>]==<span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> Response.Redirect(<span style="color:maroon;">&#8220;viewproduct.aspx&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> GridView1.DataSource = Session[<span style="color:maroon;">"ProductosActuales"</span>];<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> GridView1.DataBind();<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"> }<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">script</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">html</span><br />
<span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">head</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">head</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;</span><span style="color:maroon;">body</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">form</span><br />
<span style="color:red;">id</span><span style="color:blue;">=&#8221;form1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">GridView</span><br />
<span style="color:red;">ID</span><span style="color:blue;">=&#8221;GridView1&#8243;</span><br />
<span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span><br />
<span style="color:red;">AutoGenerateColumns</span><span style="color:blue;">=&#8221;false&#8221;&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">Columns</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">BoundField</span><br />
<span style="color:red;">DataField</span><span style="color:blue;">=&#8221;Precio&#8221;</span><br />
<span style="color:red;">DataFormatString</span><span style="color:blue;">=&#8221;{0:C}&#8221;</span><br />
<span style="color:blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">BoundField</span><br />
<span style="color:red;">DataField</span><span style="color:blue;">=&#8221;Nombre&#8221;</span><br />
<span style="color:blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">BoundField</span><br />
<span style="color:red;">DataField</span><span style="color:blue;">=&#8221;Categoria&#8221;</span><br />
<span style="color:blue;">/&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">Columns</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">asp</span><span style="color:blue;">:</span><span style="color:maroon;">GridView</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">form</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">body</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;font-size:10pt;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">html</span><span style="color:blue;">&gt;<br />
</span></span></p>
<p><span style="font-family:Arial;"><span style="color:black;">Soy consciente de que se han quedado algunas cosas en el tintero, lo más importante es saber que hay que establecer la propiedad  EnablePageMethods</span><span style="color:red;"><br />
</span><span style="color:black;">del control ScriptManager en true y declarar el método de página cómo static con el ámbito público.<br />
</span></span></p>
<p><span style="color:black;font-family:Arial;">Espero que os haya servido.<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acollado.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acollado.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acollado.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=52&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acollado.wordpress.com/2009/09/07/precarga-en-asp-net-con-ajax-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2870ea16cef0e78fd4be56eaadcc37e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">acollado</media:title>
		</media:content>
	</item>
		<item>
		<title>Mostrar progresos con BackgroundWorker</title>
		<link>http://acollado.wordpress.com/2008/05/11/mostrar-progresos-con-backgroundworker/</link>
		<comments>http://acollado.wordpress.com/2008/05/11/mostrar-progresos-con-backgroundworker/#comments</comments>
		<pubDate>Sun, 11 May 2008 20:46:52 +0000</pubDate>
		<dc:creator>acollado</dc:creator>
				<category><![CDATA[Piensa en asíncrono]]></category>
		<category><![CDATA[asíncrono]]></category>
		<category><![CDATA[BackgroundWorker]]></category>
		<category><![CDATA[Componente]]></category>
		<category><![CDATA[Progresos]]></category>

		<guid isPermaLink="false">http://acollado.wordpress.com/?p=28</guid>
		<description><![CDATA[Cuando necesitamos realizar tareas de manera asíncrona El .Net Framework nos proporciona varias opciones; -Mediante la clase Thread. -Mediante delegados asíncronos. -Mediante el componente BackgroundWorker. Se me ocurren diversas situaciones en la que cada uno puede ser más apropiado. Pero, si lo que queremos es mostrar el progreso de la tarea, la mejor opción es [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=28&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="Section1">Cuando necesitamos realizar tareas de manera asíncrona El .Net Framework nos proporciona varias opciones;<br />
-Mediante la clase  <strong><span style="font-size:10pt;line-height:115%;">Thread</span></strong><span style="font-size:10pt;line-height:115%;">.<br />
</span>-Mediante <a href="http://acollado.wordpress.com/2008/05/10/delegados-genericos/">delegados</a> asíncronos.<br />
-Mediante el componente BackgroundWorker.<br />
Se me ocurren diversas situaciones en la que cada uno puede ser más apropiado. Pero, si lo que queremos es mostrar el progreso de la tarea, la mejor opción es el componente BackgroundWorker. El componente BackgroundWorker tiene varias características que le hacen interesante; como puede ser la notificación del progreso  y notificación de cancelación.<br />
El ejemplo de código siguiente es un modo sencillo de dar soporte para cancelación y notificación del progreso de una tarea asíncrona.</p>
<table class="MsoTableColorfulGridAccent3" style="border-collapse:collapse;height:18px;" border="0" cellspacing="0" cellpadding="0" width="682">
<tbody>
<tr>
<td style="background:#d6e3bc none repeat scroll 0 50%;width:432.2pt;padding:0 5.4pt;" width="660" valign="top"><span style="color:#339966;">Nota:<br />
Este componente solo está disponible   desde la versión 2.0 del Framework.</span></td>
</tr>
</tbody>
</table>
<p class="MsoNormal">
<p>Lo primero es arrastrar el componente a nuestra aplicación</p>
<p><img src="http://acollado.files.wordpress.com/2008/05/backgroundworker.jpg?w=455" alt="" /></p>
<p>Una vez que los hemos situado en el área de trabajo configuramos las siguientes propiedades:</p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">WorkerReportsProgress = <span style="color:blue;">true<br />
</span>WorkerSupportsCancellation=<span style="color:blue;">true </span></span>(solo en caso de querer dar soporte para cancelación)</p>
<p>Ahora definimos los eventos de cancelación, notificación y trabajo.</p>
<p>DoWork: Este evento es disparado al comienzo de la operación asíncrona y sera donde realicemos las tareas.</p>
<p>ProgressChanged: Este evento será disparado el notificar un progreso al componente.</p>
<p>RunWorkerCompleted: Este evento será disparado al terminar la operación asíncrona.</p>
<table class="MsoTableColorfulGridAccent3" style="border-collapse:collapse;margin-left:5.1pt;margin-right:5.1pt;" border="0" cellspacing="0" cellpadding="0" align="left">
<tbody>
<tr>
<td style="background:#d6e3bc none repeat scroll 0 50%;width:432.2pt;padding:0 5.4pt;" width="660" valign="top"><span style="color:#339966;">Nota:<br />
Si desea acceder a un control desde la operación que este realizando el componente BackgroundWorker. Por ejemplo,   mostrar el estado de progreso en un control Label, es más que aconsejable   hacerlo desde el evento ProgressChanged, ya que la aplicación podria   comportarse de forma inesperada.</span></td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p>Ya podemos escribir el código que sera lanzado con cada evento.</p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><strong>C#</strong><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">void</span> bwProgress_DoWork(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">DoWorkEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 1; i &lt;= 100; i++)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Realiza una tarea</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> System.Threading.<span style="color:#2b91af;">Thread</span>.Sleep(100); </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> bwProgress.ReportProgress(i);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">if</span><span style="font-size:10pt;"> (bwProgress.CancellationPending)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">return</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> }</span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;"> </span></strong></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">void</span> bwProgress_ProgressChanged(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">ProgressChangedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Notificar el progreso de la tarea</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">progressBar1.Value = e.ProgressPercentage;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> lblInfo.Text = e.ProgressPercentage + <span style="color:#a31515;">&#8220;%&#8221;</span>;</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span><span style="font-size:10pt;line-height:115%;">}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">void</span> bwProgress_RunWorkerCompleted(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">RunWorkerCompletedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Realizamos las operaciones que haya que realizar al terminar el progreso</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">lblInfo.Text = <span style="color:#a31515;">&#8220;Tarea terminada&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnCancelar.Enabled = <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnIniciar.Enabled = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> progressBar1.Value = 0;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">void</span> btnIniciar_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Iniciamos el trabajo</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">if</span> (!bwProgress.IsBusy)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> bwProgress.RunWorkerAsync();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnCancelar.Enabled = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnIniciar.Enabled = <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">void</span> btnCancelar_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Solicitamos la cancelación de la operación</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">bwProgress.CancelAsync();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><strong><span style="font-size:10pt;">VB</span></strong><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;"> </span></strong></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">Private</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> bwProgress_DoWork(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.ComponentModel.DoWorkEventArgs) <span style="color:blue;">Handles</span> bwProgress.DoWork</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">For</span> i <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 1 <span style="color:blue;">To</span> 100</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8221;Realiza una tarea</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> System.Threading.Thread.Sleep(100)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> bwProgress.ReportProgress(i)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">If</span> (bwProgress.CancellationPending) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Return</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Next</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">Private</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> bwProgress_ProgressChanged(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.ComponentModel.ProgressChangedEventArgs) <span style="color:blue;">Handles</span> bwProgress.ProgressChanged</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">&#8216;Notificar el progreso de la tarea</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">progressBar1.Value = e.ProgressPercentage</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> lblInfo.Text = e.ProgressPercentage + <span style="color:#a31515;">&#8220;%&#8221;</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">Private</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> bwProgress_RunWorkerCompleted(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.ComponentModel.RunWorkerCompletedEventArgs) <span style="color:blue;">Handles</span> bwProgress.RunWorkerCompleted</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">&#8221;Realizamos las operaciones que haya que realizar al terminar el progreso</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">lblInfo.Text = <span style="color:#a31515;">&#8220;Tarea terminada&#8221;</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnCancelar.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnIniciar.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> progressBar1.Value = 0</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">End</span><span style="font-size:10pt;line-height:115%;"> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">Private</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> btnIniciar_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> btnIniciar.Click</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8221;Iniciamos el trabajo</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">If</span> (<span style="color:blue;">Not</span> bwProgress.IsBusy) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> bwProgress.RunWorkerAsync()</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnCancelar.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> btnIniciar.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">End</span><span style="font-size:10pt;line-height:115%;"> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;">Private</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> btnCancelar_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> btnCancelar.Click</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">&#8216;Solicitamos la cancelación de la operación</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;"> bwProgress.CancelAsync()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">End</span><span style="font-size:10pt;line-height:115%;"> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal">
<p><img src="http://acollado.files.wordpress.com/2008/05/backgroundworkerprogress.jpg?w=455" alt="" /></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p>Como hemos podido ver, el código es sencillo. Con unas pocas lineas podremos dar soporte estable a nuestras operaciones asíncronas.</p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;"> </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal">
<p class="MsoNormal">
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acollado.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acollado.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acollado.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acollado.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acollado.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=28&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acollado.wordpress.com/2008/05/11/mostrar-progresos-con-backgroundworker/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2870ea16cef0e78fd4be56eaadcc37e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">acollado</media:title>
		</media:content>

		<media:content url="http://acollado.files.wordpress.com/2008/05/backgroundworker.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/backgroundworkerprogress.jpg" medium="image" />
	</item>
		<item>
		<title>Delegados genéricos</title>
		<link>http://acollado.wordpress.com/2008/05/10/delegados-genericos/</link>
		<comments>http://acollado.wordpress.com/2008/05/10/delegados-genericos/#comments</comments>
		<pubDate>Sat, 10 May 2008 20:39:46 +0000</pubDate>
		<dc:creator>acollado</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Delegados]]></category>
		<category><![CDATA[Genéricos]]></category>

		<guid isPermaLink="false">http://acollado.wordpress.com/?p=27</guid>
		<description><![CDATA[Para poder entender correctamente los delegados genéricos debemos comprender antes algunos aspectos que explico a continuación. Delegados: Los delegados son una parte fundamental del Framework de .Net, pero… ¿Que es exactamente un delegado?, un delegado es un tipo que apunta a un método. Con la característica principal que dicho método ha de tener el mismo [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=27&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Para poder entender correctamente los delegados genéricos debemos comprender antes algunos aspectos que explico a continuación.</p>
<h3><strong>Delegados:</strong></h3>
<p class="MsoNormal">Los delegados son una parte fundamental del Framework de .Net, pero… ¿Que es exactamente un delegado?, un delegado es un tipo que apunta a un método. Con la característica principal que dicho método ha de tener el mismo tipo de parámetros y valor devuelto.</p>
<table class="MsoNormalTable" style="border-collapse:collapse;height:29px;" border="0" cellspacing="0" cellpadding="0" width="682">
<tbody>
<tr>
<td style="background:#d6e3bc none repeat scroll 0;width:432.2pt;padding:0 5.4pt;" width="660" valign="top"><span style="color:#339966;"><strong><span>Nota:<br />
Los delegados son algo parecido a los punteros   a funciones de C++, pero más potentes<br />
y seguros.</span></strong></span></td>
</tr>
</tbody>
</table>
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">Veamos un ejemplo:</p>
<p class="MsoNormal"><strong>C#</strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">class</span><span style="font-size:10pt;"> <span style="color:#2b91af;">Program</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">/*</span></span></p>
<p><span style="font-size:10pt;"><span style="color:green;"> Declaramos un delegado que apuntará a un metodo<br />
</span></span><span style="font-size:10pt;"><span style="color:green;">que ha de retornar un tipo int y tener dos parametros de tipo int</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"><span style="color:green;">*/</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">private</span> <span style="color:blue;">delegate</span> <span style="color:blue;">int</span> <span style="color:#2b91af;">CalculateHandler</span>(<span style="color:blue;">int</span> numA, <span style="color:blue;">int</span> numB);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Creamos una instancia del delegado  que apunte al metodo Calc</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">CalculateHandler</span> calcDelegate = <span style="color:blue;">new</span> <span style="color:#2b91af;">CalculateHandler</span>(Calc);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Invocamos al delegado </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Resultado de la invocación al delegado: &#8220;</span>+calcDelegate(5,5).ToString());</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Otra forma de invocar al delegado</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Resultado de la invocación al delegado con Invoke: &#8220;</span>+calcDelegate.Invoke(5, 5).ToString());</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">Console</span>.Read();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Aquí hacemos la declaración del metodo para nuentro     delegado. </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">private</span><span style="font-size:10pt;"> <span style="color:blue;">static</span> <span style="color:blue;">int</span> Calc(<span style="color:blue;">int</span> numA, <span style="color:blue;">int</span> numB)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">return</span> numA + numB;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;">VB</span></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">Module</span><span style="font-size:10pt;"> Module1</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p><span style="font-size:10pt;"><span style="color:green;">&#8216;Declaramos un delegado que apuntará a un metodo que ha de retornar un tipo Integer  y tener dos parametros de tipo Integer<br />
</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">Delegate</span><span style="font-size:10pt;"> <span style="color:blue;">Function</span> CalculateHandler(<span style="color:blue;">ByVal</span> numA <span style="color:blue;">As</span> <span style="color:blue;">Integer</span>, <span style="color:blue;">ByVal</span> numB <span style="color:blue;">As</span> <span style="color:blue;">Integer</span>) <span style="color:blue;">As</span> <span style="color:blue;">Integer</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Sub</span><span style="font-size:10pt;"> Main()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Creamos una instancia del delegado  que apunte al metodo Calc</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Dim</span><span style="font-size:10pt;"> calcDelegate <span style="color:blue;">As</span> <span style="color:blue;">New</span> CalculateHandler(<span style="color:blue;">AddressOf</span> Calc)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;"><span style="color:green;">&#8216;Invocamos al delegado<br />
</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Console.WriteLine(<span style="color:#a31515;">&#8220;Resultado de la invocación al delegado: &#8220;</span> + calcDelegate(5, 5).ToString())</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Otra forma de invocar al delegado</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Console.WriteLine(<span style="color:#a31515;">&#8220;Resultado de la invocación al delegado con Invoke: &#8220;</span> + calcDelegate.Invoke(5, 5).ToString())</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Console.Read()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Private</span> <span style="color:blue;">Function</span> Calc(<span style="color:blue;">ByVal</span> numA <span style="color:blue;">As</span> <span style="color:blue;">Integer</span>, <span style="color:blue;">ByVal</span> numB <span style="color:blue;">As</span> <span style="color:blue;">Integer</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Return</span><span style="font-size:10pt;"> numA + numB</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Function</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">End</span><span style="font-size:10pt;line-height:115%;"> <span style="color:blue;">Module</span></span></p>
<p>En este sencillo ejemplo declaramos un delegado que apunta a una función y despues lo invocamos.</p>
<h3><strong>Tipos genéricos:</strong></h3>
<p>Desde la versión del Framework 2.0  se incluyen los tipos genéricos. Los tipos genéricos nos servirán para declarar código genérico, de forma que podremos preparar un elemento para recibir cualquier tipo.</p>
<table class="MsoNormalTable" style="border-collapse:collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#d6e3bc none repeat scroll 0;width:432.2pt;padding:0 5.4pt;" width="660" valign="top"><span style="color:#339966;"><strong>Nota:<br />
Antes de la implementación de los tipos genéricos se podía obtener un   resultado parecido con  el tipo object, que es el  tipo base del   cual descienden todos los tipos del .Net Framework.</strong></span></td>
</tr>
</tbody>
</table>
<p class="MsoNormal">
<p class="MsoNormal">Veamos un ejemplo:</p>
<p class="MsoNormal"><strong>C#</strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">class</span><span style="font-size:10pt;"> <span style="color:#2b91af;">Program</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">//Lista genérica que contendrá elementos del tipo empleado</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">static</span><span style="font-size:10pt;"> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">Empleados</span>&gt; listaGenericaEmpleados;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> listaGenericaEmpleados = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">Empleados</span>&gt;();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> listaGenericaEmpleados.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">Empleados</span>());</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Empleados</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {<span style="color:green;">//Miembros de la clase empleados. </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;">VB</span></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">Module</span><span style="font-size:10pt;"> Module1</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Lista genérica que contendrá elementos del tipo empleado</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Dim</span><span style="font-size:10pt;"> listaGenericaEmpleados <span style="color:blue;">As</span> List(<span style="color:blue;">Of</span> Empleados)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Sub</span> Main()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Dim</span> listaGenericaEmpleados <span style="color:blue;">As</span> <span style="color:blue;">New</span> List(<span style="color:blue;">Of</span> Empleados)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> listaGenericaEmpleados.Add(<span style="color:blue;">New</span> Empleados())</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Class</span><span style="font-size:10pt;"> Empleados</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Miembros de la clase empleados. </span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Class</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">End</span><span style="font-size:10pt;"> <span style="color:blue;">Module</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p>En este ejemplo declaramos una lista que contendrá elmentos del tipo empleados que ha sido definido por nosotros.</p>
<h3><strong>Delegados genénericos:</strong></h3>
<p>Al principio de este post, he descrito que un delegado ha de tener el mismo tipo de parámetros y valor devuelto que el método al que apuntará, pero…<strong> ¿Y si un delegado se pudiera declarar con parámetros del tipo genérico, y así poder dar flexibilidad a la función a la que apunte para poder implementar cualquier tipo de parámetros sin la necesidad de que sean del tipo object?</strong> Eso se consigue con los delegados genéricos.</p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;">C#</span></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">class</span><span style="font-size:10pt;"> <span style="color:#2b91af;">Program</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"><span style="color:green;">//Declaramos un delegado genérico</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">delegate</span> <span style="color:blue;">string</span> <span style="color:#2b91af;">GenericDelegate</span>&lt;T,T2&gt;(T valor1, T2 valor2);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"><span style="color:green;">//Instanciamos el delegado genérico con tipos int y string<br />
</span></span><span style="font-size:10pt;">GenericDelegate</span><span style="font-size:10pt;">&lt;<span style="color:blue;">int</span>, <span style="color:blue;">string</span>&gt; delegado1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">GenericDelegate</span>&lt;<span style="color:blue;">int</span>, <span style="color:blue;">string</span>&gt;(Valores);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">Console</span>.WriteLine(delegado1(1,<span style="color:#a31515;">&#8220;1&#8243;</span>));</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;"><span style="color:green;">//Instanciamos el delegado genérico con tipos string y string</span></span><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">GenericDelegate</span><span style="font-size:10pt;">&lt;<span style="color:blue;">string</span>, <span style="color:blue;">string</span>&gt; delegado2 = <span style="color:blue;">new</span> <span style="color:#2b91af;">GenericDelegate</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">string</span>&gt;(Valores);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Console</span><span style="font-size:10pt;">.WriteLine(delegado2(<span style="color:#a31515;">&#8220;1&#8243;</span>, <span style="color:#a31515;">&#8220;1&#8243;</span>));</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">Console</span>.Read();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">}</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> Valores(<span style="color:blue;">int</span> val1, <span style="color:blue;">string</span> val2)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">return</span> val1 + val2;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> Valores(<span style="color:blue;">string</span> val1, <span style="color:blue;">string</span> val2)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">return</span> val1 + val2;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> }</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;">VB</span></strong></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">Module</span><span style="font-size:10pt;"> Module1</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Declaramos el delegado genérico</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Delegate</span><span style="font-size:10pt;"> <span style="color:blue;">Function</span> GenericDelegate(<span style="color:blue;">Of</span> T, T2)(<span style="color:blue;">ByVal</span> val1 <span style="color:blue;">As</span> T, <span style="color:blue;">ByVal</span> val2 <span style="color:blue;">As</span> T2) <span style="color:blue;">As</span> <span style="color:blue;">String</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Sub</span><span style="font-size:10pt;"> Main()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Instanciamos el delegado genérico con tipos int y string</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Dim</span><span style="font-size:10pt;"> delegado1 <span style="color:blue;">As</span> <span style="color:blue;">New</span> GenericDelegate(<span style="color:blue;">Of</span> <span style="color:blue;">Integer</span>, <span style="color:blue;">String</span>)(<span style="color:blue;">AddressOf</span> Valores)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Console.WriteLine(delegado1(1, <span style="color:#a31515;">&#8220;1&#8243;</span>))</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:green;">&#8216;Instanciamos el delegado genérico con tipos string y string</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Dim</span><span style="font-size:10pt;"> delegado2 <span style="color:blue;">As</span> <span style="color:blue;">New</span> GenericDelegate(<span style="color:blue;">Of</span> <span style="color:blue;">String</span>, <span style="color:blue;">String</span>)(<span style="color:blue;">AddressOf</span> Valores)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Console.WriteLine(delegado2(<span style="color:#a31515;">&#8220;1&#8243;</span>, <span style="color:#a31515;">&#8220;1&#8243;</span>))</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Console.Read()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">End</span><span style="font-size:10pt;"> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Private</span> <span style="color:blue;">Function</span> Valores(<span style="color:blue;">ByVal</span> val1 <span style="color:blue;">As</span> <span style="color:blue;">Integer</span>, <span style="color:blue;">ByVal</span> val2 <span style="color:blue;">As</span> <span style="color:blue;">String</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Return</span> val1 + val2</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Function</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">Private</span> <span style="color:blue;">Function</span> Valores(<span style="color:blue;">ByVal</span> val1 <span style="color:blue;">As</span> <span style="color:blue;">String</span>, <span style="color:blue;">ByVal</span> val2 <span style="color:blue;">As</span> <span style="color:blue;">String</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">Return</span><span style="font-size:10pt;"> val1 + val2</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">End</span> <span style="color:blue;">Function</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">End</span><span style="font-size:10pt;line-height:115%;"> <span style="color:blue;">Module</span></span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;line-height:115%;"> </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<p>Como hemos podido ver, los delegados genericos nos ofrecen una flexibilidad importante a la hora de desarrollar de una forma más escalable.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acollado.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acollado.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acollado.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acollado.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acollado.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=27&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acollado.wordpress.com/2008/05/10/delegados-genericos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2870ea16cef0e78fd4be56eaadcc37e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">acollado</media:title>
		</media:content>
	</item>
		<item>
		<title>Acceso a base de datos embebidas Firebird desde .net</title>
		<link>http://acollado.wordpress.com/2008/05/06/acceso-a-base-de-datos-embebidas-firebird-desde-net/</link>
		<comments>http://acollado.wordpress.com/2008/05/06/acceso-a-base-de-datos-embebidas-firebird-desde-net/#comments</comments>
		<pubDate>Tue, 06 May 2008 19:02:12 +0000</pubDate>
		<dc:creator>acollado</dc:creator>
				<category><![CDATA[Bases de datos]]></category>
		<category><![CDATA[Firebird]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Hace tiempo, se me planteo la necesidad de implementar una base de datos independiente de un servidor y que el mantenimiento de dicha base de datos fuera lo más escalable posible, cuando programas desde y hacia tecnologías de Microsoft la respuesta es obvia: Access, pero Access tiente el serio inconveniente de que no acepta procedimientos [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=1&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Hace tiempo, se me planteo la necesidad de implementar una base de datos independiente de un servidor y que el mantenimiento de dicha base de datos fuera lo más escalable posible, cuando programas desde y hacia tecnologías de Microsoft la respuesta es obvia: Access, pero Access tiente el serio inconveniente de que no acepta procedimientos almacenados, para mi esta característica es fundamental, ya que los procedimientos almacenados aumentan la potencia y escalabilidad de la base de datos de una forma considerable, entonces ¿Cómo lo hacemos?, ¿es posible implementar una base de datos que admita procedimientos almacenados y se pueda implementar con nuestra aplicación sin un servidor de base de datos?, la respuesta en sí, se llama Firebird. Firebird es una base de datos relacional (<span style="font-size:10pt;line-height:115%;">RDBMS)</span> de código abierto y que además dispone de unas bibliotecas para .Net Framework.</p>
<p class="MsoNormal"><span> </span>Manos a la obra.</p>
<p class="MsoNormal">Lo primero es descargar desde <a href="http://downloads.sourceforge.net/firebird/Firebird-2.1.0.17798-0_Win32_embed.zip">aquí</a> la versión <span>embedded, que nos permitirá, como su propio nombre indica, “embeber” la base de datos y todos<span> </span>sus controladores en el directorio de nuestra aplicación.</span></p>
<p><img src="http://acollado.files.wordpress.com/2008/05/fb_files.jpg?w=455" alt="" /></p>
<p class="MsoNormal">Cuando descomprimamos el archivo veremos una serie de archivos y carpetas, los que he marcado en un recuadro son los que debemos copiar el directorio raíz de nuestra aplicación.</p>
<p class="MsoNormal">Después descargamos desde <a href="http://www.firebirdsql.org/index.php?op=files&amp;id=netprovider">aquí</a> el Firebird .NET Data Provider para poder acceder desde nuestro lenguaje<span> </span>.Net (C# y Vb.Net en nuestro caso), y lo instalamos.</p>
<p class="MsoNormal"><img src="http://acollado.files.wordpress.com/2008/05/firebirdclient.jpg?w=461&#038;h=361" alt="" width="461" height="361" /></p>
<p class="MsoNormal">Bien, ya tenemos el controlador para usar Firebird desde .Net y los archivos de Firebird pero… ¿Cómo empezamos a trabajar con ella? Pues instalando el servidor de Firebird para crear el archivo de datos que contendrá los procedimientos, tablas etc. ¿Pero&#8230; no hemos dicho que no necesitamos servidor de base de datos?, si así es, la aplicación en producción no lo necesitara, pero nosotros para trabajar con ella sí, así es que descargamos el servidor desde <a href="http://downloads.sourceforge.net/firebird/Firebird-2.1.0.17798_0_Win32.exe">aquí</a> y los instalamos.</p>
<p class="MsoNormal">Durante la instalación nos dejara elegir el tipo de servidor que queremos, Classic o Superserver, seleccionaremos “Superserver”.</p>
<p class="MsoNormal">Una vez instalado veremos que nos ha dejado entre otros este archivo: &#8220;C:\Archivos de programa\Firebird\Firebird_2_1\bin\isql.exe&#8221;, que nos servirá para crear y administrar los objetos de la base de datos en modo de línea comandos, pero que no cunda el pánico, hay herramientas que le proporcionan un entorno visual o IDE para trabajar más cómodamente, en nuestro caso usaremos FlameRobin, que es una herramienta multiplataforma para la administración de la base de datos de Firebird, que al menos, en el momento de escribir estas líneas es de uso libre y podemos descargar desde <a href="http://downloads.sourceforge.net/flamerobin/flamerobin-0.8.6-setup.exe?modtime=1205754961&amp;big_mirror=0">aquí</a></p>
<p><img src="http://acollado.files.wordpress.com/2008/05/firebirdcmd.jpg?w=432&#038;h=280" alt="" width="432" height="280" /></p>
<p class="MsoNormal">Una vez hecho todo, registramos el servidor en el entorno de FlameRobin y creamos nuestra base de datos. En el momento de crear la base de datos nos pedirá que le indiquemos donde guardar el archivo de base de datos, este archivo hay que copiarlo en el raíz de nuestra aplicación junto con<span> </span>los archivos de Firebird embebido que nos hemos descargado antes.</p>
<p><img src="http://acollado.files.wordpress.com/2008/05/flamerobin.jpg?w=455" alt="" /></p>
<p class="MsoNormal">Ahora solo nos queda acceder a nuestra base de datos desde nuestra aplicación.<br />
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--></p>
<p class="MsoNormal">Agregamos a nuestra aplicación las referencias a las bibliotecas que contienen el proveedor de datos de Firebird.</p>
<p class="MsoNormal"><img src="http://acollado.files.wordpress.com/2008/05/firebirdreferences.jpg?w=535&#038;h=382" alt="" width="535" height="382" /></p>
<p class="MsoNormal">Ahora nos ponemos manos a la obra con el código.</p>
<p class="MsoNormal"><strong><span>SQL</span></strong></p>
<p><img src="http://acollado.files.wordpress.com/2008/05/firebirdsql.jpg?w=535&#038;h=458" alt="" width="535" height="458" /></p>
<p class="MsoNormal"><strong><span> </span></strong></p>
<p class="MsoNormal"><strong>C#</strong></p>
<p><img src="/Users/Andres/AppData/Local/Temp/moz-screenshot.jpg" alt="" /></p>
<p class="MsoNormal"><img src="http://acollado.files.wordpress.com/2008/05/firebirdconncs.jpg?w=529&#038;h=460" alt="" width="529" height="460" /></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><strong>VB</strong></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><img src="http://acollado.files.wordpress.com/2008/05/firebirdconnvb1.jpg?w=537&#038;h=418" alt="" width="537" height="418" /></p>
<p class="MsoNormal">
<p>Y esto es todo, ya tenemos nuestra base de datos embebida y lista para agregarla al instalador de nuestra aplicación o distribuirla simplemente junto con los ejecutables y bibliotecas de la aplicación.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acollado.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acollado.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acollado.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acollado.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acollado.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=1&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acollado.wordpress.com/2008/05/06/acceso-a-base-de-datos-embebidas-firebird-desde-net/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2870ea16cef0e78fd4be56eaadcc37e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">acollado</media:title>
		</media:content>

		<media:content url="http://acollado.files.wordpress.com/2008/05/fb_files.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdclient.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdcmd.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/flamerobin.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdreferences.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdsql.jpg" medium="image" />

		<media:content url="/Users/Andres/AppData/Local/Temp/moz-screenshot.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdconncs.jpg" medium="image" />

		<media:content url="http://acollado.files.wordpress.com/2008/05/firebirdconnvb1.jpg" medium="image" />
	</item>
		<item>
		<title>Precarga en ASP.NET con AJAX (1)</title>
		<link>http://acollado.wordpress.com/2008/05/02/precarga-en-aspnet-con-ajax-1/</link>
		<comments>http://acollado.wordpress.com/2008/05/02/precarga-en-aspnet-con-ajax-1/#comments</comments>
		<pubDate>Fri, 02 May 2008 06:49:19 +0000</pubDate>
		<dc:creator>acollado</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Piensa en asíncrono]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Precarga]]></category>

		<guid isPermaLink="false">http://acollado.wordpress.com/?p=31</guid>
		<description><![CDATA[A todos los que desarrollamos en entorno Web con Asp.Net se nos ha presentado en algún momento la necesidad de mostrar una precarga en mientras se realizaba alguna operación. Por ejemplo, mientras se llena un Datagrid. Desde la versión 2.0 de Asp.Net esto es más fácil gracias a AJAX. Que es AJAX: AJAX (Asynchronous JavaScript [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=31&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A todos los que desarrollamos en entorno Web con Asp.Net se nos ha presentado en algún momento la necesidad de mostrar una precarga en mientras se realizaba alguna operación. Por ejemplo, mientras se llena un Datagrid. Desde la versión 2.0 de Asp.Net esto es más fácil gracias a AJAX.</p>
<p>Que es AJAX:</p>
<p>AJAX (Asynchronous JavaScript And XML) nos permitirá realizar operaciones de manera asíncrona en nuestras aplicaciones Web. Esto quiere decir, que no tendremos que hacer Postback (Viajes de ida y vuelta al servidor)   para realizar algunas operaciones que antes lo requerían.</p>
<p class="MsoNormal">
<p>Empezamos:</p>
<p>En nuestro ejemplo realizaremos una tarea que llevara algo de tiempo y mostraremos una imagen animada mientras esto sucede.</p>
<p class="MsoNormal">
<p>Código:</p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="background:yellow none repeat scroll 0 50%;font-size:10pt;">&lt;%</span><span style="font-size:10pt;">@</span><span style="font-size:10pt;"> <span style="color:#a31515;">Page</span> <span style="color:red;">Language</span><span style="color:blue;">=&#8221;C#&#8221;</span> <span style="color:red;">AutoEventWireup</span><span style="color:blue;">=&#8221;true&#8221;</span> <span style="background:yellow none repeat scroll 0;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;</span><span style="font-size:10pt;">script</span><span style="font-size:10pt;"> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">language</span><span style="color:blue;">=&#8221;C#&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;">
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">public</span> <span style="color:blue;">void</span> Fill()</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#2b91af;">ArrayList</span> vals = <span style="color:blue;">new</span> <span style="color:#2b91af;">ArrayList</span>(30);</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 1; i &lt;= 30; i++)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> vals.Add(<span style="color:#a31515;">&#8220;Elemento: &#8220;</span> + i.ToString());</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Grid1.DataSource = vals;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Grid1.DataBind();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">protected</span> <span style="color:blue;">void</span> Button1_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span><span style="font-size:10pt;">{</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> Fill();</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;/</span><span style="font-size:10pt;">script</span><span style="font-size:10pt;">&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;!</span><span style="font-size:10pt;">DOCTYPE</span><span style="font-size:10pt;"> <span style="color:red;">html</span> <span style="color:red;">PUBLIC</span> <span style="color:blue;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span> <span style="color:blue;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;</span><span style="font-size:10pt;">html</span><span style="font-size:10pt;"> <span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;</span><span style="font-size:10pt;">head</span><span style="font-size:10pt;"> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">title</span><span style="color:blue;">&gt;</span>Página sin título<span style="color:blue;">&lt;/</span><span style="color:#a31515;">title</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">style</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;text/css&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:#a31515;">.loading</span> {</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:red;">color</span>: <span style="color:blue;">#FF9900</span>;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> }</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">style</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;/</span><span style="font-size:10pt;">head</span><span style="font-size:10pt;">&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;</span><span style="font-size:10pt;">body</span><span style="font-size:10pt;">&gt;</span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">form</span> <span style="color:red;">id</span><span style="color:blue;">=&#8221;form1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">div</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">div</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">ScriptManager</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ScriptManager1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">ScriptManager</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">UpdatePanel</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;UpdatePanel1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">ContentTemplate</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">Button</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;Button1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">Text</span><span style="color:blue;">=&#8221;Cargar datos&#8221;</span> <span style="color:red;">onclick</span><span style="color:blue;">=&#8221;Button1_Click&#8221;</span> <span style="color:blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">GridView</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;Grid1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">Width</span><span style="color:blue;">=&#8221;519px&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">GridView</span><span style="color:blue;">&gt;</span> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">ContentTemplate</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">UpdatePanel</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">UpdateProgress</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;UpdateProgress1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:red;">AssociatedUpdatePanelID</span><span style="color:blue;">=&#8221;UpdatePanel1&#8243;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">ProgressTemplate</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">span</span><span style="color:blue;">&gt;</span> <span style="color:blue;">&lt;</span><span style="color:#a31515;">img</span> <span style="color:red;">src</span><span style="color:blue;">=&#8221;imgs/loader.gif&#8221;</span> <span style="color:blue;">/&gt;&lt;/</span><span style="color:#a31515;">span</span><span style="color:blue;">&gt;</span> <span style="color:blue;">&lt;</span><span style="color:#a31515;">span</span> <span style="color:red;">class</span><span style="color:blue;">=&#8221;loading&#8221;&gt;</span> Cargando datos&#8230; </span><span style="font-size:10pt;">&lt;/</span><span style="font-size:10pt;">span</span><span style="font-size:10pt;">&gt;</span><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">ProgressTemplate</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">UpdateProgress</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">form</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><span style="font-size:10pt;">&lt;/</span><span style="font-size:10pt;">body</span><span style="font-size:10pt;">&gt;</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;">&lt;/</span><span style="font-size:10pt;line-height:115%;">html</span><span style="font-size:10pt;line-height:115%;">&gt;</span><span style="font-size:10pt;line-height:115%;"> </span></p>
<p>Como podeis ver, el ejemplo es muy básico. Hemos introducido los controles que se han de ejecutar en un contexto asincrono en el control UpdatePanel, a su vez colocamos un control UpdateProgress que mostrara la imagen mientras dure la operación y lo hemos asociado al control UpdatePanel.</p>
<p>Esto solo a sido la primera parte de una serie de articulos sobre el mismo tema. Según tenga tiempo los ire subiendo.</p>
<table class="MsoTableColorfulGridAccent3" style="border-collapse:collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#d6e3bc none repeat scroll 0;width:432.2pt;padding:0 5.4pt;" width="660" valign="top">
<p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"><strong><span style="color:#339966;">Nota:<br />
En esta ocasión no   he introducido el código en VB ya que opino que en este caso no hay nada de   especial relevancia.</span></strong><strong></strong></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;"> </span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acollado.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acollado.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acollado.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acollado.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acollado.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acollado.wordpress.com&amp;blog=3657593&amp;post=31&amp;subd=acollado&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acollado.wordpress.com/2008/05/02/precarga-en-aspnet-con-ajax-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f2870ea16cef0e78fd4be56eaadcc37e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">acollado</media:title>
		</media:content>
	</item>
	</channel>
</rss>
