Avatar of Nate_LR
Nate_LR

asked on 

Prevent other asp buttons from performing submit action

I'm building an upload form.  Along with uploading, the user needs to enter some data and may or may not to work with a cart.   The cart buttons remove a listing from the cart or empty the cart entirely.  However, when I attempt to use these buttons, the page performs the submit action I have indicated, return validateForm()....
<form enctype="multipart/form-data" runat="server" method="post" action="gpsFieldPics.py" name="uploadForm" id="uploadForm" onSubmit="return validateForm()">

<asp:Button ID="btnRemove" runat="server" Text="Remove Track" UseSubmitBehavior="false" OnClick="btnRemove_Click" /><br /> 
<asp:Button ID="btnEmpty" runat="server" Text="Empty Cart" OnClick="btnEmpty_Click"  />

<input id="btnProcess" type="submit" value="Upload and Process" onclick="selectAllTracks()" />

Open in new window


That is not the complete form by the way.   You may notice I tried to use this... UseSubmitBehavior="false" , but it doesn't work in the way I thought it might.   Here are the code behind functions I'm trying to use....
protected void btnRemove_Click(object sender, EventArgs e) 
    {
        if (trks.Count > 0)
        {
            if (trkCart.SelectedIndex > -1)
            {
                trks.RemoveAt(trkCart.SelectedIndex);
                this.DisplayTrackCart();
            }
            else
            {
                lblMessage.Text = "Please select the item you want to remove.";
            }
        }
    }

 protected void btnEmpty_Click(object sender, EventArgs e)
    {
        if (trks.Count > 0)
        {
            trks.Clear();
            trkCart.Items.Clear();
        }
    }

Open in new window


I apparently cannot use PageFunctions or Ajax to call the code-behind functions because they are not static and don't return anything.

I also cannot split the form into two forms, because an asp page cannot have two forms with runat=server and because I'm using a python cgi script which seems  to only recover the elements of one form not two.

Any ideas on what I can do?  Thanks
ASP.NETC#Python

Avatar of undefined
Last Comment
Nate_LR

8/22/2022 - Mon