Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 516.5k

Modal Goes off on Validation

Aug 27 2024 8:02 AM

Hi

  I have below Modal. When there is error in Code behind Modal goes off. It should remain on Modal Popup Screen

                <div id="modal_form_horizontal" class="modal fade">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header bg-info">
                                <h5 class="modal-title">Add/Update Employee Category</h5>
                                <button type="button" class="close" data-dismiss="modal">&times;</button>&nbsp;
                            </div>

                            <div class="form-horizontal">
                                <div class="modal-body">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label>Employee Category</label>&nbsp;<span style="color: red">*</span>
                                                <asp:TextBox ID="txtDescription" MinLength="3" MaxLength="50" class="form-control alpha" required="true" runat="server" Text='<%# Eval("description") %>'></asp:TextBox>
                                            </div>
                                        </div>
                                        <div class="col-lg-4">
                                            <div class="form-group">
                                                <label>Status</label>
                                                <asp:DropDownList ID="ddlStatus" class="form-control select-search" runat="server">
                                                    <asp:ListItem Value="True">Active</asp:ListItem>
                                                    <asp:ListItem Value="False">Blocked</asp:ListItem>
                                                </asp:DropDownList>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                                    <asp:Button ID="lnkEmpCategory" runat="server" class="btn bg-primary" OnClick="btnAdd_Click" Text="Save" />&nbsp;
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
protected void btnAdd_Click(object sender, EventArgs e)
        {
            string errMessage = "";

            if (String.IsNullOrWhiteSpace(txtDescription.Text))
            {
                errMessage += "Description is required and cannot Be empty.</br>";
            }

            Boolean IsValidDescription = Common.CommonFunction.IsAlpha(txtDescription.Text);
            if (IsValidDescription == false)
            {
                errMessage += "Description : Only Alphabets , Space , _ - allowed.</br>";
            }
}

Thanks


Answers (5)