ASP.NET C # Repeater - How to transfer information to a server without Javascript?

I am learning C # and working on my first ASP.Net e-commerce site.

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 relay creates JavaScript for postback, which is not suitable when filling out a shopping cart if the user has disabled JavaScript!

<div class="wrap-cart">
 <div class="cartbuy"><a id="ContentPlaceHolder1_Cartridges_buy_0" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$Cartridges$ctl00$buy&#39;,&#39;&#39;)">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 pass the cartID to the data table. Is there a way around it, so JavaScript is not involved at all?

For completeness, here is 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
    }
}
+3
source share
4 answers

Of course you can pass the selected ItemID through a QueryString

First create an anchor tag as follows:

<a href="NextCheckoutStep.aspx?ItemID=45">AddToCart</a>

This can be done in ItemTemplate:

<a href='<%# "NextCheckoutStep.aspx?ItemID=" + Eval("ItemID").ToString() %>'>AddToCart</a>

, NextCheckoutStep.aspx :

Request.QueryString["ItemID"]

  • . NextCheckoutStep.aspx CurrentCheckoutStep.aspx. ( init) ( postback = false), , . .
  • , 100% QueryString-Reads, .
  • QueryString, HTTP POST collection; , , , .
+5

, . , cartId cookie .

<asp:Repeater ID="Cartridges" runat="server">
<ItemTemplate>                                    
<p><a href="AddToCart.aspx?itemId=<%#Eval("itemID") %>">Buy</a></p>
</ItemTemplate>
</asp:Repeater>
+2

LinkButton displays a link that immediately leads to the submission, so it needs javascript.

Will you need to use simple HyperLink to display a url like mypage.aspx? id = cartid.

+1
source

Instead of LinkButton you can use

+1
source

All Articles