简体   繁体   中英

Dynamic alert box in ASP.net C#

How to create dynamic alert box in ASP.net C# using a database listener which can be triggered without using a button click?

I have a ASP.NET web site and I need to create a custom alert box which can be triggered without using a button click but using a database listener.(I'm using PostgreSQL database.) since I'm new to ASP.NET C# i have no idea how to create it. this alert box should pop up while we are browsing through the website and whenever database updated by a particular value which is updated in the database by a external process.

What I want to know is how to create a database listener in ASP.NET, if you have example codes, please be kind enough to share that.

In your code behind file you can add the below 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 above function where ever you want to show alert with your custom message.

Add the below code at client side, means in your designer page under tag

$(document).ready(function() {

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

});

function EndRequestHandler(sender, args) {

}

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