Why when I click Dropdown list bootstrap modal is closing [Resolved]

Posted by Cpatil1000 under ASP.NET on 6/29/2016 | Points: 10 | Views : 351 | Status : [Member] | Replies : 1
Hi,
i am using bootstrap modal and in modal i am using dropdownlist. But When
i click dropdownlist the modal is going close. i could not complete my
entry form.
<asp:Content ID="Content1" ContentPlaceHolderID="cHead" runat="Server">
<script type="text/javascript">
$(document).ready(function () {
$('#<%=btnShowPopup.ClientID%>').on('click', function (e) {
$("#myModal").modal('show');
e.preventDefault();
});
$('#<%=bSave.ClientID%>').on('click', function (e) {
var flag = true;
if ($('#<%=tbComment.ClientID%>').val() == "") {
alert('Please Enter Comments');
$('#<%=tbComment.ClientID%>').focus();
flag = false;
}
if (flag == false) {
$("#myModal").modal('show');
e.preventDefault();
return false;
}
});
});

//Add the function below
function openPopup() {
$("#myModal").modal('show');
e.preventDefault();
}

function closePopup() {
$("#myModal").modal('hide');
}
</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" />
<asp:PostBackTrigger ControlID="ddlEditTypeOfLand" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnShowPopup" runat="server" Text="Open Modal" class="btn btn-primary btn-lg" />
<div id="myModal" class="modal fade" data-backdrop="static" data-keyboard="false"
role="dialog">
<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="col-sm-5 form-group">
<b>Type Of Land</b><span style="color: Red; font-weight: bolder; font-size: medium;">*</span>
<asp:DropDownList ID="ddlEditTypeOfLand" AutoPostBack="true" runat="server" class="form-control"
OnSelectedIndexChanged="ddlEditTypeOfLand_SelectedIndexChanged">
<asp:ListItem Value="0" Selected="True"><---Select---></asp:ListItem>
<asp:ListItem Value="1">Wasted Land</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="modal-footer">
</as




Responses

Posted by: A2H on: 6/29/2016 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
You have selectedindexchanged event attached to dropdownlist and this cause page postback which causes the modal window to close. As a resolution reopen the modal pop in dropdownlist selectindexchanged event like below

 protected void ddlEditTypeOfLand_SelectedIndexChanged(object sender, EventArgs e)
{
//Your code here

//Open the popup
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openpopup();", true);
}



Thanks,
A2H
Please mark my reply as answer if it helps to resolve your problem

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response