简体   繁体   中英

asp.net web application - alert/message box

I have an asp.net web application. 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

Google "alert asp.net" will give you plenty of solutions using the javascript alert function.

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).

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:

$.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. The success callback of the call will display the alert. 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. When the business logic has been executed, you can register a javascript script that execute the alert. 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>"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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