• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2311
  • Last Modified:

How to use dynamic values on CommandArgument

HI
I am using the following control:

      <asp:LinkButton ID="lbComprar" runat="server" OnCommand="lbComprar_Click"
                      CommandArgument='<%=idproducto%>'
                      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.
0
dimensionav
Asked:
dimensionav
  • 4
  • 3
1 Solution
 
TechTiger007Commented:
Try this

<asp:LinkButton ID="lbComprar" runat="server" OnCommand="lbComprar_Click"
                      CommandArgument='<%#=idproducto%>'
                      CommandName="Comprar" CssClass="MasDetalles" Text="Comprar"/>
0
 
dimensionavAuthor Commented:
Hi TechTiger007

Now The output VS2005 window shows:
error BC30201: expression expected
0
 
TechTiger007Commented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dimensionavAuthor Commented:
HI

Here is my code:

        <asp:LinkButton ID="lbComprar"
                        OnCommand="lbComprar_Click"
                        CommandArgument='<%#=idproducto%>'
                        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).



0
 
TechTiger007Commented:
That could be due to the = sign

copy and paste the code below and try it out
<asp:LinkButton ID="lbComprar" runat="server" CommandArgument='<%#idproducto%>'
                            CommandName="Comprar" OnCommand="lbComprar_Click" Text="Comprar">
                        </asp:LinkButton>                        

0
 
dimensionavAuthor Commented:
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_productos.master" Title="Detalle de Producto" %>
<%@ MasterType VirtualPath="~/menu_productos.master" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="system.Data.OleDb" %>
<%@ Import Namespace="DAV.TiendaEnLinea.v1.BusinessLogicLayer" %>
<%@ Import Namespace="System.Collections.Generic" %>
 
<script runat="server">

Protected CurrentSession As DAV.TiendaEnLinea.v1.BusinessLogicLayer.BLLSessionManager
Dim objDetalleDeProducto As List(Of BLLDetalleDeProducto)
Dim objConfiguraciones As List(Of BLLConfiguraciones) = BLLConfiguraciones.ObtieneConfiguraciones()
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("CurrentSession"), DAV.TiendaEnLinea.v1.BusinessLogicLayer.BLLSessionManager)
CurrentSession.IdProductoActual = CType(Request.QueryString("idproducto"), Integer)
PaginaActual = CType(CurrentSession.PaginaActual, Integer)
idproducto = CurrentSession.IdProductoActual
objDetalleDeProducto = BLLDetalleDeProducto.ObtieneDetalleDeProducto(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.IdProductoActual = CType(e.CommandArgument, Integer)
CurrentSession.AgregaElementoEnCarrito(CurrentSession)
Response.Redirect("carrito.aspx")
End Sub

</script>

-012.jpg
0
 
TechTiger007Commented:
Not sure why it is not working.

Ok you can do another thing.
Remove command argument from the asp:LinkButton tag.
Inside page_load event handler add this line

lbComprar.CommandArgument = idproducto
This should give the desired output
0
 
Minion1Commented:
This command wouldn't actually execute because lbComprar is not declared on Page_Load event.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now