i want to add item in dropdown list if desired item is not on the list of dropdown list for which i have an asp button that calls for bootstrap modal.
my problem here is that after pressing save button in modal the data is being saved but after that nothing works on the page
The button itself is not working now, same black screen after adding one item, and modal is also not being cleared.
i am using boostrap modal inside update panel.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadItem();
}
}
public void loadItem()
{
DataTable dt = blu.getItemList();
CmbItem.DataSource = dt;
CmbItem.DataTextField = "Item_Name";
CmbItem.DataValueField = "Item_Id";
CmbItem.DataBind();
CmbItem.Items.Insert(0, "Select Item");
CmbItem.Items[0].Selected = true;
CmbItem.Items[0].Attributes["disabled"] = "disabled";
}
protected void saveButton_Click(object sender, EventArgs e)
{
string itemName = titleNameForm.Value;
blu.addItem(itemName);
loadItem();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$(function () {");
sb.Append(" $('#con-close-modal').modal('hide');});");
sb.Append("</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModelScript", sb.ToString(), false);
}
<form id="form" class="form-horizontal" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="form-group">
<label class="control-label col-md-2">Item <span style="color: red">*</span> </label>
<div class="col-md-3">
<asp:DropDownList ID="CmbItem" AutoPostBack="true" CssClass="form-control" runat="server" ToolTip="Item List"></asp:DropDownList>
</div>
<div class="col-md-1">
<asp:Button ID="plus" class="btn btn-warning" runat="server" data-toggle="modal" data-target="#con-close-modal" Text="+" />
</div>
</div>
<div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add New Menu List</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-color panel-info">
<div class="panel-heading">
<h3 class="panel-title"><span class="text-danger">* </span>Denotes Mandatory Fields </h3>
</div>
<div class="panel-body">
<h4 class="m-t-0 header-title"></h4>
<p class="text-muted m-b-30 font-13"></p>
<div class="col-md-12">
<div class="form-group">
<label class="col-md-3 control-label">New Item <span class="text-danger">* </span></label>
<div class="col-md-9">
<input type="text" id="titleNameForm" class="form-control" value="" name="titleNameForm" required="required" runat="server" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="saveButton" Text="Save" CssClass="btn btn-success btn-bordered w-md btn-bordered" OnClick="saveButton_Click" runat="server" />
<button type="button" class="btn btn-danger btn-bordered w-md btn-bordered waves-effect" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>