javascript 如何在单击 Asp.Net 按钮单击事件时显示弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10926205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show a popup on click of Asp.Net Button click event
提问by Priyank Patel
I have a popup which displays a message to the user which says their information has been submitted.The popup div's id NewCustomerStatusPopUp,I want this popup to be displayed when the information has been successfully inserted in the database , so how do I call the javascript function to show popup when all the information has been submitted.Can any one just let me know how can I do this. Here is my popup
我有一个弹出窗口,向用户显示一条消息,说明他们的信息已提交。弹出 div 的 id 为 NewCustomerStatusPopUp,我希望在信息成功插入数据库时显示此弹出窗口,那么我如何调用 javascript提交所有信息后显示弹出窗口的功能。任何人都可以让我知道我该怎么做。这是我的弹出窗口
<div id="NewCustomerStatusPopUp">
<asp:Label ID="lblStatus" Text="" runat="server"/>
</div>
CSS:
CSS:
#NewCustomerStatusPopUp
{
position: fixed;
width: 300px;
height: 250px;
top: 50%;
left: 50%;
margin-left:-255px;
margin-top:-150px;
border: 10px solid #9cc3f7;
background-color:White;
padding: 10px;
z-index: 102;
font-family:Verdana;
font-size: 10pt;
border-radius:10px;
-webkit-border-radius:20px;
-moz-border-radius:20px;
}
Any help is much appreciated.
任何帮助深表感谢。
Thanks.
谢谢。
采纳答案by Nikhil D
To call a javascript function from server you can use a RegisterStartipScript
:
After ur insert query write this code
要从服务器调用 javascript 函数,您可以使用RegisterStartipScript
:
在插入查询后编写此代码
ClientScript.RegisterStartupScript(GetType(), "id", "callMyJSFunction()", true);
<script type="text/javascript">
function callMyJSFunction()
{
alert("Record inserted sucessfully.");
}
回答by jflood.net
If you've got an click event handler in your code behind performing the insert, no need for JS, wrap the div in a panel:
如果在执行插入的代码中有一个单击事件处理程序,则不需要 JS,请将 div 包装在面板中:
<asp:Panel ID="pnlStatus" Visible="false" >
<div id="NewCustomerStatusPopUp">
<asp:Label ID="lblStatus" Text="" runat="server"/>
</div>
</asp:Panel>
In your code behind, once you've asserted that the new customer was added successfully,
在后面的代码中,一旦您断言新客户已成功添加,
set pnlStatus to visible.
将 pnlStatus 设置为可见。
pnlStatus.Visible = true;