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?
 
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
 
limmontreefreeAuthor Commented:
Thanks you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.