samedi 29 février 2020

Keep bootstrap open after firing onclick event

I went through many posts and forums and couldn't find a solution for my problem;

I have a web app using asp.net, and I have a bootstrap modal inside one of my pages, the modal contains textboxes and a button which inserts a record into the DB. The issues is when I click the Save button, the modal disappears. I want to keep the modal open after I click the Save button to see if the event is successful or not or see which textboxes are not filled.

Here is my asp code:

 <div class="modal fade" data-backdrop="static" style="font-size: 30px; font-family: 'FavFont'" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document" style="width: 1250px; text-align: center">
            <div class="modal-content">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <div class="modal-header" style="margin: auto">
                    <h5 class="modal-title" style="margin: auto; font-size: 30px">
                        <label for="forCostumer" dir="rtl">Make payment</label>
                        <asp:TextBox runat="server" ID="forCostumer" class="browser-default custom-select form-control col-12" Style="font-size: 30px; font-family: 'FavFont'; text-align: right"></asp:TextBox>
                    </h5>
                    <br />


                </div>
                <div class="modal-body">
                    <br />
                    <div>
                        <div>

                            <hr style="width: 40%; text-align: center; margin: auto" class="border-0" />

                        </div>
                    </div>
                    <br />

                    <div class="container">

                        <div class="col-sm-12 text-right" style="float: right;">
                            <label for="txtItemName1" dir="rtl">Total</label>
                            <asp:TextBox runat="server" ID="txtNowTotal" class="browser-default custom-select form-control col-12" Style="font-size: 30px; font-family: 'FavFont'; text-align: right"></asp:TextBox>
                        </div>
                        <br />
                        <div class="col-sm-12 text-right" style="float: right;">
                            <label for="txtItemName1" dir="rtl">Paid amount</label>
                            <asp:TextBox runat="server" ID="txtNowPaid" class="browser-default custom-select form-control col-12" Style="font-size: 30px; font-family: 'FavFont'; text-align: right"></asp:TextBox>
                        </div>
                        <br />
                        <div class="col-sm-12 text-right" style="float: right;">
                            <label for="txtItemName1" dir="rtl">Amount to Pay</label>
                            <asp:TextBox runat="server" ID="txtNowToPay" class="browser-default custom-select form-control col-12" Style="font-size: 30px; font-family: 'FavFont'; text-align: right"></asp:TextBox>
                        </div>

                        <div class="col-sm-12 text-right" style="float: right;">
                            <br />
                            <br />

                            <asp:Button ID="btnPayNow" runat="server" UseSubmitBehavior="false" type="button" class="btn btn-success btn-lg" Style="width: 20%; font-size: 40px" OnClick="MakePayment" Text="Make payment" ></asp:Button>
                            <br />
                            <br />







                            <br />
                            <br />
                        </div>
                        <br />



                    </div>

And here is my codebehind:

 protected void MakePayment(object sender, EventArgs e)
    {
        if (string.IsNullOrWhiteSpace(txtNowToPay.Text))
        {
            txtNowToPay.BorderColor = System.Drawing.Color.Red;
        }
        else
        {
            txtNowToPay.BorderColor = System.Drawing.Color.Gray;

            using (SqlConnection ConnectToDB = new SqlConnection(CS))
            {
                ConnectToDB.Open();
                SqlCommand cmdpay1 = new SqlCommand("update TBL_installments set paid_amount = paid_amount + '" + txtNowToPay.Text + "', remain_amount = remain_amount - '" + txtNowToPay.Text + "' where costumer_id = '" + Session["CostIdToSelect"] + "'", ConnectToDB);
                cmdpay1.ExecuteNonQuery();
                SqlCommand cmdpay2 = new SqlCommand("update TBL_debts set paid_amount = paid_amount + '" + txtNowToPay.Text + "', remain_amount = remain_amount - '" + txtNowToPay.Text + "' where costumer_id = '" + Session["CostIdToSelect"] + "'", ConnectToDB);
                cmdpay2.ExecuteNonQuery();
                ConnectToDB.Close();



                GridView1.DataSourceID = "SqlDataSource1";
                GridView1.DataBind();



            }

        }
    }

I'd appreciate anyone who can help.

Thank you




Aucun commentaire:

Enregistrer un commentaire