Dynamic alert window in ASP.net C #

How to create a dynamic alert window in ASP.net C # using a database listener that can be launched without clicking a button?

I have an ASP.NET website and I need to create a custom alert window that can be triggered without a button click, but using a database listener. (I am using a PostgreSQL database.) Since I am new to ASP.NET C # I have no idea how to create it. this warning window should appear while browsing the website and whenever the database is updated with a specific value, which is updated in the database by an external process.

I want to know how to create a database listener in ASP.NET, if you have code examples, please be kind enough to share this.

+4
source share
1 answer

In your code behind the file, you can add the following function

private void ShowMessage(string msg){
string myScript = "\n<script type=\"text/javascript\">\n";
myScript += "alert(" + msg + ");";
myScript += "\n\n </script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", myScript, true);
}

call the function above, wherever you want to show a warning with your custom message.

Add the code below on the client side, which means on the designer page in the tag

$(document).ready(function() {

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

});

function EndRequestHandler(sender, args) {

}
+2
source

Source: https://habr.com/ru/post/1536397/


All Articles