Solved

How to use dynamic values on CommandArgument

Posted on 2008-10-15
8
2,161 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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