Custom/Div based Alert in ASP.NET

The post is about implementing Custom/Div based Alert Messagebox in ASP.NET using jQuery/jQuery UI Dialog plugin. This can be a required thing when you are asked not to use default browser alert box.

You may would like to use jQuery UI Dialog to implement customized Alert/Confirm boxes. This way, you can provide the buttons, messages, title as well as actions that you wanted.

Here with, I have written a small Webform to show a customized Alert box using jQuery UI Dialog:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <script src=""></script>
    <script src=""></script>
    <link href="" rel="stylesheet" />
    <script type="text/javascript">
        function AlertBox(msgtitle, message, controlToFocus) {
                autoOpen: false,
                modal: true,
                title: msgtitle,
                closeOnEscape: true,
                buttons: [{
                    text: "Ok",
                    click: function () {
                        if (controlToFocus != null)
                close: function () {
                    if (controlToFocus != null)
                show: { effect: "clip", duration: 200 }

        function ShowMessage() {
            AlertBox("This is Title", "And This is the content of the message!", null);
            return false;
    <form id="form1" runat="server">
        <div id="msgDialogAlert" style="display: none; text-align: center; vertical-align: central">
            <p id="operationMsgAlert">&nbsp;</p>
        <asp:Button Text="Click!" runat="server" OnClientClick="return ShowMessage();" />

Result will be:

You can have Ok, Yes & No, Ok & Cancel, any combination of button you needed and can write code in click event in above given code snippet. 

Similar to this Alert box, you can use same method to implement Confirm box, Success message box (that just show by itself and then disappears without any action)


No Comments