Link to home
Start Free TrialLog in
Avatar of limmontreefree
limmontreefreeFlag for Spain

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of limmontreefree

ASKER

Thanks you very much.