Solved

How to use dynamic values on CommandArgument

Posted on 2008-10-15
8
2,137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22723522
Try this

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

Author Comment

by:dimensionav
ID: 22724738
Hi TechTiger007

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

Expert Comment

by:TechTiger007
ID: 22725526
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:dimensionav
ID: 22727092
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
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22728769
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
ID: 22730512
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
ID: 22733681
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
ID: 26528896
This command wouldn't actually execute because lbComprar is not declared on Page_Load event.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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