开发者

passing arguments in onserverclick

While us开发者_高级运维ing this line of code, I get the error

CS1040: Preprocessor directives must appear as the first non-whitespace character on a line

This code is under tag and inside an asp:Repeater control

<td valign="bottom" width="130">
<%# Eval("Quantity")%>+ in stock<br />
<input class="textbox" maxlength="2" name="Quantity" size="2" type="text" value="1" />
                    <br />

<a id="A1" class="positive" runat="server"
onserverclick='addtocart(<%#Eval("ProductDescriptionId")%>,Quantity)'> Add to Cart</a>


Make sure the <%# %> spans the entire attribute like so:

<a id="A1" class="positive" runat="server" 
   onserverclick='<%# "addtocart("+Eval("ProductDescriptionId").ToString()+",Quantity)"%>'>

Alternatively, you can use the built-in formatting on the Eval method:

<a id="A1" class="positive" runat="server" 
   onserverclick='<%# DataBinder.Eval( Container.DataItem, "ProductDescriptionId", "addtocart({0},Quantity)")%>'>


since onserverclick is evaluated on server side the # is being considered as C# directive. you can replace <%#Eval("ProductDescriptionId")%> with something like DataBinder.Eval(Container.DataItem,"ProductDescriptionId").

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜