I have a bootstrap modal popup that has bound data to the asp.net dropdown ( inside the modal ). Now I want to save the selected value into database. My problem is the selected value of the dropdown is not getting passed in the aspx.cs (code behind ) page.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It's hard to say what the problem might be because you haven't posted any code in your question so here is a complete working example of a DropDownList
control inside a Bootstrap modal popup, hope it helps you.
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
ddlFood.Items.Add(new ListItem { Text = "Fruits", Value = "1" });
ddlFood.Items.Add(new ListItem { Text = "Vegetables", Value = "2" });
ddlFood.Items.Add(new ListItem { Text = "Meat", Value = "3" });
}
}
protected void btnDone_Click(object sender, EventArgs e)
{
System.Diagnostics.Debugger.Break();
string favFood = ddlFood.SelectedItem.Text;
}
.ASPX:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
</head>
<body>
<form id="form1" runat="server">
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
<div id="myModal" class="modal fade">
<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" id="myModalLabel">Modal Header</h4>
</div>
<div class="modal-body">
Please select your favourite food group:<br />
<asp:DropDownList ID="ddlFood" runat="server"></asp:DropDownList><br />
<asp:Button ID="btnDone" runat="server" Text="Done" OnClick="btnDone_Click" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</body>
回答2:
Where you bind dropdown in page load method? write code as below in aspx.cs
private void Page_Load()
{
if (!IsPostBack)
{
// dropdown bind code
// OR
// call dropdown bind function eg. bindDropdown();
}
}
There is no issue in model popup of bootstrap.