我有一个ASPX文件,其中包含两个模式(myModal和addModal)和一个gridview,其中包含调用其中每个模块的按钮。我在打开并单击其提交按钮时遇到第二个模式的问题,因为它不会触发PostBack。它只是第二个问题。如果我在ASPX文件中更改这些Modals的顺序,那么我再次遇到麻烦只有文件中的第二个。
当在同一个ASPX页面中有两个模态来触发PostBack时,还需要一些额外的东西吗?
以下是ASPX和C#文件:
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 -->
答案 0 :(得分:0)
问题是我的页面中有3组表单标签。一个用于整个页面,一个用于两个Bootstrap Modals,我从按钮点击打开了。解决方案来自我从引导模式中删除表单标签。然后,来自模态的所有按钮单击都能正常工作并提交数据。