The second Modal in my ASPX file doesn#39;t Post when clicking submit button(单击提交按钮时,我的 ASPX 文件中的第二个模态不会发布)
问题描述
我有一个 ASPX 文件,其中包含两个模式(myModal 和 addModal)和一个 gridview,其中包含调用每个模式的按钮.我在打开并单击其提交按钮时遇到第二个模式的问题,因为它不会触发回发.它只是第二个的问题.如果我在 ASPX 文件中更改这些模式的顺序,那么我再次遇到文件中的第二个问题.
I have an ASPX file that contains two modals (myModal and addModal) and a gridview that has buttons calling each of these. I am having trouble with the second modal when opening and clicking its Submit button as it won't fire a PostBack. Its only a problem with the second one. If I change the sequence of these Modals within the ASPX file, then I again have trouble only with the second one in the file.
当在同一个 ASPX 页面中有两个模态框以使其触发 PostBack 时,是否需要额外的东西?
Is there something additional needed when having two modals in the same ASPX page to get it to fire a PostBack?
这里是 ASPX 和 C# 文件:
Here are the ASPX and C# files:
C# 文件:
protected void Page_Load(object sender, EventArgs e)
{
try{
if (IsPostBack)
{
Control control = null;
string controlName = Request.Params["__EVENTTARGET"];
if (!String.IsNullOrEmpty(controlName))
{
control = FindControl(controlName);
GridViewRow gvRow1 = (GridViewRow)control.Parent.Parent;
string controlID = control.ID.ToString();
}
}
if(!IsPostBack)
{
DataGrid_Load(DAL.reg(HeadText.Text, OrgText.Text), "reg");
ErrorText.Text = "NO POSTBACK";
}
}
catch{}
}
ASPX 文件:
<div id="myModal" class="modal fade">
<script type="text/javascript">
function openModal() {
$('[id*=myModal]').modal('show');
}
</script>
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Update Data</h2>
</div>
<div class="modal-body">
<form class="form-inline" role="form" method="POST" action="" >
<div class="control-group">
<div class="controls controls-row">
<label for="lblnameid" class="col-sm-2 control-label">Name</label>
<div class="col-sm-6">
<asp:TextBox ID="lblnameid" runat="server" Text="" CssClass="form-control" ></asp:TextBox>
</div>
<label for="rankid" class="col-sm-1 control-label">Rank</label>
<div class="col-sm-3">
<asp:DropDownList id="rankid" runat="server" CssClass="form-control"
SelectedValue='<%# Eval("rank") %>' TabIndex='<%# TabIndex %>'>
<asp:ListItem Value=""> </asp:ListItem>
<asp:ListItem Value="a"> A </asp:ListItem>
<asp:ListItem Value="b"> B </asp:ListItem>
<asp:ListItem Value="c"> C </asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<p> </p>
<div class="control-group">
<div class="col-sm-10">
<asp:TextBox ID="id" type="hidden" runat="server" Text="" CssClass="form-control" ></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="pull-right">
<button type="submit" class="btn btn-default">Cancel</button>
<!-- <button type="submit" class="btn btn-primary">Save</button> -->
<asp:Button ID="btnUpdate" OnClientClick="<% %>" class="btn btn-default" runat="server" Text="Save" CommandArgument='<%# Eval("Id") %>' OnCommand="btnUpdate_Click" />
</div>
</div>
</div>
</form>
</div><!-- /.modal-body -->
<form role="form" action="">
<div class="modal-footer">
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div id="addModal" class="modal fade" tabindex="-1" method="POST" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<script type="text/javascript">
$('#addModal').on('hidden.bs.modal', function () {
$(this).find('form').trigger('reset');
})
</script>
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<form class="form-horizontal" role="form">
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label" for="textinput">Name</label>
<div class="col-sm-6">
<input type="text" id="lblnameid" class="form-control">
</div>
</div>
</fieldset>
<div class="modal-footer">
<asp:Button ID="btnSubmit" OnClientClick="<% %>" class="btn btn-primary" runat="server" Text="Save" CommandArgument='<%# Eval("Id") %>' OnCommand="btnSubmit_Click" />
</div>
</form>
</div>
</div>
</div> <!-- /.modal-body -->
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
推荐答案
问题是我的页面中有 3 组表单标签.一个用于整个页面,一个用于我通过按钮单击打开的两个 Bootstrap 模态.当我从引导模式中删除表单标签时,解决方案就来了.然后来自模态的所有按钮点击都正常工作并提交了数据.
The problem was I had 3 sets of form tags in my page. One for the overall page and one each for the two Bootstrap Modals I had that opened up from button clicks. The solution came when I removed the form tags from the bootstrap modals. Then all button clicks from the modals worked properly and submitted the data.
这篇关于单击提交按钮时,我的 ASPX 文件中的第二个模态不会发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单击提交按钮时,我的 ASPX 文件中的第二个模态不会发布


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04