You must Sign In to post a response.
  • Category: ASP.NET

    Why Bootstrap modal is closing after bsave button click in asp.net

    Hi,

    I have developed a form for comment confirmation. when i click add comment
    my modal is going close. and also when i click save button is not checking validation
    in asp.net

    hi,

    <asp:Content ID="Content1" ContentPlaceHolderID="cHead" runat="Server">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Page-Enter" content="Alpha(opacity=1.05)" />
    <meta http-equiv="Page-Exit" content="Alpha(opacity=1.05)" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    $('#<%=btnShowPopup.ClientID%>').live('click', function (e) {
    $("#myModal").modal('show');
    });
    });
    </script>
    <script type="text/javascript">
    function ValidComment() {
    var Comment = document.getElementById('<%=btnShowPopup.ClientID%>').value;
    if (Comment == "") {
    alert("Hello");
    }
    }
    </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="mBody" runat="Server">
    <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
    <Triggers>
    <asp:PostBackTrigger ControlID="bSave" />
    <asp:PostBackTrigger ControlID="bNewComment" />
    <asp:PostBackTrigger ControlID="btnShowPopup" />
    </Triggers>
    <ContentTemplate>
    <asp:Button ID="btnShowPopup" runat="server" Text="Open Modal" OnClick="btnShowPopup_Click"
    class="btn btn-primary btn-lg" />
    <div id="myModal" class="modal fade" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <h4 class="modal-title">
    Confirmation</h4>
    </div>
    <div class="modal-body">
    <div class="row">
    <div class="col-sm-6 form-group">
    <b>Comments</b>
    <asp:Button ID="bNewComment" CssClass="btn btn-info" Text="Add Comment" runat="server"
    data-toggle="modal" data-target="#myModal" OnClick="bNewComment_Click" />
    </div>
    </div>
    <div class="row" id="dComment" runat="server" visible="false">
    <div class="col-sm-6 form-group">
    <b>Comments</b>
    <asp:TextBox ID="tbComment" TextMode="MultiLine" Width="500px" runat="server" placeholder="Enter Comments.."
    class="form-control"></asp:TextBox>
    </div>
    </div>
    </div>
    <div class="modal-footer">
    <asp:Button ID="bClose" runat="server" CssClass="btn btn-primary" data-dismiss="modal"
    Text="Close" />
    <asp:Button ID="bSave" runat="server" CssClass="btn btn-primary" Text="Save changes"
    OnClientClick="ValidComment()" />
    </div>
    </div>
    </div>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </asp:Content>

    code behind:
    ========

    protected void bNewComment_Click(object sender, EventArgs e)
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "myModals", "$('#myModal').modal('show')", true);
    upMain.Update();
    this.dComment.Visible = true;
    }

    protected void btnShowPopup_Click(object sender, EventArgs e)
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "myModals", "$('#myModal').modal('show')", true);
    }
  • #766930
    Hi,
    Inside ValidComment() function add this line at last:

    return false;

    so that postback never happens and it wouldn't submit the form when bSave is clicked.

    Also remove <Triggers> tag.

  • #766932
    You are doing the validation on client click OnClientClick="ValidComment()" .
    In the "ValidComment" you are just checking and showing the alert box. but the OnClientClick is expecting the boolean value "TRUE" or "False". You have to return "True/False" in the validation function. So that its not working.

    If you are not returning anything by default it will take as "True". So you need to send "False" value based on the validation.

    By Nathan
    Direction is important than speed

  • #766988
    Hi

    you can use the Bootstrap design with in update panel .



    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <!-- Modal -->
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
    <span aria-hidden="true">×</span></button>
    <h4 class="modal-title" id="myModalLabel">
    Modal title</h4>
    </div>
    <div class="modal-body">
    <asp:TextBox ID="TextBox1" runat="server" placeholder="First Name" class="form-control"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server" placeholder="Middle Name" class="form-control"></asp:TextBox><br />
    <asp:TextBox ID="TextBox3" runat="server" placeholder="Last Name" class="form-control"></asp:TextBox><br />
    </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">
    Close</button>
    Save changes</button>--%>
    <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />

    </div>
    </div>
    </div>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>



    refer this url

    "aspforums.net/Threads/187802/Solved-Bootstrap-Modal-Popup-Auto-Closes-on-PostBack-in-ASPNet/"

    "mindstick.com/Forum/2291/how-to-stop-closing-of-bootstrap-modal-popup-outside-click"

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments