Home Asp.net Show Alert Message in JavaScript or jQuery

Show Alert Message in JavaScript or jQuery

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

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="https://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?
How to show alert message box using javascript jquery in asp.net?
Previous articleAsp.net GridView Inline Insert Update Delete Data In C# Vb
Next articleShow Alert Message Box from Code-behind in Asp.net C# Vb
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

fifteen − fourteen =