简体   繁体   English

asp.net Web应用程序-警报/消息框

[英]asp.net web application - alert/message box

I have an asp.net web application. 我有一个asp.net Web应用程序。 On clicking a button, on the server side some code is executed. 在服务器上单击按钮后,将执行一些代码。 If the code is successfully executed I want an alert popup box to be shown to the user informing them of the successful completion of the action. 如果代码成功执行,我希望向用户显示一个警告弹出框,通知他们操作成功完成。

Any ideas? 有任何想法吗?

Kind Regards, Fiona 亲切的问候,Fiona

Google "alert asp.net" will give you plenty of solutions using the javascript alert function. Google“警报asp.net”将使用javascript警报功能为您提供大量解决方案。

Even better, googling "jquery alert asp.net" will give you jquery solutions (an html modal popup which is modal to the current page, but allows you to switch to other tabs in a tabbed browser). 更好的是,使用谷歌搜索“ jquery alert asp.net”将为您提供jquery解决方案(一个HTML模式弹出窗口,该弹出窗口是当前页面的模式,但允许您切换到选项卡式浏览器中的其他选项卡)。

server side code and clide side code run in different contexts, I think your best approach would be to post with ajax or jquery like: 服务器端代码和clide端代码在不同的上下文中运行,我认为最好的方法是使用ajax或jquery进行发布,例如:

$.post(url,parameters, function(){
    //this code runs after the post
    alert('my message')
    }
);

I suggest you a couple of solutions. 我建议您一些解决方案。

  1. Create a Javascript onclick event handler that executes an AJAX call to your business code. 创建一个Javascript onclick事件处理程序,该处理程序执行对您的业务代码的AJAX调用。 The success callback of the call will display the alert. 呼叫success回叫将显示警报。 References here . 参考文献在这里 I prefer this solution. 我更喜欢这种解决方案。

     $.ajax({ type: 'POST', url: 'path/to/my/business/handler.ashx', data: ({/*my json data*/}), error: function (request, status, error) { alert("Something wrong here!"); return false; }, success: function (returnData) { alert("Everything fine here!"); } }); 
  2. Manage the onclick event with a server side event handler. 使用服务器端事件处理程序管理onclick事件。 When the business logic has been executed, you can register a javascript script that execute the alert. 执行业务逻辑后,您可以注册执行警报的JavaScript脚本。 References here . 参考文献在这里

     ClientScriptManager cs = Page.ClientScript; Type csType = this.GetType(); cs.RegisterClientScriptBlock(csType, "handler", @"<script language='javascript' type='text/javascript'>alert('Eveything fine here!');</script>"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM