[英]Bootstrap Modal not showing on button click in asp.net and c#
I'm having an issue in getting my bootstrap modal to pop up after button submit. 我在提交按钮提交后弹出引导程序模版时遇到问题。
what needs to happen is the following: 需要发生的情况如下:
steps 1 and 2 are working fine I just can't get step 3 to work. 第1步和第2步工作正常,但是我无法使第3步正常工作。 below is a snippet of my code.
以下是我的代码段。
<asp:Button ID="addcomputerassetbutton" CssClass="btn btn-primary"
OnClick="AddcomputerassetBtn_Click" runat="server" Text="Add Computer Asset" />
<!-- Modal -->
<div class="modal fade" id="ModalCenter" tabindex="-1" role="dialog" aria-labelledby="Assetadded" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<asp:ScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle"><asp:Label ID="lblModalTitle" runat="server" Text=""></asp:Label></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<asp:Label ID ="assetadded" runat="server"></asp:Label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="javascript:window.location='http://assetdb.local/asset?action=addcomputer'">OK</button>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
Code Behind file 文件背后的代码
protected void AddcomputerassetBtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AssetDBConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand("usp_addnewasset", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("assetNumber", inputassettag.Text);
cmd.Parameters.AddWithValue("assetcatid", categoryid);
cmd.Parameters.AddWithValue("assetname", inputassetname.Text);
cmd.Parameters.AddWithValue("assetmodel", inputmodelnumber.Text);
cmd.Parameters.AddWithValue("assetmanufacture", inputassetmanufacture.Text);
cmd.Parameters.AddWithValue("assetservicetag", inputassetservicetag.Text);
cmd.Parameters.AddWithValue("assetstatus", inputassetstatus.Text);
cmd.Parameters.AddWithValue("assetcompany", inputassetcompany.Text);
cmd.Parameters.AddWithValue("assetoffice", inputassetoffice.Text);
cmd.Parameters.AddWithValue("assetdepartment", inputassetdepartment.Text);
cmd.Parameters.AddWithValue("assetuser", inputassetuser.Text);
cmd.Parameters.AddWithValue("assetcost", inputassetcost.Text);
cmd.Parameters.AddWithValue("assetram", inputassetram.Text);
cmd.Parameters.AddWithValue("assetcpu", inputassetcpu.Text);
cmd.Parameters.AddWithValue("assetdiskdrive", inputassethdd.Text);
cmd.Parameters.AddWithValue("assetlocaladminuser", inputassetadminusername.Text);
cmd.Parameters.AddWithValue("assetlocaladminpassword", inputassetlocaladminpassword.Text);
//cmd.Parameters.AddWithValue("catdescription", inputimei.Text);
//cmd.Parameters.AddWithValue("catname", inputassetmobilenumber.Text);
con.Open();
int k = cmd.ExecuteNonQuery();
if (k != 0)
{
lblModalTitle.Text = "Asset Added OK";
assetadded.Text = "The Asset has been added to the Database";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ModalCenter", "$('#ModalCenter').modal();", true);
upModal.Update();
}
else
{
lblModalTitle.Text = "Asset Not added OK";
assetadded.Text = "There was an error adding the asset";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ModalCenter", "$('#ModalCenter').modal();", true);
upModal.Update();
}
con.Close();
}
I would be grateful for your assistance 感谢您的协助
First you check if you can open a modal by a simple button click 首先,您检查是否可以通过简单的按钮单击来打开模态
If successful then what you can start with is pass an parameter like 如果成功,那么您可以通过传递一个像
AddRecord.aspx?added=true
and on 继续
$(document).ready(function(){
//Read the parameter values and if true show the dialog using
$('#ModalCenter').modal();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.