gpt4 book ai didi

javascript - 如何从后面的代码关闭 Bootstrap 模式?

转载 作者:数据小太阳 更新时间:2023-10-29 05:09:47 25 4
gpt4 key购买 nike

我正在从模态进行更新操作。当模态弹出时,它会加载我要更新的特定行数据。下面是我的模态代码:

<form id="form1" runat="server">
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="myModal" class="modal fade" role="dialog" runat="server" draggable="auto">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Insert Module</h4>
</div>
<div class="modal-body">
<table class="table table-bordered">
<thead>
<tr>
<td colspan="2" style="text-align: center">
<label>UPDATE EMPLOYEE DETAIL</label>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>FIRST NAME</label>
</td>
<td>
<asp:TextBox ID="up_tb1" runat="server"></asp:TextBox>
<ajax:filteredtextboxextender id="FilteredTextBoxExtender7" targetcontrolid="up_tb1" filtertype="UppercaseLetters,LowercaseLetters" runat="server"></ajax:filteredtextboxextender>
</td>
</tr>
<tr>
<td>
<label>MIDDLE NAME</label>
</td>
<td>
<asp:TextBox ID="up_tb2" runat="server"></asp:TextBox>
<ajax:filteredtextboxextender id="FilteredTextBoxExtender8" targetcontrolid="up_tb2" filtertype="UppercaseLetters,LowercaseLetters" runat="server"></ajax:filteredtextboxextender>
</td>
</tr>
<tr>
<td>
<label>LAST NAME</label>
</td>
<td>
<asp:TextBox ID="up_tb3" runat="server"></asp:TextBox>
<ajax:filteredtextboxextender id="FilteredTextBoxExtender9" targetcontrolid="up_tb3" filtertype="UppercaseLetters,LowercaseLetters" runat="server"></ajax:filteredtextboxextender>
</td>
</tr>
<tr>
<td>
<label>EMAIL</label>
</td>
<td>
<asp:TextBox ID="up_tb4" runat="server"></asp:TextBox>
<ajax:filteredtextboxextender id="FilteredTextBoxExtender10" targetcontrolid="up_tb4" filtertype="Numbers, LowercaseLetters, Custom" validchars=".@" runat="server"></ajax:filteredtextboxextender>
</td>
</tr>
<tr>
<td>
<label>DOB</label>
</td>
<td>
<asp:TextBox ID="up_tb5" runat="server" Enabled="false"></asp:TextBox>
<ajax:calendarextender id="CalendarExtender2" runat="server" popupbuttonid="ImageButton1" targetcontrolid="up_tb5"></ajax:calendarextender>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/calendar146.png" Width="16px" Height="16px" />
</td>
</tr>
<tr>
<td>
<label>USERNAME</label>
</td>
<td>
<asp:TextBox ID="up_tb6" runat="server"></asp:TextBox>
<ajax:filteredtextboxextender id="FilteredTextBoxExtender12" targetcontrolid="up_tb6" filtertype="Numbers, LowercaseLetters, Custom" validchars=".@" runat="server"></ajax:filteredtextboxextender>
</td>
</tr>
<tr>
<td>
<label>PASSWORD</label>
</td>
<td>
<asp:TextBox ID="up_tb7" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="up_tb8" CssClass="btn btn-success" runat="server" Text="UPDATE" OnClick="up_tb8_Click" />
</td>
</tr>
</tbody>
</table>
<asp:ValidationSummary ID="ValidationSummary2" runat="server"
DisplayMode="BulletList" ShowSummary="true" HeaderText="Errors:" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>

我正在从代码隐藏中加载模态并从代码隐藏中填充其字段。下面是我的隐藏代码:

protected void up_tb8_Click(object sender, EventArgs e)
{
var db = new dbDataContext();
Employee emp = new Employee();
db.Sp_Updatevalue(up_id, up_tb1.Text, up_tb2.Text, up_tb3.Text, up_tb4.Text, Convert.ToDateTime(up_tb5.Text), up_tb6.Text, up_tb7.Text);
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ClosePopup();", true);
}

当我单击我的更新按钮时,它成功地运行了我的更新存储过程并更新了数据库中的值。问题是当数据更新模式弹出窗口消失但它的暗灰色背景仍然固定在我的屏幕上时我想在我的记录更新并且我的 gridview 刷新并显示我更新的记录时正确关闭模式。

最佳答案

如果用户控件 (ascx) 包装在模态框内,则:

 ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#myModal').modal('hide');", true);

将不起作用。您应该使用 this.Page 而不是 this

正确的解决方案:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Pop", "$('#myModal').modal('hide');", true);

关于javascript - 如何从后面的代码关闭 Bootstrap 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35178717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com