开发者

CommandArgument is empty

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜