dimensionav
asked on
How to use dynamic values on CommandArgument
HI
I am using the following control:
<asp:LinkButton ID="lbComprar" runat="server" OnCommand="lbComprar_Click "
CommandArgument='<%=idprod ucto%>'
CommandName="Comprar" CssClass="MasDetalles" Text="Comprar"/>
What I want is to pass a dynamic/variable value to OnCommand method using CommandArgument, but the debug shows that the only value that its passed is a string equals to <%=idproducto%>.
¿Any ideas?
Thanks.
I am using the following control:
<asp:LinkButton ID="lbComprar" runat="server" OnCommand="lbComprar_Click
CommandArgument='<%=idprod
CommandName="Comprar" CssClass="MasDetalles" Text="Comprar"/>
What I want is to pass a dynamic/variable value to OnCommand method using CommandArgument, but the debug shows that the only value that its passed is a string equals to <%=idproducto%>.
¿Any ideas?
Thanks.
ASKER
Hi TechTiger007
Now The output VS2005 window shows:
error BC30201: expression expected
Now The output VS2005 window shows:
error BC30201: expression expected
dimensionav,
This error could be due to some other thing. I tried this line of code and it showed up a link with no errors. Debug the code and let know where exactly is this error
This error could be due to some other thing. I tried this line of code and it showed up a link with no errors. Debug the code and let know where exactly is this error
ASKER
HI
Here is my code:
<asp:LinkButton ID="lbComprar"
OnCommand="lbComprar_Click "
CommandArgument='<%#=idpro ducto%>'
CommandName="Comprar" runat="server" Text="Comprar"/>
And as I said before is:
error BC30201: expression expected
Is presented just at the time of compiling, normal or compiling mode (avoids to execute the application).
Here is my code:
<asp:LinkButton ID="lbComprar"
OnCommand="lbComprar_Click
CommandArgument='<%#=idpro
CommandName="Comprar" runat="server" Text="Comprar"/>
And as I said before is:
error BC30201: expression expected
Is presented just at the time of compiling, normal or compiling mode (avoids to execute the application).
That could be due to the = sign
copy and paste the code below and try it out
<asp:LinkButton ID="lbComprar" runat="server" CommandArgument='<%#idprod ucto%>'
CommandName="Comprar" OnCommand="lbComprar_Click " Text="Comprar">
</asp:LinkButton>
copy and paste the code below and try it out
<asp:LinkButton ID="lbComprar" runat="server" CommandArgument='<%#idprod
CommandName="Comprar" OnCommand="lbComprar_Click
</asp:LinkButton>
ASKER
HI TechTiger007
I have attached the part of the code that uses the value passed by command argument and you could see that it represents just an empty string.
Here is script content in which you can see the variable "idproducto" as a global element and how it is used on the method:
<%@ Page Language="VB" MasterPageFile="~/menu_pro ductos.mas ter" Title="Detalle de Producto" %>
<%@ MasterType VirtualPath="~/menu_produc tos.master " %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="system.Data.Ole Db" %>
<%@ Import Namespace="DAV.TiendaEnLin ea.v1.Busi nessLogicL ayer" %>
<%@ Import Namespace="System.Collecti ons.Generi c" %>
<script runat="server">
Protected CurrentSession As DAV.TiendaEnLinea.v1.Busin essLogicLa yer.BLLSes sionManage r
Dim objDetalleDeProducto As List(Of BLLDetalleDeProducto)
Dim objConfiguraciones As List(Of BLLConfiguraciones) = BLLConfiguraciones.Obtiene Configurac iones()
Dim idproducto As Integer = 0
Dim PaginaActual As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Obtiene Instancia de objeto de sesion y valores de controles de masterpage
CurrentSession = DirectCast(Session("Curren tSession") , DAV.TiendaEnLinea.v1.Busin essLogicLa yer.BLLSes sionManage r)
CurrentSession.IdProductoA ctual = CType(Request.QueryString( "idproduct o"), Integer)
PaginaActual = CType(CurrentSession.Pagin aActual, Integer)
idproducto = CurrentSession.IdProductoA ctual
objDetalleDeProducto = BLLDetalleDeProducto.Obtie neDetalleD eProducto( idproducto )
If IsPostBack Then
End If
End Sub
Protected Sub lbComprar_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
'Agrega producto al carrito de compras
CurrentSession.IdProductoA ctual = CType(e.CommandArgument, Integer)
CurrentSession.AgregaEleme ntoEnCarri to(Current Session)
Response.Redirect("carrito .aspx")
End Sub
</script>
-012.jpg
I have attached the part of the code that uses the value passed by command argument and you could see that it represents just an empty string.
Here is script content in which you can see the variable "idproducto" as a global element and how it is used on the method:
<%@ Page Language="VB" MasterPageFile="~/menu_pro
<%@ MasterType VirtualPath="~/menu_produc
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="system.Data.Ole
<%@ Import Namespace="DAV.TiendaEnLin
<%@ Import Namespace="System.Collecti
<script runat="server">
Protected CurrentSession As DAV.TiendaEnLinea.v1.Busin
Dim objDetalleDeProducto As List(Of BLLDetalleDeProducto)
Dim objConfiguraciones As List(Of BLLConfiguraciones) = BLLConfiguraciones.Obtiene
Dim idproducto As Integer = 0
Dim PaginaActual As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Obtiene Instancia de objeto de sesion y valores de controles de masterpage
CurrentSession = DirectCast(Session("Curren
CurrentSession.IdProductoA
PaginaActual = CType(CurrentSession.Pagin
idproducto = CurrentSession.IdProductoA
objDetalleDeProducto = BLLDetalleDeProducto.Obtie
If IsPostBack Then
End If
End Sub
Protected Sub lbComprar_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
'Agrega producto al carrito de compras
CurrentSession.IdProductoA
CurrentSession.AgregaEleme
Response.Redirect("carrito
End Sub
</script>
-012.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This command wouldn't actually execute because lbComprar is not declared on Page_Load event.
<asp:LinkButton ID="lbComprar" runat="server" OnCommand="lbComprar_Click
CommandArgument='<%#=idpro
CommandName="Comprar" CssClass="MasDetalles" Text="Comprar"/>