Problem with a DataList ItemCommand if the page is use a MasterPage

I have an strange problem, If a use a MasterPage, the Itemcommand of DataList don't execute.

I've simplified the code to the minimun, and this is:

<%@ Master Language="VB" CodeFile="MasterPagePruebas.master.vb" Inherits="MasterPagePruebas" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPagePruebas.master" AutoEventWireup="true"  EnableEventValidation="false"  CodeFile="tiendas4.aspx.vb" Inherits="tiendas4" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:SqlDataSource ID="SqlDataSourceTiendas" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT Member_Id, IdTienda, Nombre_Fiscal, Nombre_Comercial, Lema, Persona_Contacto, Calle, CodPostal, CodProvincia, Poblacion, email, web, Telefono, Fax, logo, activo FROM Tiendas"></asp:SqlDataSource>
            <asp:DataList ID="DataListTiendas" runat="server" DataKeyField="IdTienda"
            DataSourceID="SqlDataSourceTiendas">
          <ItemTemplate>
           <span class="tienda_nombre"><asp:Label ID="Nombre_ComercialLabel" runat="server" Text='<%# Eval("Nombre_Comercial") %>' /></span><br />
                 <asp:Button ID="Button2" runat="server" Text=" Ver todos sus productos" CommandName="VerArticulosDelCliente" CommandArgument='<%# Eval("IdTienda") %>'/>
           </ItemTemplate>
        </asp:DataList>
  </asp:Content>


Partial Class tiendas4
    Inherits System.Web.UI.Page
    Protected Sub DataListTiendas_ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataListTiendas.ItemCommand
        If e.CommandName = "VerArticulosDelCliente" Then
            Dim strCodigoTienda As String = Trim(e.CommandArgument)
            Session("IdTienda") = strCodigoTienda
            Response.Redirect("Default.aspx?B=2")
        End If
    End Sub
End Class






THIS VERSION DON0T WORK IY NEED THE BUTTON REDIRECT TO ANOTHER PAGE.

THIS OTHER VERSION WITOUT MASTER PAGE WORKS

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="tiendas3.aspx.vb" Inherits="tiendas3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <div id="contenido2">
     <asp:SqlDataSource ID="SqlDataSourceTiendas" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT Member_Id, IdTienda, Nombre_Fiscal, Nombre_Comercial, Lema, Persona_Contacto, Calle, CodPostal, CodProvincia, Poblacion, email, web, Telefono, Fax, logo, activo FROM Tiendas"></asp:SqlDataSource>
            <asp:DataList ID="DataListTiendas" runat="server" DataKeyField="IdTienda"
            DataSourceID="SqlDataSourceTiendas">
            <ItemTemplate>
             <span class="tienda_nombre"><asp:Label ID="Nombre_ComercialLabel" runat="server" Text='<%# Eval("Nombre_Comercial") %>' /></span><br />
                 <asp:Button ID="Button2" runat="server" Text=" Ver todos sus productos" CommandName="VerArticulosDelCliente" CommandArgument='<%# Eval("IdTienda") %>'/>
           </ItemTemplate>
       </asp:DataList>
       </form>
</body>
</html>


Partial Class tiendas3
    Inherits System.Web.UI.Page
    Protected Sub DataListTiendas_ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataListTiendas.ItemCommand
        If e.CommandName = "VerArticulosDelCliente" Then
            Dim strCodigoTienda As String = Trim(e.CommandArgument)
            Session("IdTienda") = strCodigoTienda
            Response.Redirect("Default.aspx?B=2")
        End If
    End Sub
End Class
limmontreefreeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale BurrellDirectorCommented:
I think the issue is related to the AutoEventWireup="false" setting, on the page that doesn't work its AutoEventWireup="true" and on the page that works its AutoEventWireup="false". I don't quite understand how the 'handles' keyword (http://msdn.microsoft.com/en-us/library/6k46st1y(v=vs.71).aspx) works as I'm not familiar with VB. Therefore I'm not totally sure I'm correct, and to be honest its backwards to my way of thinking - al I can imagine is that when it automatically wires up the events that over-writes you event association.

However there is another way I believe to assign the event handler as part of the control declaration:

<asp:DataList ID="DataListTiendas" runat="server" DataKeyField="IdTienda" OnItemComment="DataListTiendas_ItemCommand"...

Maybe try it that way?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
limmontreefreeAuthor Commented:
Thanks you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.