Home Asp.net Show Alert Message in JavaScript or jQuery

Show Alert Message in JavaScript or jQuery

6
0

In my previous tutorials, I’d explained how to show alert message from code-behind, how to call javascript function from code-behind, confirm message box example using javascript and more cracking tutorials on Asp.net, JavaScript, jQuery here.

Now here in this tutorial, I’ll explain how to show alert message in javascript or jquery from client-side in asp.net with example code.

Show Alert Message in jQuery

Following is the simple jQuery function to display or show alert message in jQuery:

<script type=”text/javascript”>
//Function for jQuery
$(function () {
$(‘#btnUsingjQuery’).click(function () {
alert(‘Alert using jQuery Function!’);
});
});
</script>

Show Message in JavaScript

Following is the simple JavaScript function:

<script type=”text/javascript”>
//Function for JavaScript
function alertUsingJavaScript() {
alert(‘Alert using JavaScript Function!’);
}
</script>

Show Message in JavaScript or jQuery – [Asp.net]

And here is the final code that I used in my .aspx page for this demonstration:

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ 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. In case of jQuery, we can bind click event directly on window load as $(‘#btnUsingjQuery’).click(function () { }); });.

Example Result

How to show alert message box using javascript jquery in asp.net?

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!