Question

I would like to do this :

<asp:ImageButton runat="server" ID="addToCartIMG" OnCommand="btnAdd_Click" EnableViewState="false" CommandArgument='<%# itemId1.Value + ";" + Name1.Text %>' ImageUrl="<%$Resources:MasterPage, Image_AddToCart%>" />

where Item1 is hiddenField and Name1 a literal.

When I debug the method btnAdd_Click, the CommandEventArgs is empty and I don't understand why...

Thank you

Was it helpful?

Solution

You can't evaluate form field's values as you do in your example. If these values you try to evaluate are static, I mean doesn't change by your user's actions, you can pass them statically to your button's CommandArgument property.

If the values are changing by your user's actions, then you should get them at server-side by the reference of your controls like that :

string itemId = itemId1.Value;
// OR : 
string itemId2 =  Request.Forms["itemId1"];

For LiteralControl, you can't get it's text. you should turn it to form element.

Eval method is not a client-side function that passes your controls' values dynamically to server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top