Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 222
tk_ Avatar asked Oct 21 '22 10:10

tk_


1 Answers

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

}
like image 161
kaushik Avatar answered Oct 23 '22 02:10

kaushik