Jose R. Guay Paz

Most of the time on
ASP.NET, C# & SQL Server

Sponsors

News

INETA Community Speakers Program

My latest tweets

this.blog.owner=

  • CSW Solutions
  • Follow Me
  • Works On My Machine

.NET Communities

  • INETA Latam

Blogs I Read

Websites I like

July 2008 - Posts

Official Note: Version 1.0 RTM of the SQL Server 2005 Driver for PHP is live!

It's official. You can now download version 1.0 RTM of the SQL Server 2005 Driver for PHP from the MSDN download site

The SQL Server 2005 Driver for PHP download is available to all SQL Server users at no additional charge.

The SQL Server 2005 Driver for PHP is a PHP 5 extension that allows for the reading and writing of SQL Server data from within PHP scripts. The extension provides a procedural interface for accessing data in all editions of SQL Server 2005.

Enjoy!

Noticia Oficial: La Versión 1.0 RTM Del Driver de SQL Server 2005 Para PHP Ha Sido Liberada

La versión 1.0 del Driver de SQL Server 2005 para PHP está disponible en el sitio de descargas de MSDN.

Ahora si, no hay excusas. Esta, es una extensión de PHP 5 que permite la lectura y escritura de datos almacenados en SQL Server 2005 desde scripts de PHP. La extensión provee de una interface procedural para el acceso a datos de cualquier edición de SQL Server 2005.

Saludos.

Having RadioButtons on a Repeater or DataList

Repeaters are very powerful controls that allows us to present formated information from a datasource.

Recently I needed to include some RadioButtons inside a Repeater so I could select one of the items from the repeater, but to my surprise, and old bug resurfaced. Reference to the bug can be found here but I will include some information regarding it:

SYMPTOMS

When you add a ASP.NET RadioButton control to the ItemTemplate of a data-bound Repeater server control, the RadioButton control that you created is not mutually exclusive when you run the ASP.NET page. This problem occurs even if the GroupName attribute is set for the RadioButton controls.

CAUSE

This problem occurs because the Repeater server control implements the INamingContainer interface, which requires that all controls that are nested within it must have a unique name when rendered in Hypertext Markup Language (HTML). Therefore, the HTML name attribute of any rendered child server control is unique.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Well, the products in cuestion are:

  • Microsoft ASP.NET 1.0
  • Microsoft ASP.NET 1.1

But guess what, it happens also in ASP.NET 2.0/3.0/3.5, so someone forgot to fix this thing.

Anyway, I found this very helpful article from Erick Smith at CodeGuru.com that helps overcome this problem. The solution is a JavaScript function that will be attached to every RadioButton as it is being bounded in the Repeater. The function is:

function SetUniqueRadioButton(nameregex, current)
{
      re =
new RegExp(nameregex);
     
for(i = 0; i < document.forms[0].elements.length; i++)
      
{
            elm = document.forms[0].elements[i]
            
if (elm.type == 'radio')
            {
                 
if (re.test(elm.name))
                  {
                          elm.checked =
false;
                  }
             }
      }
      current.checked =
true;
}

That you must add to your page on the HEAD section. Then link the function to the RadioButtons in the OnItemDataBound event for the Repeater. NOTE that you must know the Repeater name and the GroupName for the RadioButtons. For this example, the name of the Repeater is "Repeater1" and the name of the RadioButtons GroupName property is "RadioGroup".

And that's it. You will end up with a bunch of RadioButtons all with the same GroupName and working as expected.

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
     
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return;
     
RadioButton rb = (RadioButton) e.Item.FindControl("RadioButton");
      string script = "SetUniqueRadioButton('Repeater1.*RadioGroup',this)";
      rb.Attributes.Add(
"onclick", script);
}

But you know what, this can also be applied for DataList controls. In the source code that I've included I have a page with a Repeater and a DataList so you can see that it's exactly the same form of solution.

Hope you like it. Enjoy!

 

Ensure Proper Closure & Disposal Of A DataReader

Most of the time, we create programs that use DataReaders (weather they are on ASP.NET or Winforms). They're fast, easy to use but sometimes, they fill out our connections pool and withour proper care, they can cause problems to our users.

There are some blog posts around this issue and many questions in the forums, so I'll try to make it as simple as possible so you'll find it attractive to use, because in the end, there is no magic here, just a nice tip.

The solution: Use the DataReader within the scope of a using clause. How? Take a look at this sample:

Regular Programming
In general, programmers tend to use DataReaders like this:

SqlConnection connection = new SqlConnection("connection string");
SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection);
SqlDataReader reader = cmd.ExecuteReader();
if (reader != null)
{
      while (reader.Read())
      {
             
//do something
      
}
}
reader.Close();
reader.Dispose();

While this would work and do excatly what you need it to do, it does not ensure that the reader will be actualy closed and disposed. Why? it's by design. DataReaders will be kept open until they got all the data from the source and even then, they depend on the command object that should be opened with the CommandBehavior.CloseConnection parameter.

So, anyway. Here is my proposed solution to overcome this problems.

using (SqlDataReader reader = cmd.ExecuteReader())
{
       if (reader != null)
       {
              while (reader.Read())
              {
                        //do something
              }
              reader.Close();
              reader.Dispose();
       }
}

Why this works better? Because the DataReader lives only within the scope of the using clause. Once the flow leaves the using clause the datareader is forced to deallocate from memory thus closing/disposing it properly.

Hope this will help you get the most of DataReaders because, yes, they are the FASTEST way to get data from any datasource.

Enjoy!!

 

Ya Disponible: Preview 1 de ASP.NET AJAX 4.0

Ya es oficial!!

El Primer Preview de ASP.NET Ajax 4.0 acaba de salir a la luz. Pueden ver el Roadmap para mas información sobre el contenido de este preview y si pueden, por favor envíen un poco de feedback.

Este preview contiene (entre otros) las siguientes implementaciones:

  • Client-side template rendering
  • Declarative instantiation of behaviors and controls
  • DataView control
  • Markup extensions
  • Bindings

La página de descarga de CodePlex está aquí.

Saludos!!

Now Available at CodePlex: ASP.NET AJAX 4.0 Preview 1

Well, it's official. The first preview for the new Ajax features in ASP.NET just went live. Check out the Roadmap for information about what it covers and if you can, provide some feedback.

This preview contains preview implementations for the following features:

  • Client-side template rendering
  • Declarative instantiation of behaviors and controls
  • DataView control
  • Markup extensions
  • Bindings

You can find the download page at CodePlex here.

Enjoy!!

 

Now Available: SubSonic 2.1 is Finally Here :)

Hi all.

I'm a bit late but it's never late for good news. It's here, now SubSonic 2.1 has finally arrived.

Description

  • SqlQuery, our next-generation querying engine
  • SubStage, a visual configuration management and code generation tool
  • Programmatic migrations between database versions
  • Greatly improved documentation across the entire code base
  • Improvements in performance and stability
  • ...and a massive collection of bug fixes and assorted goodies

You can get it from the codeplex website here.

Enjoy!

SubSonic 2.1 Liberado

Hola a todos.

Un poco tarde lo se, pero nunca es tarde para las buenas noticias. Ya ha sido liberada la versión 2.1 de SubSonic.

Descripción

  • SqlQuery, el motor de consultas de siguiente generación
  • SubStage, una herramienta visual de generación de código y administración de configuración
  • Migraciones programadas entre diferentes versiones de bases de datos
  • Documentación mejorada
  • Mejoras en rendimiento y estabilidad
  • ... y una masiva colección de arreglos a problemas y diferentes cositas para ayudarnos

Pueden descargarlo del sitio de codeplex aquí.

Saludos.

Security Best Practices Videos for ASP.NET Websites

New video series by Microsoft’s Joe Stagner focused on security best practices for ASP.NET websites.

Security Videos on ASP.NET

ASP.NET MVC Preview 4 Liberado en CodePlex

Hola a todos.

El Preview 4 de ASP.NET MVC ha sido liberado en CodePlex.

Saludos.

More Posts Next page »