views:

61

answers:

1

Hi, I have an asp:button control and am using the "CommandName" and "CommandArgument" parameters in the .aspx file. The CommandName is found with <%# Eval("Name") %>, but the CommandArgument has to be found via a javascript function. However, I'm not quite sure how to do this inline. The function returns a number (integer), which is to be used as the value of the CommandArgument. Is it possible to do this? Thanks

EDITED TO ADD CODE I've added an example code (don't have access to the real code atm). However, basically, the CommandArgument should be the value returned by the function CalculateLength().

function CalculateLength(a,b) {
    return a*b;
}

<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName=<%# Eval("Name") %> CommandArgument= ??? //Should be result of CalculateLength(a,b).
+1  A: 

I am not sure how you are going to get the javascript to work because the aspx code is running server side and building the output for your button. By the time the javascript runs the page code has already been built and the button's html and attached javascript as well.

Is there anyway to calculate the function server side and then just do:

CommandArgument="<%= CalculateLengthServerSide() %>"

You don't need to just use the data your binding to, you can call any server side function.

Edit: Try switching your label that stores the quantity to a textbox and making it read only so uses will not mess with it. After the button is clicked, you should be able to find the textbox control and read out the posted value.

Kelsey