March 20, 2019 12:03 by
Peter
Today, I will explain you about Showing Alert Message Box from client Side on ASP.NET Core 2.2.3 using JavaScript and JQuery. In the Following, this is jQuery Code Snippet to show/display alert message:
//Function for jQuery
$(function () {
$('#btnUsingjQuery').click(function () {
alert('Alert using jQuery Function!');
});
});
And, this is the JavaScript code to show or display alert message:
//Function for JavaScript
function alertUsingJavaScript() {
alert('Alert using JavaScript Function!');
}
Show Alert Message – (.aspx)
Here is the code snippet for your .aspx webpage:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to show alert message using jQuery/JavaScript in ASP.NET
</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js">
</script>
<script type="text/javascript">
//Function for JavaScript
function alertUsingJavaScript() {
alert('Alert using JavaScript Function!');
}
//Function for jQuery
$(function () {
$('#btnUsingjQuery').click(function () {
alert('Alert using jQuery Function!');
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<h4>
Show alert message using JavaScript/jQuery in Asp.net</h4>
<div>
<input id="btnUsingJavaScript" type="button" onclick="alertUsingJavaScript()"
value="Using JavaScript" />
<input id="btnUsingjQuery" type="button" value="Using jQuery" />
</div>
</form>
</body>
</html>
You can see i’d added onclick=”alertUsingJavaScript()” when calling function using JavaScript. Just in case of jQuery, we are able to bind click event directly on window load as $(‘#btnUsingjQuery’).click(function () ); });. And here is the result: