bluem1 0 Newbie Poster

Team -

I hope you can help me here. I am converting an old ecommerce site to a newer asp.net site but I need to retain the old cart. The cart is unique in that it uses forms to post the items into the cart. So if a page listed 10 products there were 10 forms. When I try this via asp.net the top product button always posts the last product on the page because the cart isn't isolated in it's own form tag.

Here is a sample of the origional code:

<tr>
            <td width="100%">&nbsp;<form method="POST" action="">
              <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
                <tr>
                  <td width="50%" align="center"><font face="Arial">
                  <select NAME="cartitadd" size="1">
                  <option value="The Perfect Prescription^40.00^4^^" selected>The Perfect Prescription (Shown) -- $40.00
                  </option>
                  <option value="The Perfect Prescription^50.00^5^^">The Perfect Prescription -- $50.00
                  </option>
                  </select></font><p><font face="Arial">Enclosure Card:
                  <input TYPE="TEXT" NAME="textadd_Enclosure Card_0.2" SIZE="40" MAXLENGTH="200"><br>
                  <font SIZE="1">Maximum 200 Characters</font> </font> </td>
                  <td width="20%">
                  <p align="center"><font face="Arial"><input TYPE="submit" VALUE="Add To Cart"></font></td>
                </tr>
              </table>
            </form>



  <tr>
            <td width="100%">&nbsp;<form method="POST" action="">
              <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
                <tr>
                  <td width="50%" align="center"><font face="Arial">
                  <select NAME="cartitadd" size="1">
                  <option value="productname2^40.00^4^^" selected>Product Name 2 (Shown) -- $40.00
                  </option>
                  <option value="Product Name 2^50.00^5^^">Product Name 2 -- $50.00
                  </option>
                  </select></font><p><font face="Arial">Enclosure Card:
                  <input TYPE="TEXT" NAME="textadd_Enclosure Card_0.2" SIZE="40" MAXLENGTH="200"><br>
                  <font SIZE="1">Maximum 200 Characters</font> </font> </td>
                  <td width="20%">
                  <p align="center"><font face="Arial"><input TYPE="submit" VALUE="Add To Cart"></font></td>
                </tr>
              </table>
            </form>

and so on, all would be within the same body tag. How can I make this work via asp.net and keep the products seperated? I can make the cart post, I just need to seperate the products and make it fairly easy to move code around from page to page because they move stuff around on the site all the time.

Any Suggestions?

Thanks!
Dewayne

Dani AI

Generated

— The symptom you describe is the classic clash between legacy per-product HTML posts and an ASP.NET page model that expects a single server-managed form. There are three practical ways to keep the old cart while avoiding nested-form/name-collision problems.

A low-impact, easy-to-deploy approach is client-side form creation: when the user clicks "Add", build a small HTML form in JavaScript with the exact field names the cart expects, append it to the document, and submit it. That avoids nested server forms and works inside master pages without moving server markup.

function postToLegacyCart(endpoint, fields) {
  var f = document.createElement('form');
  f.method = 'POST';
  f.action = endpoint;
  for (var key in fields) {
    var i = document.createElement('input');
    i.type = 'hidden';
    i.name = key;
    i.value = fields[key];
    f.appendChild(i);
  }
  document.body.appendChild(f);
  f.submit();
}

If you prefer server-side control, create a small ASP.NET endpoint that accepts product data and forwards it to the legacy CGI using HttpClient. This centralizes cookie/session handling, lets you translate field names, and keeps the public pages free of raw legacy form markup.

using (var client = new HttpClient()) {
  var data = new Dictionary<string,string> { { "FIELD_FOR_PRODUCT", productValue }, { "FIELD_FOR_NOTE", noteValue } };
  var content = new FormUrlEncodedContent(data);
  var resp = await client.PostAsync("https://your-legacy-endpoint/cgi-bin/cart", content);
  var body = await resp.Content.ReadAsStringAsync();
  // return or redirect as needed
}

Other options: render standalone plain HTML forms outside the server form (if your master/layout allows), or embed a small iframe per product. Troubleshooting tips: verify exact field names, inspect the POST payload with browser dev tools, and when proxying preserve cookies/redirects so the legacy cart session remains consistent. If editors move markup frequently, keep the add-to-cart button as a tiny reusable control that supplies product values via data-attributes so layout changes don’t break the submission code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.