0

I have a modal inside an update panel which give information of student when click on argument in a grid view.

In my modal I have also 3 textbox in which the value need to be save when click in save button. It is not triggering the save button.

Here is my code:

<div class="modal fade" id="studinfo" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Student Info</h4>
                <button type="button" class="close"
                    data-dismiss="modal">
                    &times;</button>
            </div>
            <div class="modal-body">
                <asp:UpdatePanel ID="updModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

                        <div class="card h-100">
                            <div class="card-body">
                                <ul class="list-group list-group-flush">
                                    <asp:TextBox ID="txtId" Visible="false" runat="server"></asp:TextBox>
                                    <asp:Panel ID="typepannel" CssClass="list-group-item" runat="server">
                                        <asp:Label ID="lbltype" runat="server"
                                            Font-Bold="true" Text="Candidate Type: "></asp:Label>
                                        <asp:Label ID="type" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </asp:Panel>

                                    <asp:Panel ID="colpanel" CssClass="list-group-item" runat="server">
                                        <asp:Label ID="lblCol" runat="server"
                                            Font-Bold="true" Text="College Attend: "></asp:Label>
                                        <asp:Label ID="college" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </asp:Panel>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblName" runat="server"
                                            Font-Bold="true" Text="Name: "></asp:Label>
                                        <asp:Label ID="Name" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblNic" runat="server"
                                            Font-Bold="true" Text="Nic: "></asp:Label>
                                        <asp:Label ID="Nic" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblAge" runat="server"
                                            Font-Bold="true" Text="Age: "></asp:Label>
                                        <asp:Label ID="Age" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblAdress" runat="server"
                                            Font-Bold="true" Text="Address: "></asp:Label>
                                        <asp:Label ID="Address" runat="server"
                                            Text=''>
                                        </asp:Label>

                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblacad" runat="server"
                                            Font-Bold="true" Text="Academy: "></asp:Label>
                                        <asp:Label ID="Academy" runat="server"
                                            Text=''>
                                        </asp:Label>
                                    </div>

                                    <h6 class="mt-3 mb-3">Parent in Charge</h6>
                                    <div class="list-group-item">
                                        <asp:Label ID="lblParent" runat="server"
                                            Font-Bold="true" Text="Parent Name: "></asp:Label>
                                        <asp:Label ID="parentName" runat="server"
                                            Text=''>
                                        </asp:Label>
                                    </div>
                                    <div class="list-group-item">
                                        <asp:Label ID="lblNumber" runat="server"
                                            Font-Bold="true" Text="Parent Contact Number: "></asp:Label>
                                        <asp:Label ID="Number" runat="server"
                                            Text=''>
                                        </asp:Label>
                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblEmail" runat="server"
                                            Font-Bold="true" Text="Parent Email Address: "></asp:Label>
                                        <asp:Label ID="Email" runat="server"
                                            Text=''>
                                        </asp:Label>
                                    </div>

                                    <div class="list-group-item">
                                        <asp:Label ID="lblResult" runat="server"
                                            Font-Bold="true" Text="Result: "></asp:Label>
                                        <asp:DropDownList ID="ddlResult"
                                            CssClass="select form-control"
                                            runat="server">
                                        </asp:DropDownList>

                                    </div>


                                    <div class="list-group-item">
                                        <asp:Label ID="lblMarks" runat="server" Font-Bold="true" Text="Marks: "></asp:Label>
                                        <asp:TextBox runat="server" ID="txtMarks"
                                            CssClass="form-control form-control-lg" />
                                        <asp:RequiredFieldValidator ID="rfvMarks" runat="server"
                                            Display="Dynamic" ForeColor="Red"
                                            ControlToValidate="txtMarks"
                                            SetFocusOnError="true"
                                            ErrorMessage="Marks is Mandatory">
                                        </asp:RequiredFieldValidator>
                                        <asp:CompareValidator ID="cmpVMarks" runat="server"
                                            ControlToValidate="txtMarks"
                                            Operator="DataTypeCheck"
                                            Type="Double"
                                            SetFocusOnError="true"
                                            Display="Dynamic"
                                            Text="Incorect data type"
                                            ForeColor="Red"
                                            ErrorMessage="Invalid">
                                        </asp:CompareValidator>
                                        <asp:RegularExpressionValidator ID="revPhone"
                                            runat="server"
                                            ControlToValidate="txtMarks"
                                            SetFocusOnError="true"
                                            Display="Dynamic"
                                            ForeColor="Red"
                                            ValidationExpression="^\d\d+(\.[1-9])?$"
                                            ErrorMessage="Invalid">

                                        </asp:RegularExpressionValidator>
                                    </div>
                                    <div class="list-group-item">
                                        <asp:Label ID="lblpurcentage" runat="server"
                                            Font-Bold="true" Text="Purcentage : "></asp:Label>
                                        <asp:TextBox runat="server" ID="txtpur"
                                            CssClass="form-control form-control-lg" />
                                        <asp:RequiredFieldValidator
                                            ID="rfvpur" runat="server"
                                            Display="Dynamic" ForeColor="Red"
                                            ControlToValidate="txtpur"
                                            SetFocusOnError="true"
                                            ErrorMessage="Purcentage is Mandatory">
                                        </asp:RequiredFieldValidator>
                                        <asp:CompareValidator ID="cvpur" runat="server"
                                            ControlToValidate="txtpur"
                                            Operator="DataTypeCheck"
                                            Type="Double"
                                            SetFocusOnError="true"
                                            Display="Dynamic"
                                            Text="Incorect data type"
                                            ForeColor="Red"
                                            ErrorMessage="Invalid">
                                        </asp:CompareValidator>
                                    </div>
                                </ul>
                            </div>

                        </div>

                    </ContentTemplate>

                </asp:UpdatePanel>

                <asp:Button ID="btnSave" OnClick="btnSave_Click"
                    CssClass="btn btn-success btn-block" runat="server" Text="Save" />
            </div>
        </div>

To make this data appear in modal I used updModal.Update(); in the button where I use to call the modal.

Here is my code behind of save button:

  protected void btnSave_Click(object sender, EventArgs e)
    {

        try
        {

            string id = txtId.Text;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update tblStudent set stud_result=@res,stud_purcentage=@pur,stud_totalMarks=@marks where stud_Id=@id";
            cmd.Parameters.AddWithValue("@id", id);
            cmd.Parameters.AddWithValue("@res", ddlResult.SelectedValue);
            cmd.Parameters.AddWithValue("@pur", txtpur.Text.Trim());
            cmd.Parameters.AddWithValue("@marks", txtMarks.Text.Trim());
            con.Open();
            cmd.Connection = con;

            updModal.Update();
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "LaunchServerSide",
                      "$(function () { showUErrorModal(); });", true);

        }
        finally
        {

            con.Close();

        }

    }

When I have try to put the button inside the update panel it freeze the app when I triger the button.

Can someone please please help me with that? Thank you in advance.

  • first remove the updatepanel, and check for errors on your code that are not visible because of the updatepanel – Aristos Dec 31 '21 at 15:40
  • Thanks for replying, I already make a debug like that. The update panel is preventing the button onclick event, The update panel allows me to pass value in my modal when I open it. Is there a solution with that problem. I am totally stuck. – DeathStriker2 Jan 01 '22 at 14:37
  • I suspect that the javascript is not running after you update the update panel - take a look at this answer -> https://stackoverflow.com/questions/3341623/asp-net-updatepanel-in-gridview-jquery-datepicker/3341741#3341741 – Aristos Jan 03 '22 at 18:54
  • and on this one (are similar) -> https://stackoverflow.com/questions/14769641/how-to-keep-javascripts-after-updatepanel-partial-postback/14769925#14769925 – Aristos Jan 03 '22 at 18:55

0 Answers0