I’m learning C# and working on my first ASP.Net e-commerce website.
I have the following repeater:
<asp:Repeater ID="Cartridges" runat="server" OnItemCommand="Cartridges_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument=<%#Eval("cartID") %> Text="Buy"></asp:LinkButton>
</ItemTemplate>
However, when the code is rendered the repeater produces JavaScript to postback which is no good when populating a shopping cart if the user has JavaScript turned off!
<div class="wrap-cart">
<div class="cartbuy"><a id="ContentPlaceHolder1_Cartridges_buy_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Cartridges$ctl00$buy','')">Buy</a></div>
<div class="cartimg"><a href="url.html" class="productsurl"><img src="pic/epson-comp-set50.jpg" alt="product" /></a></div>
<div class="carttext">
<p class="cartdesc"><a href="url.html" class="productsurl"><span class="homeprinters">product</span></a></p>
<p class="cartprice">£x.xx</p>
</div>
All I want to do is to pass the cartID to a data table. Is there a way round it so JavaScript is not involved at all?
For completeness here’s my code behind:
protected void Cartridges_ItemCommand(object source, RepeaterCommandEventArgs e)
{
cartidtest.Text = "added";
if (e.CommandName == "AddtoCart")
{
string varCartID = (e.CommandArgument).ToString();
//more code here
}
}
Sure, you can pass the selected ItemID via QueryString
First, Generate an anchor tag like this:
This may be accomplished in an ItemTemplate:
Finally, in NextCheckoutStep.aspx, access:
Notes