Dialog modal popup on button click from Server Side (Code Behind) using jquery

As previous we have learned that how to Dialog Modal Popup on page load using Jquery and how to Dialog modal popup on button click using jquery. But many times we need to pop up on server side means code-behind in asp.net c#. This code is very useful when we want so customize pop up message or status message.


Source code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pop-up-window.aspx.cs" Inherits="pop_up_window" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function ShowPopup(message, title) {
            $(function () {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    title: title,
                    width: 450,
                    buttons: {
                        Close: function () {
                            $(this).dialog('close');

                        }
                    },
                    modal: true
                });
            });
        };
    </script>

</head>
<body>
    <form id="form1" runat="server">

        <div id="dialog" style="display: none">
        </div>


        <asp:Button ID="btndialogpopup" runat="server" Text="Click here to show Popup" OnClick="btndialogpopup_Click" />

    </form>
</body>
</html>

Code-behind(c#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pop_up_window : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }




    protected void btndialogpopup_Click(object sender, EventArgs e)
    {
        string message = "Hello Friend, Please like our facebook and you will get daily updates of MVC , asp-net using c#, javascript , sql server , jquery and so on";
        string title = " Dialog modal popup on server side";

        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "','" + title + "');", true);
    }
}

Out-Put:-


Dialog modal popup on button click from Server Side (Code Behind) using jquery Dialog modal popup on button click from Server Side (Code Behind) using jquery Reviewed by NEERAJ SRIVASTAVA on 12:36:00 PM Rating: 5

No comments:

Powered by Blogger.