Solved

How to use dynamic values on CommandArgument

Posted on 2008-10-15
8
2,024 Views
Last Modified: 2013-11-07
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
Comment
Question by:dimensionav
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
Try this

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

Author Comment

by:dimensionav
Comment Utility
Hi TechTiger007

Now The output VS2005 window shows:
error BC30201: expression expected
0
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
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
 

Author Comment

by:dimensionav
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
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
 

Author Comment

by:dimensionav
Comment Utility
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
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 125 total points
Comment Utility
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
 

Expert Comment

by:Minion1
Comment Utility
This command wouldn't actually execute because lbComprar is not declared on Page_Load event.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now