Open Dialog Box from Server side code

Open Dialog Box from Server side code
If your requirement is to open a dialog box from the code behind, this post will help you in this. Mainly we need this when we are performing the validation on server side and wants to open the error messages in dialog box.
Follow the below steps to implement this in your web application
Step 1 – Prerequisite
                Jquery CDN
<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>

Step 2 – Html Code
            <div id="dialog" title="Warning" style="display:none;">
                <p>
                    <asp:Label ID="lblDialogText" runat="server"></asp:Label>
                </p>
            </div>
Step 3 – javascript Code
<script lang="javascript" type="text/javascript"
    $(document).ready(function () {
        $("#dialog").dialog({ autoOpen: false });
    })

    function ShowPopup() {
        $(function () {
            $("#dialog").dialog({
                autoOpen:true,
                title: "Warning",
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
        });
    };
</script>
Step 4 - Server Side Code
                lblDialogText.Text += error.ErrorMessage + "
"
;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);

Step 5 – Test the code J

Comments

Popular posts from this blog

SSIS Merge Join - Both inputs of the transformation must contain at least one sorted column, and those columns must have matching metadata SSIS

jsGrid

Add Item to SharePoint List with attachment using client object model