Marius Vasile

Marius Vasile

  • 552
  • 1.9k
  • 145.8k

Submit button not working as intended

Jun 14 2024 4:03 PM

I don't understand what stop triggering insert procedure for the below configuration while on a separate test page works perfectly. I have a tab which get active based on code behind control.

<div class="row no-gutters ml-2 mr-2 mb-2 justify-content-center">

    <asp:HiddenField ID="ActiveTAB" runat="server" Value="#TabEvaluare" ClientIDMode="Static" />
    <asp:HiddenField ID="ActiveMicroclimat" runat="server" Value="disabled" ClientIDMode="Static" />
    <asp:HiddenField ID="ActiveMasuri" runat="server" Value="disabled" ClientIDMode="Static" />

    <ul class="nav nav-tabs" id="DivTab" role="tablist">

        <li class="nav-item" style="width: 200px;">
            <class="nav-link" id="TabEchipament" data-toggle="tab" aaaa="#DivEchipamentTab" role="tab">Echipament</a>
        </li>

    </ul>
</div>

Then on Echipament tab

<div class="tab-content" id="DivTabContent">
        <div id="DivEchipamentTab" class="tab-pane fade pb-2 pt-2 mb-4" style="border: solid 2px LightSteelBlue">
        <div class="row no-gutters mb-2 ml-1">
            <asp:Label class="form-control form-control-sm text-left border border-0"
                Style="font-weight: 700; font-size: 14px;"
                Text="Echipamente utilizate"
                runat="server" />
        </div>
        <div class="row no-gutters mb-2 d-flex justify-content-center">
            <div class="col-3">
                <asp:Label Text="Echipament" class="form-control form-control-sm" runat="server" Style="background-color: #1E90FF; color: #f4f1eb;" />
            </div>
            <div class="col-1"></div>
        </div>
        <div class="row no-gutters mb-2 d-flex justify-content-center">
            <div class="col-3">
                <asp:TextBox ID="txtEchipament" PlaceHolder="Adauga echipament" class="form-control form-control-sm" runat="server" ClientIDMode="Static" />
            </div>
            <div class="col-1 pl-1">
                <asp:Button ID="btnAddEchipament"
                    Text="Submit"
                    runat="server"
                    OnClick="AddEchipament"
                    CausesValidation="false"
                    class="btn btn-md lfc-green align-self-center"
                    Style="font-size: 12px; height: 30px; width: 100px"
                    ClientIDMode="Static" />
            </div>
        </div>
        <hr />
    </div>

On code behind

protected void AddEchipament(Object sender, EventArgs e)
{
    if (Session["AID"] != null)
    {
        int aid = Int32.Parse(Session["AID"].ToString());
        using (SqlConnection conn = new SqlConnection(connString))
        {
            using (SqlCommand cmd = new SqlCommand("AddActivitateEchipament", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Echipament", txtEchipament.Text);
                cmd.Parameters.AddWithValue("@AID", aid);
                conn.Open();

                int result = cmd.ExecuteNonQuery();
                if (result > 0)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
                }

                conn.Close();

                txtEchipament.Text = string.Empty;
                ActiveTAB.Value = "#TabEchipament";
            }
        }
    }
}

Whitout the tab setup is working, with is not but I can't figure out why? Please help


Answers (1)