Reputation: 3424
While using 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>
Upvotes: 0
Views: 7173
Reputation: 13673
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)")%>'>
Upvotes: 2
Reputation: 1494
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")
.
Upvotes: 1